@visulima/string 3.0.0 → 3.1.1

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 (117) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE.md +55 -129
  3. package/README.md +2 -2
  4. package/dist/align-text.d.ts +29 -29
  5. package/dist/align-text.js +2 -2
  6. package/dist/case/camel-case.d.ts +16 -16
  7. package/dist/case/camel-case.js +1 -1
  8. package/dist/case/capital-case.d.ts +13 -13
  9. package/dist/case/capital-case.js +1 -1
  10. package/dist/case/constant-case.d.ts +13 -13
  11. package/dist/case/constant-case.js +1 -1
  12. package/dist/case/dot-case.d.ts +13 -13
  13. package/dist/case/dot-case.js +1 -1
  14. package/dist/case/flat-case.d.ts +11 -11
  15. package/dist/case/flat-case.js +1 -1
  16. package/dist/case/flip-case.d.ts +14 -14
  17. package/dist/case/flip-case.js +1 -1
  18. package/dist/case/identify-case.d.ts +14 -14
  19. package/dist/case/identify-case.js +1 -1
  20. package/dist/case/index.d.ts +7 -7
  21. package/dist/case/index.js +1 -1
  22. package/dist/case/kebab-case.d.ts +22 -22
  23. package/dist/case/kebab-case.js +1 -1
  24. package/dist/case/lower-first.d.ts +12 -12
  25. package/dist/case/lower-first.js +1 -1
  26. package/dist/case/no-case.d.ts +13 -13
  27. package/dist/case/no-case.js +1 -1
  28. package/dist/case/pascal-case.d.ts +16 -16
  29. package/dist/case/pascal-case.js +1 -1
  30. package/dist/case/pascal-snake-case.d.ts +13 -13
  31. package/dist/case/pascal-snake-case.js +1 -1
  32. package/dist/case/path-case.d.ts +13 -13
  33. package/dist/case/path-case.js +1 -1
  34. package/dist/case/sentence-case.d.ts +13 -13
  35. package/dist/case/sentence-case.js +1 -1
  36. package/dist/case/snake-case.d.ts +13 -13
  37. package/dist/case/snake-case.js +1 -1
  38. package/dist/case/split-by-case.d.ts +20 -20
  39. package/dist/case/split-by-case.js +1 -1
  40. package/dist/case/title-case.d.ts +11 -11
  41. package/dist/case/title-case.js +1 -1
  42. package/dist/case/train-case.d.ts +13 -13
  43. package/dist/case/train-case.js +1 -1
  44. package/dist/case/upper-first.d.ts +12 -12
  45. package/dist/case/upper-first.js +1 -1
  46. package/dist/closest-string.d.ts +28 -28
  47. package/dist/closest-string.js +1 -1
  48. package/dist/compare-similarity.d.ts +33 -33
  49. package/dist/compare-similarity.js +1 -1
  50. package/dist/count-occurrences.d.ts +6 -6
  51. package/dist/count-occurrences.js +1 -1
  52. package/dist/direction.d.ts +4 -4
  53. package/dist/direction.js +1 -1
  54. package/dist/east-asian-width.d.ts +25 -15
  55. package/dist/east-asian-width.js +1 -1
  56. package/dist/excerpt.d.ts +18 -18
  57. package/dist/excerpt.js +55 -44
  58. package/dist/get-string-truncated-width.d.ts +131 -131
  59. package/dist/get-string-truncated-width.js +1 -1
  60. package/dist/get-string-width.d.ts +56 -56
  61. package/dist/indent.d.ts +11 -8
  62. package/dist/indent.js +1 -1
  63. package/dist/index.d.ts +4 -4
  64. package/dist/index.js +1 -1
  65. package/dist/is-fullwidth-code-point.d.ts +4 -4
  66. package/dist/is-fullwidth-code-point.js +1 -1
  67. package/dist/levenshtein.d.ts +19 -19
  68. package/dist/levenshtein.js +1 -1
  69. package/dist/native-string-types.d.ts +212 -228
  70. package/dist/outdent.d.ts +64 -64
  71. package/dist/outdent.js +1 -1
  72. package/dist/packem_shared/{_isFullWidth-Dqc3MWgl.js → _isFullWidth-dWWDw5Is.js} +1 -1
  73. package/dist/packem_shared/ansi-state-tracker-BFhXTS-5.js +1 -0
  74. package/dist/packem_shared/closest-CSX4px2F.js +1 -0
  75. package/dist/packem_shared/constants-BGGeBKGT.js +1 -0
  76. package/dist/packem_shared/dedent-CDXp3nZQ.js +1 -0
  77. package/dist/packem_shared/eastAsianWidth-DACe9Ds2.js +1 -0
  78. package/dist/packem_shared/generate-cache-key-th9N8-CB.js +1 -0
  79. package/dist/packem_shared/indent-CY079Qyq.js +1 -0
  80. package/dist/packem_shared/joinSegments-9qx7xSy7.js +1 -0
  81. package/dist/packem_shared/{lru-cache-BtMSrYQJ.js → lru-cache-BD25OaEQ.js} +1 -1
  82. package/dist/packem_shared/normalize-german-eszett-DtW4F-Wg.js +1 -0
  83. package/dist/packem_shared/redent-lctoaAtw.js +1 -0
  84. package/dist/packem_shared/strip-vt-control-characters-vMeu7uFw.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 +7 -7
  88. package/dist/replace-string.js +1 -1
  89. package/dist/slice.d.ts +38 -38
  90. package/dist/slice.js +1 -1
  91. package/dist/slugify.d.ts +9 -9
  92. package/dist/slugify.js +1 -1
  93. package/dist/test/utils.d.ts +14 -14
  94. package/dist/test/utils.js +11 -11
  95. package/dist/test/vitest.d.ts +2 -2
  96. package/dist/transliterate.d.ts +7 -7
  97. package/dist/transliterate.js +3 -3
  98. package/dist/truncate.d.ts +37 -37
  99. package/dist/truncate.js +1 -1
  100. package/dist/utilities.d.ts +23 -23
  101. package/dist/utilities.js +1 -1
  102. package/dist/word-similarity-sort.d.ts +32 -32
  103. package/dist/word-similarity-sort.js +1 -1
  104. package/dist/word-wrap.d.ts +33 -33
  105. package/dist/word-wrap.js +5 -7
  106. package/package.json +1 -1
  107. package/dist/packem_shared/closest-C6YDQs4m.js +0 -1
  108. package/dist/packem_shared/constants-aPzGW29R.js +0 -1
  109. package/dist/packem_shared/dedent-CPjAYUXh.js +0 -1
  110. package/dist/packem_shared/eastAsianWidth-DJV8Kqd-.js +0 -1
  111. package/dist/packem_shared/generate-cache-key-BqU1Cqwm.js +0 -1
  112. package/dist/packem_shared/indent-cz8WMI0e.js +0 -1
  113. package/dist/packem_shared/joinSegments-CaHT-45s.js +0 -1
  114. package/dist/packem_shared/normalize-german-eszett-hNMwtGjd.js +0 -1
  115. package/dist/packem_shared/redent-ByOoJ6fN.js +0 -1
  116. package/dist/packem_shared/types.d-CmNvyl4l.d.ts +0 -360
  117. package/dist/packem_shared/types.d-fhe030jX.d.ts +0 -402
