@visulima/string 3.0.0-alpha.9 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +305 -0
  2. package/LICENSE.md +68 -3
  3. package/README.md +80 -2
  4. package/dist/align-text.d.ts +35 -0
  5. package/dist/align-text.js +2 -34
  6. package/dist/case/camel-case.d.ts +17 -3
  7. package/dist/case/camel-case.js +1 -55
  8. package/dist/case/capital-case.d.ts +14 -3
  9. package/dist/case/capital-case.js +1 -47
  10. package/dist/case/constant-case.d.ts +14 -3
  11. package/dist/case/constant-case.js +1 -7
  12. package/dist/case/dot-case.d.ts +14 -3
  13. package/dist/case/dot-case.js +1 -7
  14. package/dist/case/flat-case.d.ts +12 -3
  15. package/dist/case/flat-case.js +1 -7
  16. package/dist/case/flip-case.d.ts +16 -3
  17. package/dist/case/flip-case.js +1 -82
  18. package/dist/case/identify-case.d.ts +15 -3
  19. package/dist/case/identify-case.js +1 -66
  20. package/dist/case/index.d.ts +8 -3
  21. package/dist/case/index.js +1 -20
  22. package/dist/case/kebab-case.d.ts +25 -3
  23. package/dist/case/kebab-case.js +1 -55
  24. package/dist/case/lower-first.d.ts +13 -3
  25. package/dist/case/lower-first.js +1 -9
  26. package/dist/case/no-case.d.ts +14 -3
  27. package/dist/case/no-case.js +1 -7
  28. package/dist/case/pascal-case.d.ts +17 -3
  29. package/dist/case/pascal-case.js +1 -48
  30. package/dist/case/pascal-snake-case.d.ts +14 -3
  31. package/dist/case/pascal-snake-case.js +1 -28
  32. package/dist/case/path-case.d.ts +14 -3
  33. package/dist/case/path-case.js +1 -7
  34. package/dist/case/sentence-case.d.ts +14 -3
  35. package/dist/case/sentence-case.js +1 -54
  36. package/dist/case/snake-case.d.ts +14 -3
  37. package/dist/case/snake-case.js +1 -7
  38. package/dist/case/split-by-case.d.ts +29 -3
  39. package/dist/case/split-by-case.js +1 -763
  40. package/dist/case/title-case.d.ts +12 -3
  41. package/dist/case/title-case.js +1 -40
  42. package/dist/case/train-case.d.ts +14 -3
  43. package/dist/case/train-case.js +1 -40
  44. package/dist/case/upper-first.d.ts +13 -3
  45. package/dist/case/upper-first.js +1 -9
  46. package/dist/closest-string.d.ts +32 -0
  47. package/dist/closest-string.js +1 -22
  48. package/dist/compare-similarity.d.ts +37 -0
  49. package/dist/compare-similarity.js +1 -12
  50. package/dist/count-occurrences.d.ts +9 -0
  51. package/dist/count-occurrences.js +1 -0
  52. package/dist/direction.d.ts +7 -0
  53. package/dist/direction.js +1 -0
  54. package/dist/east-asian-width.d.ts +58 -0
  55. package/dist/east-asian-width.js +1 -0
  56. package/dist/excerpt.d.ts +25 -0
  57. package/dist/excerpt.js +53 -0
  58. package/dist/get-string-truncated-width.d.ts +151 -0
  59. package/dist/get-string-truncated-width.js +1 -332
  60. package/dist/get-string-width.d.ts +58 -0
  61. package/dist/get-string-width.js +1 -5
  62. package/dist/indent.d.ts +88 -0
  63. package/dist/indent.js +1 -0
  64. package/dist/index.d.ts +12 -20
  65. package/dist/index.js +1 -44
  66. package/dist/is-fullwidth-code-point.d.ts +7 -0
  67. package/dist/is-fullwidth-code-point.js +1 -0
  68. package/dist/levenshtein.d.ts +25 -0
  69. package/dist/levenshtein.js +1 -0
  70. package/dist/native-string-types.d.ts +241 -18
  71. package/dist/outdent.d.ts +74 -0
  72. package/dist/outdent.js +1 -109
  73. package/dist/packem_shared/_isFullWidth-Dqc3MWgl.js +1 -0
  74. package/dist/packem_shared/closest-C6YDQs4m.js +1 -0
  75. package/dist/packem_shared/constants-aPzGW29R.js +1 -0
  76. package/dist/packem_shared/dedent-CPjAYUXh.js +1 -0
  77. package/dist/packem_shared/eastAsianWidth-DJV8Kqd-.js +1 -0
  78. package/dist/packem_shared/generate-cache-key-B_0X7MKm.js +1 -0
  79. package/dist/packem_shared/indent-cz8WMI0e.js +1 -0
  80. package/dist/packem_shared/joinSegments-CaHT-45s.js +1 -0
  81. package/dist/packem_shared/lru-cache-BtMSrYQJ.js +1 -0
  82. package/dist/packem_shared/normalize-german-eszett-hNMwtGjd.js +1 -0
  83. package/dist/packem_shared/redent-ByOoJ6fN.js +1 -0
  84. package/dist/packem_shared/strip-vt-control-characters-BW1RglLp.js +1 -0
  85. package/dist/packem_shared/types.d-CMNqA5bi.d.ts +402 -0
  86. package/dist/packem_shared/types.d-LgsTR37y.d.ts +360 -0
  87. package/dist/replace-string.d.ts +10 -0
  88. package/dist/replace-string.js +1 -0
  89. package/dist/slice.d.ts +42 -0
  90. package/dist/slice.js +1 -415
  91. package/dist/slugify.d.ts +10 -1
  92. package/dist/slugify.js +1 -46
  93. package/dist/test/utils.d.ts +17 -0
  94. package/dist/test/utils.js +13 -88
  95. package/dist/test/vitest.d.ts +3 -0
  96. package/dist/test/vitest.js +1 -5
  97. package/dist/transliterate.d.ts +10 -0
  98. package/dist/transliterate.js +5 -0
  99. package/dist/truncate.d.ts +43 -0
  100. package/dist/truncate.js +1 -112
  101. package/dist/utilities.d.ts +28 -2
  102. package/dist/utilities.js +1 -52
  103. package/dist/word-similarity-sort.d.ts +34 -0
  104. package/dist/word-similarity-sort.js +1 -22
  105. package/dist/word-wrap.d.ts +44 -0
  106. package/dist/word-wrap.js +8 -639
  107. package/package.json +70 -36
  108. package/dist/packem_shared/LRUCache-3r3SovvR.js +0 -46
  109. package/dist/packem_shared/closest-IHuSvnSn.js +0 -139
  110. package/dist/packem_shared/closestN-DUsjgiXb.js +0 -25
  111. package/dist/packem_shared/constants-BsZS5f0z.js +0 -95
  112. package/dist/packem_shared/countOccurrences-CS9XprQN.js +0 -22
  113. package/dist/packem_shared/direction-C9gfWWTK.js +0 -16
  114. package/dist/packem_shared/eastAsianWidthType-SD3YniiT.js +0 -20
  115. package/dist/packem_shared/excerpt-COsVNttN.js +0 -1502
  116. package/dist/packem_shared/generate-cache-key-DdayDfjV.js +0 -6
  117. package/dist/packem_shared/indent-D3DSCa6s.js +0 -33
  118. package/dist/packem_shared/isFullwidthCodePoint-IFXZxNjq.js +0 -10
  119. package/dist/packem_shared/joinSegments-CvxSgKz0.js +0 -44
  120. package/dist/packem_shared/lookup-BE8lEqy4.js +0 -104
  121. package/dist/packem_shared/lru-cache.d-BsP6kbVJ.d.ts +0 -13
  122. package/dist/packem_shared/normalize-german-eszett-4p3yKEzn.js +0 -8
  123. package/dist/packem_shared/redent-DSb1IJWn.js +0 -8
  124. package/dist/packem_shared/replaceString-Ce8X2ZQ-.js +0 -192
  125. package/dist/packem_shared/stripIndent-D_TRjxZ_.js +0 -20
  126. package/dist/packem_shared/transliterate-CKt9VK7D.js +0 -47756
  127. package/dist/packem_shared/types.d-BVNv675q.d.ts +0 -61
  128. package/dist/packem_shared/types.d-DfgbcNKh.d.ts +0 -57
@@ -1,5 +1,14 @@
1
- import { C as CaseOptions, T as TitleCase } from "../packem_shared/types.d-DfgbcNKh.js";
2
- import "../packem_shared/types.d-BVNv675q.js";
3
- import "../packem_shared/lru-cache.d-BsP6kbVJ.js";
1
+ import { b as CaseOptions, T as TitleCase } from "../packem_shared/types.d-CMNqA5bi.js";
2
+ import "../packem_shared/types.d-LgsTR37y.js";
3
+ /**
4
+ * With Title Case all words are capitalized, except for minor words.
5
+ * @example
6
+ * ```typescript
7
+ * titleCase("this-IS-aTitle") // => "This is a Title"
8
+ * titleCase("XMLHttpRequest") // => "XML Http Request"
9
+ * titleCase("AJAXRequest") // => "AJAX Request"
10
+ * titleCase("QueryXML123String") // => "Query XML 123 String"
11
+ * ```
12
+ */
4
13
  declare function titleCase<T extends string = string>(value?: T, options?: CaseOptions): TitleCase<T>;
5
14
  export { titleCase as default };
@@ -1,40 +1 @@
1
- import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
2
- import { splitByCase } from './split-by-case.js';
3
- import upperFirst from './upper-first.js';
4
- import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
5
- import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-4p3yKEzn.js';
6
-
7
- const defaultCacheStore = new LRUCache(1e3);
8
- function titleCase(value, options) {
9
- if (typeof value !== "string") {
10
- return "";
11
- }
12
- const shouldCache = options?.cache ?? false;
13
- const cacheStore = options?.cacheStore ?? defaultCacheStore;
14
- let cacheKey;
15
- if (shouldCache) {
16
- cacheKey = generateCacheKey(value, options);
17
- }
18
- if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
19
- return cacheStore.get(cacheKey);
20
- }
21
- const result = splitByCase(value, {
22
- handleAnsi: options?.handleAnsi,
23
- handleEmoji: options?.handleEmoji,
24
- knownAcronyms: options?.knownAcronyms,
25
- locale: options?.locale,
26
- normalize: options?.normalize,
27
- separators: void 0,
28
- stripAnsi: options?.stripAnsi,
29
- stripEmoji: options?.stripEmoji
30
- }).map((word) => {
31
- const normalized = options?.locale?.startsWith("de") ? normalizeGermanEszett(word) : word;
32
- return upperFirst(options?.locale ? normalized.toLocaleLowerCase(options.locale) : normalized.toLowerCase(), { locale: options?.locale });
33
- }).join(" ");
34
- if (shouldCache && cacheKey) {
35
- cacheStore.set(cacheKey, result);
36
- }
37
- return result;
38
- }
39
-
40
- export { titleCase as default };
1
+ import{i as e}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as c}from"./split-by-case.js";import m from"./upper-first.js";import{a as p}from"../packem_shared/generate-cache-key-B_0X7MKm.js";import{a as f}from"../packem_shared/normalize-german-eszett-hNMwtGjd.js";const d=new e(1e3);function y(a,o){if(typeof a!="string")return"";const t=o?.cache??!1,s=o?.cacheStore??d;let r;if(t&&(r=p(a,o)),t&&r&&s.has(r))return s.get(r);const i=c(a,{handleAnsi:o?.handleAnsi,handleEmoji:o?.handleEmoji,knownAcronyms:o?.knownAcronyms,locale:o?.locale,normalize:o?.normalize,separators:void 0,stripAnsi:o?.stripAnsi,stripEmoji:o?.stripEmoji}).map(n=>{const l=o?.locale?.startsWith("de")?f(n):n;return m(o?.locale?l.toLocaleLowerCase(o.locale):l.toLowerCase(),{locale:o?.locale})}).join(" ");return t&&r&&s.set(r,i),i}export{y as default};
@@ -1,5 +1,16 @@
1
- import { C as CaseOptions, j as TrainCase } from "../packem_shared/types.d-DfgbcNKh.js";
2
- import "../packem_shared/types.d-BVNv675q.js";
3
- import "../packem_shared/lru-cache.d-BsP6kbVJ.js";
1
+ import { b as CaseOptions, j as TrainCase } from "../packem_shared/types.d-CMNqA5bi.js";
2
+ import "../packem_shared/types.d-LgsTR37y.js";
3
+ /**
4
+ * Converts a string to Train-Case.
5
+ * @example
6
+ * ```typescript
7
+ * trainCase("foo bar") // => "Foo-Bar"
8
+ * trainCase("foo-bar") // => "Foo-Bar"
9
+ * trainCase("foo_bar") // => "Foo-Bar"
10
+ * trainCase("XMLHttpRequest") // => "XML-Http-Request"
11
+ * trainCase("AJAXRequest") // => "AJAX-Request"
12
+ * trainCase("QueryXML123String") // => "Query-XML-123-String"
13
+ * ```
14
+ */
4
15
  declare const trainCase: <T extends string = string>(value?: T, options?: CaseOptions) => TrainCase<T>;