@@ -1,14 +1,14 @@
1
- import { b as CaseOptions, T as TitleCase } from "../packem_shared/types.d-fhe030jX.js";
2
- import "../packem_shared/types.d-CmNvyl4l.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
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
+ * 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
+ */
13
13
  declare function titleCase<T extends string = string>(value?: T, options?: CaseOptions): TitleCase<T>;
14
14
  export { titleCase as default };
@@ -1 +1 @@
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{n as p}from"../packem_shared/generate-cache-key-BqU1Cqwm.js";import{a as f}from"../packem_shared/normalize-german-eszett-hNMwtGjd.js";const d=new e(1e3);function y(t,o){if(typeof t!="string")return"";const a=o?.cache??!1,i=o?.cacheStore??d;let r;if(a&&(r=p(t,o)),a&&r&&i.has(r))return i.get(r);const n=c(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(s=>{const l=o?.locale?.startsWith("de")?f(s):s;return m(o?.locale?l.toLocaleLowerCase(o.locale):l.toLowerCase(),{locale:o?.locale})}).join(" ");return a&&r&&i.set(r,n),n}export{y as default};
1
+ import{L as n}from"../packem_shared/lru-cache-BD25OaEQ.js";import{splitByCase as o}from"./split-by-case.js";import i from"./upper-first.js";import{g as h}from"../packem_shared/generate-cache-key-th9N8-CB.js";import{n as f}from"../packem_shared/normalize-german-eszett-DtW4F-Wg.js";const d=new n(1e3);function z(a,e){if(typeof a!="string")return"";const t=e?.cache??!1,l=e?.cacheStore??d;let r;if(t&&(r=h(a,e)),t&&r&&l.has(r))return l.get(r);const c=o(a,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(s=>{const m=e?.locale?.startsWith("de")?f(s):s;return i(e?.locale?m.toLocaleLowerCase(e.locale):m.toLowerCase(),{locale:e?.locale})}).join(" ");return t&&r&&l.set(r,c),c}export{z as default};
@@ -1,16 +1,16 @@
1
- import { b as CaseOptions, j as TrainCase } from "../packem_shared/types.d-fhe030jX.js";
2
- import "../packem_shared/types.d-CmNvyl4l.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
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
+ * 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
+ */
15
15
  declare const trainCase: <T extends string = string>(value?: T, options?: CaseOptions) => TrainCase<T>;
16
16
  export { trainCase as default };
@@ -1 +1 @@
1
- import{i as a}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as l}from"./split-by-case.js";import e from"./upper-first.js";import{n as p}from"../packem_shared/generate-cache-key-BqU1Cqwm.js";import c from"../packem_shared/joinSegments-CaHT-45s.js";const f=new a(1e3),y=(n,o)=>{if(typeof n!="string")return"";const t=o?.cache??!1,i=o?.cacheStore??f;let r;if(t&&(r=p(n,o)),t&&r&&i.has(r))return i.get(r);const s=c(l(n,{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(m=>e(m,{locale:o?.locale})),"-");return t&&r&&i.set(r,s),s};export{y as default};
1
+ import{L as n}from"../packem_shared/lru-cache-BD25OaEQ.js";import{splitByCase as i}from"./split-by-case.js";import l from"./upper-first.js";import{g as o}from"../packem_shared/generate-cache-key-th9N8-CB.js";import h from"../packem_shared/joinSegments-9qx7xSy7.js";const f=new n(1e3),C=(a,e)=>{if(typeof a!="string")return"";const t=e?.cache??!1,c=e?.cacheStore??f;let r;if(t&&(r=o(a,e)),t&&r&&c.has(r))return c.get(r);const s=h(i(a,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(m=>l(m,{locale:e?.locale})),"-");return t&&r&&c.set(r,s),s};export{C as default};
@@ -1,15 +1,15 @@
1
- import { L as LocaleOptions, U as UpperFirst } from "../packem_shared/types.d-fhe030jX.js";
2
- import "../packem_shared/types.d-CmNvyl4l.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
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
+ * 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
+ */
14
14
  declare const upperFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => UpperFirst<T>;
15
15
  export { upperFirst as default };
@@ -1 +1 @@
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
+ const s=(r,t)=>typeof r!="string"||r===""?"":(t?.locale?r[0].toLocaleUpperCase(t.locale):r[0].toUpperCase())+r.slice(1);export{s as default};
@@ -1,38 +1,38 @@
1
1
  /** Options for {@linkcode closestString}. */
2
2
  interface ClosestStringOptions {
3
3
  /**
4
- * Whether the distance should include case.
5
- * @default {false}
6
- */
4
+ * Whether the distance should include case.
5
+ * @default {false}
6
+ */
7
7
  caseSensitive?: boolean;
8
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
- */
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
+ */
15
15
  compareFn?: (a: string, b: string) => number;
16
16
  }
17
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
- */
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
+ */
37
37
  declare const closestString: (givenWord: string, possibleWords: ReadonlyArray<string>, options?: ClosestStringOptions) => string | undefined;
38
38
  export { ClosestStringOptions, closestString };
@@ -1 +1 @@
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
+ import{distance as f}from"./packem_shared/closest-CSX4px2F.js";const h=(o,t,l)=>{if(t.length===0)throw new TypeError("When using closestString(), the possibleWords array must contain at least one word");const{caseSensitive:n,compareFn:r=f}={...l},s=n?o:o.toLowerCase();let c=t[0]??void 0,i=1/0;for(const d of t){const e=d,a=n?r(s,e):r(s,e.toLowerCase());a<i&&(c=e,i=a)}return c};export{h as closestString};
@@ -1,43 +1,43 @@
1
1
  /** Options for {@linkcode compareSimilarity}. */
2
2
  interface CompareSimilarityOptions {
3
3
  /**
4
- * Whether the distance should include case.
5
- * @default {false}
6
- */
4
+ * Whether the distance should include case.
5
+ * @default {false}
6
+ */
7
7
  caseSensitive?: boolean;
8
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
- */
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
+ */
15
15
  compareFn?: (a: string, b: string) => number;
16
16
  }
17
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
- */
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
+ */
42
42
  declare const compareSimilarity: (givenWord: string, options?: CompareSimilarityOptions) => (a: string, b: string) => number;
43
43
  export { CompareSimilarityOptions, compareSimilarity };
@@ -1 +1 @@
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};
1
+ import{distance as n}from"./packem_shared/closest-CSX4px2F.js";const s=(o,a)=>{const{compareFn:e=n}={...a};if(a?.caseSensitive)return(r,t)=>e(o,r)-e(o,t);const c=o.toLowerCase();return(r,t)=>e(c,r.toLowerCase())-e(c,t.toLowerCase())};export{s as compareSimilarity};
@@ -1,9 +1,9 @@
1
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
- */
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
8
  declare const countOccurrences: (value: unknown, substring: string) => number;
9
9
  export { countOccurrences };
@@ -1 +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};
1
+ const x=(o,e)=>{const n=String(o);if(typeof e!="string")throw new TypeError("Expected character");if(e.length===0)throw new TypeError("Expected non-empty substring");let r=0,t=n.indexOf(e);for(;t!==-1;){r++;const c=t+e.length;if(c<=t)break;t=n.indexOf(e,c)}return r};export{x as countOccurrences};
@@ -1,7 +1,7 @@
1
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
- */
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
6
  declare const direction: (value?: string) => "rtl" | "ltr" | "neutral";
7
7
  export { direction };
package/dist/direction.js CHANGED
@@ -1 +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};
1
+ const r="֑-߿יִ-﷽ﹰ-ﻼ",e="A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿",o=new RegExp(`^[^${e}]*[${r}]`),s=new RegExp(`^[^${r}]*[${e}]`),c=(n="")=>{const t=n;return o.test(t)?"rtl":s.test(t)?"ltr":"neutral"};export{c as direction};
@@ -1,20 +1,26 @@
1
1
  type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
2
2
  type Options = {
3
3
  /**
4
- Whether to treat an `'ambiguous'` character as wide.
5
- @default true
6
- @example
7
- ```
8
- import {eastAsianWidth} from 'get-east-asian-width';
9
- const codePoint = '⛣'.codePointAt(0);
10
- console.log(eastAsianWidth(codePoint));
11
- //=> 1
12
- console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
13
- //=> 2
14
- ```
15
- > 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.__
16
- > - http://www.unicode.org/reports/tr11/
17
- */
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
+ */
18
24
  readonly ambiguousAsWide?: boolean;
19
25
  };
20
26
  /**
@@ -49,4 +55,8 @@ console.log(eastAsianWidthType(codePoint));
49
55
  ```
50
56
  */
51
57
  declare function eastAsianWidthType(codePoint: number): WidthType;
52
- export { type Options as EastAsianWidthOptions, type WidthType as EastAsianWidthType, eastAsianWidth, eastAsianWidthType };
58
+ export {
59
+
60
+ type Options as EastAsianWidthOptions,
61
+
62
+ type WidthType as EastAsianWidthType, eastAsianWidth, eastAsianWidthType };
@@ -1 +1 @@
1
- import{eastAsianWidth as e,eastAsianWidthType as i}from"./packem_shared/eastAsianWidth-DJV8Kqd-.js";export{e as eastAsianWidth,i as eastAsianWidthType};
1
+ import{eastAsianWidth as e,eastAsianWidthType as i}from"./packem_shared/eastAsianWidth-DACe9Ds2.js";export{e as eastAsianWidth,i as eastAsianWidthType};
package/dist/excerpt.d.ts CHANGED
@@ -1,25 +1,25 @@
1
1
  import { TruncateOptions } from "./truncate.js";
2
2
  import "./get-string-truncated-width.js";
3
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
- */
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
20
  declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
21
21
  /**
22
- * Options for the excerpt function
23
- */
22
+ * Options for the excerpt function
23
+ */
24
24
  type ExcerptOptions = Omit<TruncateOptions, "position">;
25
25
  export { ExcerptOptions, excerpt };