5
16
  export { trainCase as default };
@@ -1,40 +1 @@
1
- import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
2
- import { splitByCase } from './split-by-case.js';
3
- import upperFirst from './upper-first.js';
4
- import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
5
- import joinSegments from '../packem_shared/joinSegments-CvxSgKz0.js';
6
-
7
- const defaultCacheStore = new LRUCache(1e3);
8
- const trainCase = (value, options) => {
9
- if (typeof value !== "string") {
10
- return "";
11
- }
12
- const shouldCache = options?.cache ?? false;
13
- const cacheStore = options?.cacheStore ?? defaultCacheStore;
14
- let cacheKey;
15
- if (shouldCache) {
16
- cacheKey = generateCacheKey(value, options);
17
- }
18
- if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
19
- return cacheStore.get(cacheKey);
20
- }
21
- const result = joinSegments(
22
- splitByCase(value, {
23
- handleAnsi: options?.handleAnsi,
24
- handleEmoji: options?.handleEmoji,
25
- knownAcronyms: options?.knownAcronyms,
26
- locale: options?.locale,
27
- normalize: options?.normalize,
28
- separators: void 0,
29
- stripAnsi: options?.stripAnsi,
30
- stripEmoji: options?.stripEmoji
31
- }).map((p) => upperFirst(p, { locale: options?.locale })),
32
- "-"
33
- );
34
- if (shouldCache && cacheKey) {
35
- cacheStore.set(cacheKey, result);
36
- }
37
- return result;
38
- };
39
-
40
- export { trainCase as default };
1
+ import{i as m}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as l}from"./split-by-case.js";import e from"./upper-first.js";import{a as p}from"../packem_shared/generate-cache-key-B_0X7MKm.js";import c from"../packem_shared/joinSegments-CaHT-45s.js";const f=new m(1e3),y=(t,o)=>{if(typeof t!="string")return"";const i=o?.cache??!1,n=o?.cacheStore??f;let r;if(i&&(r=p(t,o)),i&&r&&n.has(r))return n.get(r);const s=c(l(t,{handleAnsi:o?.handleAnsi,handleEmoji:o?.handleEmoji,knownAcronyms:o?.knownAcronyms,locale:o?.locale,normalize:o?.normalize,separators:void 0,stripAnsi:o?.stripAnsi,stripEmoji:o?.stripEmoji}).map(a=>e(a,{locale:o?.locale})),"-");return i&&r&&n.set(r,s),s};export{y as default};
@@ -1,5 +1,15 @@
1
- import { L as LocaleOptions, U as UpperFirst } from "../packem_shared/types.d-DfgbcNKh.js";
2
- import "../packem_shared/types.d-BVNv675q.js";
3
- import "../packem_shared/lru-cache.d-BsP6kbVJ.js";
1
+ import { L as LocaleOptions, U as UpperFirst } from "../packem_shared/types.d-CMNqA5bi.js";
2
+ import "../packem_shared/types.d-LgsTR37y.js";
3
+ /**
4
+ * Converts first character to upper case.
5
+ * @param value The string to convert.
6
+ * @param options Options for case conversion.
7
+ * @returns The string with its first character converted to uppercase.
8
+ * @example
9
+ * ```typescript
10
+ * upperFirst("hello world!") // => "Hello world!"
11
+ * upperFirst("istanbul", { locale: "tr" }) // => "İstanbul"
12
+ * ```
13
+ */
4
14
  declare const upperFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => UpperFirst<T>;
5
15
  export { upperFirst as default };
@@ -1,9 +1 @@
1
- const upperFirst = (value, options) => {
2
- if (typeof value !== "string" || value === "") {
3
- return "";
4
- }
5
- const firstChar = options?.locale ? value[0].toLocaleUpperCase(options.locale) : value[0].toUpperCase();
6
- return firstChar + value.slice(1);
7
- };
8
-
9
- export { upperFirst as default };
1
+ const a=(e,o)=>typeof e!="string"||e===""?"":(o?.locale?e[0].toLocaleUpperCase(o.locale):e[0].toUpperCase())+e.slice(1);export{a as default};
@@ -1,6 +1,38 @@
1
+ /** Options for {@linkcode closestString}. */
1
2
  interface ClosestStringOptions {
3
+ /**
4
+ * Whether the distance should include case.
5
+ * @default {false}
6
+ */
2
7
  caseSensitive?: boolean;
8
+ /**
9
+ * A custom comparison function to use for comparing strings.
10
+ * @param a The first string for comparison.
11
+ * @param b The second string for comparison.
12
+ * @returns The distance between the two strings.
13
+ * @default {levenshteinDistance}
14
+ */
3
15
  compareFn?: (a: string, b: string) => number;
4
16
  }
17
+ /**
18
+ * Finds the most similar string from an array of strings.
19
+ *
20
+ * By default, calculates the distance between words using the
21
+ * {@link https://en.wikipedia.org/wiki/Levenshtein_distance | Levenshtein distance}.
22
+ * @example Usage
23
+ * ```ts
24
+ * import { closestString } from "@visulima/string";
25
+ * import assert from "node:assert";
26
+ *
27
+ * const possibleWords = ["length", "size", "blah", "help"];
28
+ * const suggestion = closestString("hep", possibleWords);
29
+ *
30
+ * assert.deepStrictEqual(suggestion, "help");
31
+ * ```
32
+ * @param givenWord The string to measure distance against
33
+ * @param possibleWords The string-array to pick the closest string from
34
+ * @param options The options for the comparison.
35
+ * @returns The closest string from `possibleWords`, or `undefined` if `possibleWords` is empty (though the function throws in this case).
36
+ */
5
37
  declare const closestString: (givenWord: string, possibleWords: ReadonlyArray<string>, options?: ClosestStringOptions) => string | undefined;
6
38
  export { ClosestStringOptions, closestString };
@@ -1,22 +1 @@
1
- import { distance } from './packem_shared/closest-IHuSvnSn.js';
2
-
3
- const closestString = (givenWord, possibleWords, options) => {
4
- if (possibleWords.length === 0) {
5
- throw new TypeError("When using closestString(), the possibleWords array must contain at least one word");
6
- }
7
- const { caseSensitive, compareFn: compareFunction = distance } = { ...options };
8
- const normalizedGivenWord = caseSensitive ? givenWord : givenWord.toLowerCase();
9
- let nearestWord = possibleWords[0] ?? void 0;
10
- let closestStringDistance = Infinity;
11
- for (const possibleWord of possibleWords) {
12
- const each = possibleWord;
13
- const distance = caseSensitive ? compareFunction(normalizedGivenWord, each) : compareFunction(normalizedGivenWord, each.toLowerCase());
14
- if (distance < closestStringDistance) {
15
- nearestWord = each;
16
- closestStringDistance = distance;
17
- }
18
- }
19
- return nearestWord;
20
- };
21
-
22
- export { closestString };
1
+ import{distance as p}from"./packem_shared/closest-C6YDQs4m.js";const d=(s,o,l)=>{if(o.length===0)throw new TypeError("When using closestString(), the possibleWords array must contain at least one word");const{caseSensitive:e,compareFn:r=p}={...l},n=e?s:s.toLowerCase();let a=o[0]??void 0,i=1/0;for(const g of o){const t=g,c=e?r(n,t):r(n,t.toLowerCase());c<i&&(a=t,i=c)}return a};export{d as closestString};
@@ -1,6 +1,43 @@
1
+ /** Options for {@linkcode compareSimilarity}. */
1
2
  interface CompareSimilarityOptions {
3
+ /**
4
+ * Whether the distance should include case.
5
+ * @default {false}
6
+ */
2
7
  caseSensitive?: boolean;
8
+ /**
9
+ * A custom comparison function to use for comparing strings.
10
+ * @param a The first string for comparison.
11
+ * @param b The second string for comparison.
12
+ * @returns The distance between the two strings.
13
+ * @default {levenshteinDistance}
14
+ */
3
15
  compareFn?: (a: string, b: string) => number;
4
16
  }
17
+ /**
18
+ * Takes a string and generates a comparator function to determine which of two
19
+ * strings is more similar to the given one.
20
+ *
21
+ * By default, calculates the distance between words using the
22
+ * {@link https://en.wikipedia.org/wiki/Levenshtein_distance | Levenshtein distance}.
23
+ * @param givenWord The string to measure distance against.
24
+ * @param options Options for the sort.
25
+ * @returns The difference in distance. This will be a negative number if `a`
26
+ * is more similar to `givenWord` than `b`, a positive number if `b` is more
27
+ * similar, or `0` if they are equally similar.
28
+ * @example Usage
29
+ *
30
+ * Most-similar words will be at the start of the array.
31
+ *
32
+ * ```ts
33
+ * import { compareSimilarity } from "@visulima/string";
34
+ * import assert from "node:assert";
35
+ *
36
+ * const words = ["hi", "hello", "help"];
37
+ * const sortedWords = words.toSorted(compareSimilarity("hep"));
38
+ *
39
+ * assert.deepStrictEqual(sortedWords, ["help", "hi", "hello"]);
40
+ * ```
41
+ */
5
42
  declare const compareSimilarity: (givenWord: string, options?: CompareSimilarityOptions) => (a: string, b: string) => number;
6
43
  export { CompareSimilarityOptions, compareSimilarity };
@@ -1,12 +1 @@
1
- import { distance } from './packem_shared/closest-IHuSvnSn.js';
2
-
3
- const compareSimilarity = (givenWord, options) => {
4
- const { compareFn: compareFunction = distance } = { ...options };
5
- if (options?.caseSensitive) {
6
- return (a, b) => compareFunction(givenWord, a) - compareFunction(givenWord, b);
7
- }
8
- const normalizedGivenWord = givenWord.toLowerCase();
9
- return (a, b) => compareFunction(normalizedGivenWord, a.toLowerCase()) - compareFunction(normalizedGivenWord, b.toLowerCase());
10
- };
11
-
12
- export { compareSimilarity };
1
+ import{distance as i}from"./packem_shared/closest-C6YDQs4m.js";const n=(o,s)=>{const{compareFn:e=i}={...s};if(s?.caseSensitive)return(t,r)=>e(o,t)-e(o,r);const a=o.toLowerCase();return(t,r)=>e(a,t.toLowerCase())-e(a,r.toLowerCase())};export{n as compareSimilarity};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get the count of `substring` in `value`.
3
+ * @param value Content to search in. Will be coerced to string.
4
+ * @param substring Substring to look for, typically one character.
5
+ * @returns Count of `substring`s in `value`.
6
+ * @throws {TypeError} When substring is not a string or is empty.
7
+ */
8
+ declare const countOccurrences: (value: unknown, substring: string) => number;
9
+ export { countOccurrences };
@@ -0,0 +1 @@
1
+ const i=(c,r)=>{const n=String(c);if(typeof r!="string")throw new TypeError("Expected character");if(r.length===0)throw new TypeError("Expected non-empty substring");let e=0,t=n.indexOf(r);for(;t!==-1;){e++;const o=t+r.length;if(o<=t)break;t=n.indexOf(r,o)}return e};export{i as countOccurrences};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Detect the direction of text: left-to-right, right-to-left, or neutral.
3
+ * @param value The string to analyze.
4
+ * @returns The text direction: 'rtl' for right-to-left, 'ltr' for left-to-right, or 'neutral' for neutral.
5
+ */
6
+ declare const direction: (value?: string) => "rtl" | "ltr" | "neutral";
7
+ export { direction };
@@ -0,0 +1 @@
1
+ const e="֑-߿יִ-﷽ﹰ-ﻼ",n="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿",o=new RegExp(`^[^${n}]*[${e}]`),s=new RegExp(`^[^${e}]*[${n}]`),c=(r="")=>{const t=r;return o.test(t)?"rtl":s.test(t)?"ltr":"neutral"};export{c as direction};
@@ -0,0 +1,58 @@
1
+ type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
2
+ type Options = {
3
+ /**
4
+ Whether to treat an `'ambiguous'` character as wide.
5
+
6
+ @default true
7
+
8
+ @example
9
+ ```
10
+ import {eastAsianWidth} from 'get-east-asian-width';
11
+
12
+ const codePoint = '⛣'.codePointAt(0);
13
+
14
+ console.log(eastAsianWidth(codePoint));
15
+ //=> 1
16
+
17
+ console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
18
+ //=> 2
19
+ ```
20
+
21
+ > Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
22
+ > - http://www.unicode.org/reports/tr11/
23
+ */
24
+ readonly ambiguousAsWide?: boolean;
25
+ };
26
+ /**
27
+ Returns the width as a number for the given code point.
28
+
29
+ @param codePoint - A Unicode code point.
30
+
31
+ @example
32
+ ```
33
+ import {eastAsianWidth} from 'get-east-asian-width';
34
+
35
+ const codePoint = '字'.codePointAt(0);
36
+
37
+ console.log(eastAsianWidth(codePoint));
38
+ //=> 2
39
+ ```
40
+ */
41
+ declare function eastAsianWidth(codePoint: number, options?: Options): 1 | 2;
42
+ /**
43
+ Returns the type of “East Asian Width” for the given code point.
44
+
45
+ @param codePoint - A Unicode code point.
46
+
47
+ @example
48
+ ```
49
+ import {eastAsianWidthType} from 'get-east-asian-width';
50
+
51
+ const codePoint = '字'.codePointAt(0);
52
+
53
+ console.log(eastAsianWidthType(codePoint));
54
+ //=> 'wide'
55
+ ```
56
+ */
57
+ declare function eastAsianWidthType(codePoint: number): WidthType;
58
+ export { type Options as EastAsianWidthOptions, type WidthType as EastAsianWidthType, eastAsianWidth, eastAsianWidthType };
@@ -0,0 +1 @@
1
+ import{eastAsianWidth as e,eastAsianWidthType as i}from"./packem_shared/eastAsianWidth-DJV8Kqd-.js";export{e as eastAsianWidth,i as eastAsianWidthType};
@@ -0,0 +1,25 @@
1
+ import { TruncateOptions } from "./truncate.js";
2
+ import "./get-string-truncated-width.js";
3
+ /**
4
+ * Truncates a sentence to be under the given character limit and strips HTML tags from it.
5
+ * This function first removes all HTML tags and decodes HTML entities, then truncates
6
+ * the resulting plain text to the specified character limit using the truncate function.
7
+ * @example
8
+ * ```typescript
9
+ * excerpt('<p>Hello <strong>world</strong>!</p>', 10);
10
+ * // => 'Hello worl…'
11
+ *
12
+ * excerpt('<div>This is a <em>long</em> text</div>', 20, { ellipsis: '...' });
13
+ * // => 'This is a long text'
14
+ * ```
15
+ * @param html The HTML string to truncate
16
+ * @param limit Maximum character limit for the truncated string
17
+ * @param options Configuration options for truncation
18
+ * @returns The truncated plain text string with HTML tags removed
19
+ */
20
+ declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
21
+ /**
22
+ * Options for the excerpt function
23
+ */
24
+ type ExcerptOptions = Omit<TruncateOptions, "position">;
25
+ export { ExcerptOptions, excerpt };