@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,53 +1,53 @@
1
1
  import { StringTruncatedWidthOptions } from "./get-string-truncated-width.js";
2
2
  type TruncateOptions = {
3
3
  /**
4
- * Text appended to the string when it is truncated
5
- * @default '…'
6
- */
4
+ * Text appended to the string when it is truncated
5
+ * @default '…'
6
+ */
7
7
  ellipsis?: string;
8
8
  /**
9
- * Width of the ellipsis string
10
- * If not provided, it will be calculated using getStringTruncatedWidth
11
- */
9
+ * Width of the ellipsis string
10
+ * If not provided, it will be calculated using getStringTruncatedWidth
11
+ */
12
12
  ellipsisWidth?: number;
13
13
  /**
14
- * The position to truncate the string.
15
- * @default 'end'
16
- */
14
+ * The position to truncate the string.
15
+ * @default 'end'
16
+ */
17
17
  position?: "end" | "middle" | "start";
18
18
  /**
19
- * Truncate the string from a whitespace if it is within 3 characters from the actual breaking point.
20
- * @default false
21
- */
19
+ * Truncate the string from a whitespace if it is within 3 characters from the actual breaking point.
20
+ * @default false
21
+ */
22
22
  preferTruncationOnSpace?: boolean;
23
23
  /**
24
- * Width calculation options
25
- */
24
+ * Width calculation options
25
+ */
26
26
  width?: Omit<StringTruncatedWidthOptions, "ellipsis" | "ellipsisWidth" | "limit">;
27
27
  };
28
28
  /**
29
- * Truncates a string to a specified width limit, handling Unicode characters, ANSI escape codes,
30
- * and adding an optional ellipsis.
31
- *
32
- * ANSI Sequence Handling:
33
- * - Valid ANSI sequences (e.g. '\u001b[31m') are preserved and handled as styling
34
- * - Incomplete sequences are preserved as-is
35
- * - Missing terminators are preserved as-is
36
- * @example
37
- * ```typescript
38
- * // Basic usage
39
- * truncate('Hello World', 5); // 'Hello…'
40
- *
41
- * // With valid ANSI styling
42
- * truncate('\u001b[31mRed\u001b[0m Text', 3); // '\u001b[31mRed\u001b[0m…'
43
- *
44
- * // With invalid ANSI sequence
45
- * truncate('\u001b[abcText', 4); // '\u001b[abcText'
46
- * ```
47
- * @param input The string to truncate
48
- * @param limit Maximum width of the returned string
49
- * @param options Configuration options for truncation
50
- * @returns The truncated string with ellipsis if applicable
51
- */
29
+ * Truncates a string to a specified width limit, handling Unicode characters, ANSI escape codes,
30
+ * and adding an optional ellipsis.
31
+ *
32
+ * ANSI Sequence Handling:
33
+ * - Valid ANSI sequences (e.g. '\u001b[31m') are preserved and handled as styling
34
+ * - Incomplete sequences are preserved as-is
35
+ * - Missing terminators are preserved as-is
36
+ * @example
37
+ * ```typescript
38
+ * // Basic usage
39
+ * truncate('Hello World', 5); // 'Hello…'
40
+ *
41
+ * // With valid ANSI styling
42
+ * truncate('\u001b[31mRed\u001b[0m Text', 3); // '\u001b[31mRed\u001b[0m…'
43
+ *
44
+ * // With invalid ANSI sequence
45
+ * truncate('\u001b[abcText', 4); // '\u001b[abcText'
46
+ * ```
47
+ * @param input The string to truncate
48
+ * @param limit Maximum width of the returned string
49
+ * @param options Configuration options for truncation
50
+ * @returns The truncated string with ellipsis if applicable
51
+ */
52
52
  declare const truncate: (input: string, limit: number, options?: TruncateOptions) => string;
53
53
  export { TruncateOptions, truncate };
package/dist/truncate.js CHANGED
@@ -1 +1 @@
1
- import{getStringTruncatedWidth as g}from"./get-string-truncated-width.js";import{getStringWidth as S}from"./get-string-width.js";import{slice as n}from"./slice.js";const x="…",N=3,u=(r,e,t=!1)=>{if(r.charAt(e)===" ")return e;const i=t?1:-1,d=Math.min(N,t?r.length-e:e);for(let w=1;w<=d;w++){const l=e+w*i;if(r.charAt(l)===" ")return l}return e},f=(r,e,t)=>g(r,{...t,ellipsis:"",ellipsisWidth:0,limit:e}).index,m=(r,e,t)=>S(r.slice(0,e),t),v=(r,e,t={})=>{if(typeof r!="string")throw new TypeError(`Expected \`input\` to be a string, got ${typeof r}`);if(typeof e!="number")throw new TypeError(`Expected \`limit\` to be a number, got ${typeof e}`);if(r===""||e<=0)return"";const i=r.normalize("NFC"),{ellipsis:d=x,position:w="end",preferTruncationOnSpace:l=!1}=t;let o=t.ellipsisWidth??(d===x?1:void 0);o??=g(d,{...t.width,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width;const{width:h}=g(i,{...t.width,ellipsis:d,ellipsisWidth:o});if(h<=e)return i;switch(w){case"end":{if(l){const p=e-o,a=f(i,p,t.width),s=u(i,a),c=m(i,s,t.width);return n(i,0,c,{width:t.width})+d}return n(i,0,e-o,{width:t.width})+d}case"middle":{const p=Math.floor(e/2),a=Math.max(0,e-o),s=Math.min(p,a),c=Math.max(0,a-s);if(l){const E=f(i,s,t.width),I=u(i,E),T=m(i,I,t.width),W=h-c,b=f(i,W,t.width),y=u(i,b,!0),M=m(i,y,t.width);return n(i,0,T,{width:t.width})+d+n(i,M,h,{width:t.width}).trim()}return n(i,0,s,{width:t.width})+d+n(i,h-c,h,{width:t.width})}case"start":{if(l){const p=h-e+o,a=f(i,p,t.width),s=u(i,a,!0),c=m(i,s,t.width);return d+n(i,c,h,{width:t.width}).trim()}return d+n(i,h-e+o,h,{width:t.width})}default:throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${w}'`)}};export{v as truncate};
1
+ import{getStringTruncatedWidth as m}from"./get-string-truncated-width.js";import{getStringWidth as B}from"./get-string-width.js";import{slice as h}from"./slice.js";const S="…",y=3,u=(i,r,t=!1)=>{if(i.charAt(r)===" ")return r;const e=t?1:-1,d=Math.min(y,t?i.length-r:r);for(let a=1;a<=d;a++){const o=r+a*e;if(i.charAt(o)===" ")return o}return r},W=(i,r,t)=>m(i,{...t,ellipsis:"",ellipsisWidth:0,limit:r}).index,g=(i,r,t)=>B(i.slice(0,r),t),_=(i,r,t={})=>{if(typeof i!="string")throw new TypeError(`Expected \`input\` to be a string, got ${typeof i}`);if(typeof r!="number")throw new TypeError(`Expected \`limit\` to be a number, got ${typeof r}`);if(i===""||r<=0)return"";const e=i.normalize("NFC"),{ellipsis:d=S,position:a="end",preferTruncationOnSpace:o=!1}=t;let c=t.ellipsisWidth??(d===S?1:void 0);c??=m(d,{...t.width,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width;const{width:n}=m(e,{...t.width,ellipsis:d,ellipsisWidth:c});if(n<=r)return e;switch(a){case"end":{if(o){const l=r-c,w=W(e,l,t.width),s=u(e,w),f=g(e,s,t.width);return h(e,0,f,{width:t.width})+d}return h(e,0,r-c,{width:t.width})+d}case"middle":{const l=Math.floor(r/2),w=Math.max(0,r-c),s=Math.min(l,w),f=Math.max(0,w-s);if(o){const T=W(e,s,t.width),E=u(e,T),x=g(e,E,t.width),I=n-f,p=W(e,I,t.width),A=u(e,p,!0),k=g(e,A,t.width);return h(e,0,x,{width:t.width})+d+h(e,k,n,{width:t.width}).trim()}return h(e,0,s,{width:t.width})+d+h(e,n-f,n,{width:t.width})}case"start":{if(o){const l=n-r+c,w=W(e,l,t.width),s=u(e,w,!0),f=g(e,s,t.width);return d+h(e,f,n,{width:t.width}).trim()}return d+h(e,n-r+c,n,{width:t.width})}default:throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${a}'`)}};export{_ as truncate};
@@ -1,34 +1,34 @@
1
- import { e as IntervalArray } from "./packem_shared/types.d-CmNvyl4l.js";
1
+ import { e as IntervalArray } from "./packem_shared/types.d-LgsTR37y.js";
2
2
  /**
3
- * Escapes characters with special meaning in regular expressions.
4
- * @param char The string to escape.
5
- * @returns The escaped string.
6
- */
3
+ * Escapes characters with special meaning in regular expressions.
4
+ * @param char The string to escape.
5
+ * @returns The escaped string.
6
+ */
7
7
  declare const escapeRegExp: (char: string) => string;
8
8
  /**
9
- * Checks if a number falls within any of the specified intervals.
10
- * @param number_ The number to check.
11
- * @param ranges An array of intervals [start, end].
12
- * @returns True if the number is within any interval, false otherwise.
13
- */
9
+ * Checks if a number falls within any of the specified intervals.
10
+ * @param number_ The number to check.
11
+ * @param ranges An array of intervals [start, end].
12
+ * @returns True if the number is within any interval, false otherwise.
13
+ */
14
14
  declare const inRange: (number_: number, ranges: IntervalArray) => boolean;
15
15
  /**
16
- * Checks if a string contains Chinese characters (Han script).
17
- * @param char The string to check.
18
- * @returns True if the string contains Chinese characters, false otherwise.
19
- */
16
+ * Checks if a string contains Chinese characters (Han script).
17
+ * @param char The string to check.
18
+ * @returns True if the string contains Chinese characters, false otherwise.
19
+ */
20
20
  declare const hasChinese: (char: string) => boolean;
21
21
  /**
22
- * Checks if a string contains punctuation or space characters.
23
- * @param char The string to check.
24
- * @returns True if the string contains punctuation or space, false otherwise.
25
- */
22
+ * Checks if a string contains punctuation or space characters.
23
+ * @param char The string to check.
24
+ * @returns True if the string contains punctuation or space, false otherwise.
25
+ */
26
26
  declare const hasPunctuationOrSpace: (char: string) => boolean;
27
27
  /**
28
- * Finds all occurrences of a set of substrings within a source string and returns their start/end indices.
29
- * @param source The string to search within.
30
- * @param needles An array of strings to search for.
31
- * @returns An array of intervals [start, end] for each occurrence.
32
- */
28
+ * Finds all occurrences of a set of substrings within a source string and returns their start/end indices.
29
+ * @param source The string to search within.
30
+ * @param needles An array of strings to search for.
31
+ * @returns An array of intervals [start, end] for each occurrence.
32
+ */
33
33
  declare const findStringOccurrences: (source: string, needles: string[]) => IntervalArray;
34
34
  export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange };
package/dist/utilities.js CHANGED
@@ -1 +1 @@
1
- const i=/[.*+?^${}()|[\]\\]/g,E=/[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3400-\u4DBF\u4E00-\u9FFC\uF900-\uFA6D\uFA70-\uFAD9]|\uD81B[\uDFF0\uDFF1]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD869[\uDC00-\uDEDD\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A]/,a=/[\p{P}\p{Z}]/u,c=D=>D.replaceAll(i,String.raw`\$&`),C=(D,e)=>e.some(t=>D>=t[0]&&D<=t[1]),h=D=>E.test(D),p=D=>a.test(D),f=(D,e)=>{const t=[];if(!Array.isArray(e))return t;if(e.forEach(u=>{if(typeof u!="string"||u.length===0)return;let n=0,r;for(;(r=D.indexOf(u,n))>-1;){const o=r+u.length-1;t.push([r,o]),n=r+1}}),t.length===0)return[];t.sort((u,n)=>u[0]-n[0]);const s=[];let F;for(const u of t)F===void 0?F=[...u]:u[0]<=F[1]+1?F[1]=Math.max(F[1],u[1]):(s.push(F),F=[...u]);return F!==void 0&&s.push(F),s};export{c as escapeRegExp,f as findStringOccurrences,h as hasChinese,p as hasPunctuationOrSpace,C as inRange};
1
+ const o=/[.*+?^${}()|[\]\\]/g,c=/[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3400-\u4DBF\u4E00-\u9FFC\uF900-\uFA6D\uFA70-\uFAD9]|\uD81B[\uDFF0\uDFF1]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD869[\uDC00-\uDEDD\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A]/,i=/[\p{P}\p{Z}]/u,C=D=>D.replaceAll(o,String.raw`\$&`),a=(D,n)=>n.some(F=>D>=F[0]&&D<=F[1]),A=D=>c.test(D),f=D=>i.test(D),g=(D,n)=>{const F=[];if(!Array.isArray(n))return F;if(n.forEach(u=>{if(typeof u!="string"||u.length===0)return;let s=0,r;for(;(r=D.indexOf(u,s))>-1;){const E=r+u.length-1;F.push([r,E]),s=r+1}}),F.length===0)return[];F.sort((u,s)=>u[0]-s[0]);const e=[];let t;for(const u of F)t===void 0?t=[...u]:u[0]<=t[1]+1?t[1]=Math.max(t[1],u[1]):(e.push(t),t=[...u]);return t!==void 0&&e.push(t),e};export{C as escapeRegExp,g as findStringOccurrences,A as hasChinese,f as hasPunctuationOrSpace,a as inRange};
@@ -4,37 +4,37 @@ interface WordSimilaritySortOptions {
4
4
  compareFunction?: (a: string, b: string) => number;
5
5
  }
6
6
  /**
7
- * Sorts a string-array by similarity to a given string.
8
- *
9
- * By default, calculates the distance between words using the
10
- * {@link https://en.wikipedia.org/wiki/Levenshtein_distance | Levenshtein distance}.
11
- * @example Basic usage
12
- *
13
- * ```ts
14
- * import { wordSimilaritySort } from "@visulima/string";
15
- * import assert from "node:assert";
16
- *
17
- * const possibleWords = ["length", "size", "blah", "help"];
18
- * const suggestions = wordSimilaritySort("hep", possibleWords);
19
- *
20
- * assert.deepStrictEqual(suggestions, ["help", "size", "blah", "length"]);
21
- * ```
22
- * @example Case-sensitive sorting
23
- *
24
- * ```ts
25
- * import { wordSimilaritySort } from "@visulima/string";
26
- * import assert from "node:assert";
27
- *
28
- * const possibleWords = ["length", "Size", "blah", "HELP"];
29
- * const suggestions = wordSimilaritySort("hep", possibleWords, { caseSensitive: true });
30
- *
31
- * assert.deepStrictEqual(suggestions, ["Size", "blah", "HELP", "length"]);
32
- * ```
33
- * @param givenWord The string to measure distance against.
34
- * @param possibleWords The string-array that will be sorted. This array will
35
- * not be mutated, but the sorted copy will be returned.
36
- * @param options Options for the sort.
37
- * @returns A sorted copy of `possibleWords`.
38
- */
7
+ * Sorts a string-array by similarity to a given string.
8
+ *
9
+ * By default, calculates the distance between words using the
10
+ * {@link https://en.wikipedia.org/wiki/Levenshtein_distance | Levenshtein distance}.
11
+ * @example Basic usage
12
+ *
13
+ * ```ts
14
+ * import { wordSimilaritySort } from "@visulima/string";
15
+ * import assert from "node:assert";
16
+ *
17
+ * const possibleWords = ["length", "size", "blah", "help"];
18
+ * const suggestions = wordSimilaritySort("hep", possibleWords);
19
+ *
20
+ * assert.deepStrictEqual(suggestions, ["help", "size", "blah", "length"]);
21
+ * ```
22
+ * @example Case-sensitive sorting
23
+ *
24
+ * ```ts
25
+ * import { wordSimilaritySort } from "@visulima/string";
26
+ * import assert from "node:assert";
27
+ *
28
+ * const possibleWords = ["length", "Size", "blah", "HELP"];
29
+ * const suggestions = wordSimilaritySort("hep", possibleWords, { caseSensitive: true });
30
+ *
31
+ * assert.deepStrictEqual(suggestions, ["Size", "blah", "HELP", "length"]);
32
+ * ```
33
+ * @param givenWord The string to measure distance against.
34
+ * @param possibleWords The string-array that will be sorted. This array will
35
+ * not be mutated, but the sorted copy will be returned.
36
+ * @param options Options for the sort.
37
+ * @returns A sorted copy of `possibleWords`.
38
+ */
39
39
  declare const wordSimilaritySort: (givenWord: string, possibleWords: ReadonlyArray<string>, options?: WordSimilaritySortOptions) => string[];
40
40
  export { WordSimilaritySortOptions, wordSimilaritySort };
@@ -1 +1 @@
1
- import{distance as d}from"./packem_shared/closest-C6YDQs4m.js";const m=(e,t,n)=>{const{caseSensitive:i=!1,compareFunction:s=d}=n??{},c=i?e:e.toLowerCase(),r=t.map(o=>{const a=i?o:o.toLowerCase();return{distance:s(c,a),originalWord:o}});return r.sort((o,a)=>o.distance!==a.distance?o.distance-a.distance:o.originalWord.localeCompare(a.originalWord)),r.map(o=>o.originalWord)};export{m as wordSimilaritySort};
1
+ import{distance as d}from"./packem_shared/closest-CSX4px2F.js";const p=(e,s,n)=>{const{caseSensitive:t=!1,compareFunction:a=d}=n??{},c=t?e:e.toLowerCase(),i=s.map(o=>{const r=t?o:o.toLowerCase();return{distance:a(c,r),originalWord:o}});return i.sort((o,r)=>o.distance!==r.distance?o.distance-r.distance:o.originalWord.localeCompare(r.originalWord)),i.map(o=>o.originalWord)};export{p as wordSimilaritySort};
@@ -1,58 +1,58 @@
1
1
  /**
2
- * Enum representing different wrapping strategies for text
3
- */
2
+ * Enum representing different wrapping strategies for text
3
+ */
4
4
  declare const WrapMode: {
5
5
  /**
6
- * Breaks words at character boundaries to fit the width
7
- */
6
+ * Breaks words at character boundaries to fit the width
7
+ */
8
8
  readonly BREAK_AT_CHARACTERS: "BREAK_AT_CHARACTERS";
9
9
  /**
10
- * Breaks lines at word boundaries. If a word is longer than the width, it will be broken.
11
- */
10
+ * Breaks lines at word boundaries. If a word is longer than the width, it will be broken.
11
+ */
12
12
  readonly BREAK_WORDS: "BREAK_WORDS";
13
13
  /**
14
- * Preserves word boundaries, words are kept intact even if they exceed width
15
- */
14
+ * Preserves word boundaries, words are kept intact even if they exceed width
15
+ */
16
16
  readonly PRESERVE_WORDS: "PRESERVE_WORDS";
17
17
  /**
18
- * Enforces strict adherence to the width limit by breaking at exact width
19
- */
18
+ * Enforces strict adherence to the width limit by breaking at exact width
19
+ */
20
20
  readonly STRICT_WIDTH: "STRICT_WIDTH";
21
21
  };
22
22
  /**
23
- * Word wrap options interface with detailed documentation
24
- */
23
+ * Word wrap options interface with detailed documentation
24
+ */
25
25
  interface WordWrapOptions {
26
26
  /**
27
- * Whether to remove zero-width characters from the string.
28
- * @default true
29
- */
27
+ * Whether to remove zero-width characters from the string.
28
+ * @default true
29
+ */
30
30
  removeZeroWidthCharacters?: boolean;
31
31
  /**
32
- * Whether to trim whitespace from wrapped lines.
33
- * @default true
34
- */
32
+ * Whether to trim whitespace from wrapped lines.
33
+ * @default true
34
+ */
35
35
  trim?: boolean;
36
36
  /**
37
- * Maximum width of each line in visible characters.
38
- * @default 80
39
- */
37
+ * Maximum width of each line in visible characters.
38
+ * @default 80
39
+ */
40
40
  width?: number;
41
41
  /**
42
- * Controls how text wrapping is handled at width boundaries.
43
- * - PRESERVE_WORDS: Words are kept intact even if they exceed width (default)
44
- * - BREAK_AT_CHARACTERS: Words are broken at character boundaries to fit width
45
- * - STRICT_WIDTH: Forces breaking exactly at width limit, always
46
- * - BREAK_WORDS: Breaks at word boundaries, but breaks words if they are too long
47
- * @default WrapMode.PRESERVE_WORDS
48
- */
42
+ * Controls how text wrapping is handled at width boundaries.
43
+ * - PRESERVE_WORDS: Words are kept intact even if they exceed width (default)
44
+ * - BREAK_AT_CHARACTERS: Words are broken at character boundaries to fit width
45
+ * - STRICT_WIDTH: Forces breaking exactly at width limit, always
46
+ * - BREAK_WORDS: Breaks at word boundaries, but breaks words if they are too long
47
+ * @default WrapMode.PRESERVE_WORDS
48
+ */
49
49
  wrapMode?: keyof typeof WrapMode;
50
50
  }
51
51
  /**
52
- * Wraps text using multiple wrapping strategies.
53
- * @param string The string to wrap
54
- * @param options Wrapping options
55
- * @returns The wrapped string
56
- */
52
+ * Wraps text using multiple wrapping strategies.
53
+ * @param string The string to wrap
54
+ * @param options Wrapping options
55
+ * @returns The wrapped string
56
+ */
57
57
  declare const wordWrap: (string: string, options?: WordWrapOptions) => string;
58
58
  export { WordWrapOptions, WrapMode, wordWrap };
package/dist/word-wrap.js CHANGED
@@ -1,8 +1,6 @@
1
- import{O as m,P as B,Q as v,S as x,T as H,U as $,V as D,W as N,X as y}from"./packem_shared/constants-aPzGW29R.js";import{getStringWidth as E}from"./get-string-width.js";const O=/\x1B\[(\d+)m/;class T{activeForeground=void 0;activeBackground=void 0;activeFormatting=[];processEscape(t){const i=O.exec(t);if(!i)return;const s=Number.parseInt(i[1],10);switch(s){case 0:{this.activeForeground=void 0,this.activeBackground=void 0,this.activeFormatting=[];break}case 39:{this.activeForeground=void 0;break}case 49:{this.activeBackground=void 0;break}default:if(s>=30&&s<=37||s>=90&&s<=97)this.activeForeground=t;else if(s>=40&&s<=47||s>=100&&s<=107)this.activeBackground=t;else if([1,2,3,4,7,8,9].includes(s))this.activeFormatting.push(t);else if([22,23,24,27,28,29].includes(s)){const u={22:"[1m",23:"[3m",24:"[4m",27:"[7m",28:"[8m",29:"[9m"}[s];u&&(this.activeFormatting=this.activeFormatting.filter(n=>!n.includes(u)))}}}getStartEscapesForAllActiveAttributes(){return[this.activeBackground,this.activeForeground,...this.activeFormatting].filter(Boolean).join("")}getEndEscapesForAllActiveAttributes(){const t=[];if(this.activeFormatting.length>0){const i={"\x1B[1m":"\x1B[22m","\x1B[2m":"\x1B[22m","\x1B[3m":"\x1B[23m","\x1B[4m":"\x1B[24m","\x1B[7m":"\x1B[27m","\x1B[8m":"\x1B[28m","\x1B[9m":"\x1B[29m"};[...this.activeFormatting].toReversed().forEach(s=>{const u=i[s];u&&t.push(u)})}return this.activeForeground&&t.push("\x1B[39m"),this.activeBackground&&t.push("\x1B[49m"),t.join("")}}const P=(e,t)=>{if(!m.has(e[t]))return{isInsideEscape:!1,isInsideLinkEscape:!1};const i=!0,s=e.slice(t+1,t+1+v.length).join("")===v;return{isInsideEscape:i,isInsideLinkEscape:s}},q=(e,t={})=>{const i=new T;let s="",u=!1,n="",r="",o=!1;const a=[...e];for(let l=0;l<a.length;l++){const c=a[l];if(c&&m.has(c)){if(s){const g=t.getWidth?.(s)??0,S={isEscapeSequence:!1,isGrapheme:!0,text:s,width:g};if(o&&(S.isHyperlink=!0,S.hyperlinkUrl=r),t.onSegment?.(S,i)===!1)return;s=""}u=!0,n=c;const p=P(a,l),{isInsideLinkEscape:C}=p;if(C){let g=l+1;for(r="";g<a.length;){const _=a[g];if(_===x)break;r+=_,g+=1}r=r.slice(4);const S={hyperlinkUrl:r,isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkStart:!0,width:0};if(t.onSegment?.(S,i)===!1)return;l=g,o=!0,u=!1,n="";continue}if(l+1<a.length&&a[l+1]==="\\"&&o){const g={isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkEnd:!0,width:0};if(t.onSegment?.(g,i)===!1)return;o=!1,r="",l+=1,u=!1,n="";continue}}if(u){if(n!==c&&(n+=c),c===B){u=!1,i.processEscape(n);const p={isEscapeSequence:!0,isGrapheme:!1,text:n,width:0};if(t.onSegment?.(p,i)===!1)return;n=""}continue}s+=c;const h=t.getWidth?.(s)??0,f={isEscapeSequence:!1,isGrapheme:!0,text:s,width:h};if(o&&(f.isHyperlink=!0,f.hyperlinkUrl=r),t.onSegment?.(f,i)===!1)return;s=""}if(s){const l=t.getWidth?.(s)??0,c={isEscapeSequence:!1,isGrapheme:!0,text:s,width:l};o&&(c.isHyperlink=!0,c.hyperlinkUrl=r),t.onSegment?.(c,i)}if(n){const l={isEscapeSequence:!0,isGrapheme:!1,text:n,width:0};t.onSegment?.(l,i)}},k=e=>`${m.values().next().value}${H}${String(e)}${B}`,F=e=>`${m.values().next().value}${v}${e}${x}`,G=e=>{if(e.length===0)return"";if(e.length===1)return e[0];let t="",i,s;const u=e.join(`
2
- `),n=[...u];let r=0;for(const[o,a]of n.entries()){if(t+=a,m.has(a)){const c=$.exec(u.slice(r))?.groups??{};if(c.code!==void 0){const h=Number.parseFloat(c.code);i=h===N?void 0:h}else c.uri!==void 0&&(s=c.uri.length===0?void 0:c.uri)}const l=D.get(Number(i));n[o+1]===`
3
- `?(s&&(t+=F("")),i&&l&&(t+=k(l))):a===`
4
- `&&(i&&l&&(t+=k(i)),s&&(t+=F(s))),r+=a.length}return t},W=/(?=\s)|(?<=\s)/,b=/^\s+$/,I=new Map,j=e=>{const t=I.get(e);if(t!==void 0)return t;const i=E(e);return I.set(e,i),i},R=e=>{if(!e.includes("\x1B"))return e;let t=e;return e.includes("\x1B[30m")&&(t+="\x1B[39m"),e.includes("\x1B[42m")&&(t+="\x1B[49m"),t},d=e=>{const t=e.split(" ");let i=t.length;for(;i>0&&E(t[i-1])===0;)i--;return i===t.length?e:t.slice(0,i).join(" ")+t.slice(i).join("")},w=(e,t,i)=>{if(e.length===0)return[""];if(t<=0)return[e];const s=[],u=new T;let n="",r=0,o=!1,a=!1,l="",c=0;for(;c<e.length;){const h=e[c];if(m.has(h)){o=!0,l=h,n+=h,a=e.startsWith(v,c+1),c+=1;continue}if(o){l+=h,n+=h,a?h===x&&(o=a=!1):h===B&&(o=!1,u.processEscape(l)),c+=1;continue}const f=j(h),p=h===" ";if(f===0){n+=h,c+=1;continue}if(r+f>t&&(n&&s.push(n+u.getEndEscapesForAllActiveAttributes()),n=u.getStartEscapesForAllActiveAttributes(),r=E(n),p&&i)){for(;c<e.length&&e[c]===" ";)c+=1;continue}if(n+=h,r+=f,r===t&&c<e.length-1&&(s.push(n+u.getEndEscapesForAllActiveAttributes()),n=u.getStartEscapesForAllActiveAttributes(),r=E(n),c+1<e.length&&e[c+1]===" "&&i)){for(c+=1;c<e.length&&e[c]===" ";)c+=1;continue}c+=1}return n&&s.push(n+u.getEndEscapesForAllActiveAttributes()),i?s.map(h=>d(h)):s},K=(e,t,i)=>{if(e.length===0)return[];const s=i?e.trim():e;if(s.length===0)return[];const u=[];let n="",r=0;return q(s,{getWidth:E,onSegment:(o,a)=>{const l=o.text??"";if(o.isEscapeSequence)n+=l;else{const c=l===" ";if(o.width===0)return n+=l,!0;if(r+o.width>t&&(n&&u.push(n),n=a.getStartEscapesForAllActiveAttributes(),r=0,c))return i||u.push(a.getStartEscapesForAllActiveAttributes()+l),!0;n+=l,r+=o.width}return!0}}),n&&u.push(n),i?u.map(o=>d(o)):u},L=(e,t,i)=>{if(e.length===0)return[];const s=i?e.trim():e;if(s.length===0)return[];const u=s.split(W),n=[];let r="",o=0,a=0;for(;a<u.length;){const l=u[a],c=b.test(l),h=E(l);if(l.length===0){a+=1;continue}if(i&&c&&o===0){a+=1;continue}if(o+h>t&&o>0){i?n.push(d(r)):n.push(r),r="",o=0;continue}r+=l,o+=h,a+=1}return r&&(i?n.push(d(r)):n.push(r)),n},U=(e,t,i)=>{if(e.length===0)return[];const s=i?e.trim():e;if(s.length===0)return[];const u=s.split(W),n=[];let r="",o=0,a=0;for(;a<u.length;){const l=u[a],c=b.test(l),h=E(l);if(l.length===0){a+=1;continue}if(i&&c&&o===0){a+=1;continue}if(h>t){r&&n.push(R(i?d(r):r));const f=w(l,t,i);if(f.length>0){for(let p=0;p<f.length-1;p+=1)n.push(f[p]);r=f.at(-1),o=E(r)}else r="",o=0;a+=1;continue}if(o+h>t&&o>0&&(n.push(R(i?d(r):r)),r="",o=0,i&&c)){a+=1;continue}r+=l,o+=h,a+=1}return r&&n.push(R(i?d(r):r)),n},A={BREAK_AT_CHARACTERS:"BREAK_AT_CHARACTERS",BREAK_WORDS:"BREAK_WORDS",PRESERVE_WORDS:"PRESERVE_WORDS",STRICT_WIDTH:"STRICT_WIDTH"},Z=(e,t={})=>{const{removeZeroWidthCharacters:i=!0,trim:s=!0,width:u=80,wrapMode:n=A.PRESERVE_WORDS}=t;if(s&&e.trim()==="")return"";let r=e.normalize("NFC").replaceAll(`\r
1
+ import{O as p,P as A,Q as w,S as x}from"./packem_shared/constants-BGGeBKGT.js";import{getStringWidth as g}from"./get-string-width.js";import{A as q}from"./packem_shared/ansi-state-tracker-BFhXTS-5.js";const I=/(?:\u{1B}\[|\u{9B})[\u{30}-\u{3F}]*[\u{20}-\u{2F}]*[\u{40}-\u{7E}]/uy,m=(e,n)=>{if(p.has(e[n])){if(e.startsWith(A,n+1)){const t=e.indexOf(w,n);return t===-1?void 0:e.slice(n,t+1)}return I.lastIndex=n,I.exec(e)?.[0]}},B=(e,n)=>{if(!p.has(e[n]))return{isInsideEscape:!1,isInsideLinkEscape:!1};const t=!0,i=e.slice(n+1,n+1+A.length).join("")===A;return{isInsideEscape:t,isInsideLinkEscape:i}},O=e=>{let n=0;for(let t=0;t<e.length;t+=1)e.codePointAt(t)>65535&&(t+=1),n+=1;return n},D=(e,n={})=>{let t="",r=!1,i=0,c="",s="",l=!1;const o=[...e],h=[];for(let u=0,a=0;u<o.length;u+=1)h.push(a),a+=o[u].length;for(let u=0;u<o.length;u++){const a=o[u];if(a&&p.has(a)){if(t){const d=n.getWidth?.(t)??0,k={isEscapeSequence:!1,isGrapheme:!0,text:t,width:d};if(l&&(k.isHyperlink=!0,k.hyperlinkUrl=s),n.onSegment?.(k)===!1)return;t=""}r=!0,i=u,c=a;const W=B(o,u),{isInsideLinkEscape:C}=W;if(C){let d=u+1;for(s="";d<o.length;){const T=o[d];if(T===w)break;s+=T,d+=1}s=s.slice(4);const k={hyperlinkUrl:s,isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkStart:!0,width:0};if(n.onSegment?.(k)===!1)return;u=d,l=!0,r=!1,c="";continue}if(u+1<o.length&&o[u+1]==="\\"&&l){const d={isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkEnd:!0,width:0};if(n.onSegment?.(d)===!1)return;l=!1,s="",u+=1,r=!1,c="";continue}}if(r){const W=m(e,h[i]);r=!1,W===void 0?(c=o.slice(i).join(""),u=o.length):(c=W,u=i+O(W)-1);const C={isEscapeSequence:!0,isGrapheme:!1,text:c,width:0};if(n.onSegment?.(C)===!1)return;c="";continue}t+=a;const f=n.getWidth?.(t)??0,E={isEscapeSequence:!1,isGrapheme:!0,text:t,width:f};if(l&&(E.isHyperlink=!0,E.hyperlinkUrl=s),n.onSegment?.(E)===!1)return;t=""}if(t){const u=n.getWidth?.(t)??0,a={isEscapeSequence:!1,isGrapheme:!0,text:t,width:u};l&&(a.isHyperlink=!0,a.hyperlinkUrl=s),n.onSegment?.(a)}if(c){const u={isEscapeSequence:!0,isGrapheme:!1,text:c,width:0};n.onSegment?.(u)}},v=e=>`${p.values().next().value}${A}${e}${w}`,N=(e,n,t)=>{let r=t,i=0;for(;i<e.length;){if(!p.has(e[i])){i+=1;continue}const c=m(e,i);if(c===void 0){i+=1;continue}if(e.startsWith(A,i+1)){const s=c.slice(1+A.length,-1);r=s.length===0?void 0:s}else n.processEscape(c);i+=c.length}return r},G=e=>{if(e.length===0)return"";if(e.length===1)return e[0];const n=new q,t=e.length-1;let r="",i;for(const[c,s]of e.entries())c>0&&(r+=n.getStartEscapesForAllActiveAttributes(),i!==void 0&&(r+=v(i))),r+=s,i=N(s,n,i),c<t&&(i!==void 0&&(r+=v("")),r+=n.getEndEscapesForAllActiveAttributes(),r+=`
2
+ `);return r},U=/(?=\s)|(?<=\s)/,K=new Intl.Segmenter("en",{granularity:"grapheme"}),F=/[^\u0000-\u02FF]/,_=/^\s+$/,H=new Map,M=e=>{const n=H.get(e);if(n!==void 0)return n;const t=g(e);return H.set(e,t),t},V=e=>{if(!F.test(e))return[e];const n=[];let t="";for(const{segment:r}of K.segment(e)){if(g(r)>1){t!==""&&(n.push(t),t=""),n.push(r);continue}t+=r}return t!==""&&n.push(t),n},L=e=>e.split(U).flatMap(n=>n===""||_.test(n)?[n]:V(n)),P="x",j=e=>{let n="",t=0;for(;t<e.length;){const r=p.has(e[t])?m(e,t):void 0;if(r===void 0){if(p.has(e[t]))return n+P.repeat(e.length-t);n+=e[t],t+=1;continue}n+=P.repeat(r.length),t+=r.length}return n},y=e=>{if(![...p].some(r=>e.includes(r)))return L(e);const n=[];let t=0;for(const r of L(j(e)))n.push(e.slice(t,t+r.length)),t+=r.length;return n},S=e=>{const n=e.split(" ");let t=n.length;for(;t>0&&g(n[t-1])===0;)t--;return t===n.length?e:n.slice(0,t).join(" ")+n.slice(t).join("")},b=(e,n,t)=>{if(e.length===0)return[""];if(n<=0)return[e];const r=[];let i="",c=0,s=0;for(;s<e.length;){const l=e.codePointAt(s),o=String.fromCodePoint(l),h=o.length;if(p.has(o)){const f=m(e,s);if(f===void 0){i+=e.slice(s);break}i+=f,s+=f.length;continue}const u=M(o),a=o===" ";if(u===0){i+=o,s+=h;continue}if(c+u>n&&(i&&r.push(i),i="",c=0,a&&t)){for(;s<e.length&&e[s]===" ";)s+=1;continue}if(i+=o,c+=u,c===n&&s+h<e.length&&(r.push(i),i="",c=0,s+h<e.length&&e[s+h]===" "&&t)){for(s+=h;s<e.length&&e[s]===" ";)s+=1;continue}s+=h}return i&&r.push(i),t?r.map(l=>S(l)):r},$=(e,n,t)=>{if(e.length===0)return[];const r=t?e.trim():e;if(r.length===0)return[];const i=[];let c="",s=0;return D(r,{getWidth:g,onSegment:l=>{const o=l.text??"";if(l.isEscapeSequence)c+=o;else{const h=o===" ";if(l.width===0)return c+=o,!0;if(s+l.width>n&&(c&&i.push(c),c="",s=0,h))return t||i.push(o),!0;c+=o,s+=l.width}return!0}}),c&&i.push(c),t?i.map(l=>S(l)):i},z=(e,n,t)=>{if(e.length===0)return[];const r=t?e.trim():e;if(r.length===0)return[];const i=y(r),c=[];let s="",l=0,o=0;for(;o<i.length;){const h=i[o],u=_.test(h),a=g(h);if(h.length===0){o+=1;continue}if(t&&u&&l===0){o+=1;continue}if(l+a>n&&l>0){t?c.push(S(s)):c.push(s),s="",l=0;continue}s+=h,l+=a,o+=1}return s&&(t?c.push(S(s)):c.push(s)),c},Q=(e,n,t)=>{if(e.length===0)return[];const r=t?e.trim():e;if(r.length===0)return[];const i=y(r),c=[];let s="",l=0,o=0;for(;o<i.length;){const h=i[o],u=_.test(h),a=g(h);if(h.length===0){o+=1;continue}if(t&&u&&l===0){o+=1;continue}if(a>n){s&&c.push(t?S(s):s);const f=b(h,n,t);if(f.length>0){for(let E=0;E<f.length-1;E+=1)c.push(f[E]);s=f.at(-1),l=g(s)}else s="",l=0;o+=1;continue}if(l+a>n&&l>0&&(c.push(t?S(s):s),s="",l=0,t&&u)){o+=1;continue}s+=h,l+=a,o+=1}return s&&c.push(t?S(s):s),c},R={BREAK_AT_CHARACTERS:"BREAK_AT_CHARACTERS",BREAK_WORDS:"BREAK_WORDS",PRESERVE_WORDS:"PRESERVE_WORDS",STRICT_WIDTH:"STRICT_WIDTH"},X=(e,n={})=>{const{removeZeroWidthCharacters:t=!0,trim:r=!0,width:i=80,wrapMode:c=R.PRESERVE_WORDS}=n;if(r&&e.trim()==="")return"";let s=e.normalize("NFC").replaceAll(`\r
5
3
  `,`
6
- `);return i&&(r=r.replaceAll(y,"")),r.split(`
7
- `).map(o=>{if(s&&o.trim()==="")return"";let a;switch(n){case A.BREAK_AT_CHARACTERS:{a=K(o,u,s);break}case A.BREAK_WORDS:{a=U(o,u,s);break}case A.STRICT_WIDTH:{a=w(o,u,s);break}default:a=L(o,u,s)}return G(a)}).join(`
8
- `)};export{A as WrapMode,Z as wordWrap};
4
+ `);return t&&(s=s.replaceAll(x,"")),s.split(`
5
+ `).map(o=>{if(r&&o.trim()==="")return"";let h;switch(c){case R.BREAK_AT_CHARACTERS:{h=$(o,i,r);break}case R.BREAK_WORDS:{h=Q(o,i,r);break}case R.STRICT_WIDTH:{h=b(o,i,r);break}default:h=z(o,i,r)}return G(h)}).join(`
6
+ `)};export{R as WrapMode,X as wordWrap};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/string",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "Functions for manipulating strings.",
5
5
  "keywords": [
6
6
  "align",
@@ -1 +0,0 @@
1
- const i=new Uint32Array(65536),q=(r,l)=>{const o=r.length,n=l.length,a=1<<o-1;let c=-1,d=0,p=o,h=o;for(;h--;)i[r.charCodeAt(h)]|=1<<h;for(h=0;h<n;h++){let A=i[l.charCodeAt(h)];const g=A|d;A|=(A&c)+c^c,d|=~(A|c),c&=A,d&a&&p++,c&a&&p--,d=d<<1|1,c=c<<1|~(g|d),d&=g}for(h=o;h--;)i[r.charCodeAt(h)]=0;return p},z=(r,l)=>{const o=l.length,n=r.length,a=[],c=[],d=Math.ceil(o/32),p=Math.ceil(n/32);for(let t=0;t<d;t++)c[t]=-1,a[t]=0;let h=0;for(;h<p-1;h++){let t=0,s=-1;const M=h*32,u=Math.min(32,n)+M;for(let e=M;e<u;e++)i[r.charCodeAt(e)]|=1<<e;for(let e=0;e<o;e++){const m=i[l.charCodeAt(e)],C=c[e/32|0]>>>e&1,f=a[e/32|0]>>>e&1,j=m|t,k=((m|f)&s)+s^s|m|f;let x=t|~(k|s),w=s&k;x>>>31^C&&(c[e/32|0]^=1<<e),w>>>31^f&&(a[e/32|0]^=1<<e),x=x<<1|C,w=w<<1|f,s=w|~(j|x),t=x&j}for(let e=M;e<u;e++)i[r.charCodeAt(e)]=0}let A=0,g=-1;const v=h*32,U=Math.min(32,n-v)+v;for(let t=v;t<U;t++)i[r.charCodeAt(t)]|=1<<t;let y=n;for(let t=0;t<o;t++){const s=i[l.charCodeAt(t)],M=c[t/32|0]>>>t&1,u=a[t/32|0]>>>t&1,e=s|A,m=((s|u)&g)+g^g|s|u;let C=A|~(m|g),f=g&m;y+=C>>>n-1&1,y-=f>>>n-1&1,C>>>31^M&&(c[t/32|0]^=1<<t),f>>>31^u&&(a[t/32|0]^=1<<t),C=C<<1|M,f=f<<1|u,g=f|~(e|C),A=C&e}for(let t=v;t<U;t++)i[r.charCodeAt(t)]=0;return y},I=(r,l)=>{if(r.length<l.length){const o=l;l=r,r=o}return l.length===0?r.length:r.length<=32?q(r,l):z(r,l)},_=(r,l)=>{let o=1/0,n=0;for(let a=0;a<l.length;a++){const c=I(r,l[a]);c<o&&(o=c,n=a)}return l[n]};export{_ as closest,I as distance};
@@ -1 +0,0 @@
1
- const R=String.raw,E=R`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,a=()=>new RegExp(R`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${E}(?:\u200D${E})*`,"gu"),n=new Set(["\x1B","›"]),e="\x07",_="[",r="m",u="]8;;",S=39,s=/[\u200B\uFEFF\u2060-\u2064]/g,I=new RegExp(`(?:\\${_}(?<code>\\d+)m|\\${u}(?<uri>.*)${e})`),i=Object.freeze(new Map([[0,0],[1,22],[2,22],[3,23],[4,24],[7,27],[8,28],[9,29],[30,39],[31,39],[32,39],[33,39],[34,39],[35,39],[36,39],[37,39],[40,49],[41,49],[42,49],[43,49],[44,49],[45,49],[46,49],[47,49],[90,39]])),t=/^[ \t]*(?:\r\n|\r|\n)/,N=/(?:\r\n|\r|\n)[ \t]*$/,g=/^(?:[\r\n]|$)/,c=/(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/,T=/^[ \t]*[\r\n][ \t\r\n]*$/,L=/\r\n|\n|\r/g,w=/[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g,x=/\u001B\[[\d;]*m[^\u001B]*(?:\u001B\[[\d;]*m|$)/g,B=/\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)[^\u001B]*\u001B\]8;;(?:\u0007|\u001B\\)/g,O=/[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y,A=a(),H=/[-_./\s]+/g,C=/(\u001B\[[0-9;]*[a-z])/i,G=new RegExp("\\p{Script=Arabic}","u"),M=new RegExp("\\p{Script=Bengali}","u"),D=new RegExp("\\p{Script=Cyrillic}","u"),K=new RegExp("\\p{Script=Devanagari}","u"),F=new RegExp("\\p{Script=Ethiopic}","u"),P=new RegExp("\\p{Script=Greek}","u"),m=new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+","gu"),l=new RegExp("\\p{Script=Gujarati}","u"),o=new RegExp("\\p{Script=Gurmukhi}","u"),W=new RegExp("\\p{Script=Hangul}","u"),d=new RegExp("\\p{Script=Hebrew}","u"),$=new RegExp("\\p{Script=Hiragana}","u"),U=new RegExp("\\p{Script=Han}","u"),y=new RegExp("\\p{Script=Kannada}","u"),Y=new RegExp("\\p{Script=Katakana}","u"),h=new RegExp("\\p{Script=Khmer}","u"),k=new RegExp("\\p{Script=Lao}","u"),b=new RegExp("\\p{Script=Latin}","u"),j=new RegExp("\\p{Script=Malayalam}","u"),J=new RegExp("\\p{Script=Myanmar}","u"),V=new RegExp("\\p{Script=Oriya}","u"),f=new RegExp("\\p{Script=Sinhala}","u"),z=new RegExp("\\p{Script=Tamil}","u"),Z=new RegExp("\\p{Script=Telugu}","u"),q=new RegExp("\\p{Script=Thai}","u"),v=new RegExp("\\p{Script=Tibetan}","u"),Q=/[\u02BB\u02BC\u0027]/u,X=p=>p.replace(A,"");export{l as A,o as B,y as C,z as D,Z as E,j as F,f as G,q as H,k as I,v as J,J as K,F as L,h as M,V as N,n as O,r as P,u as Q,w as R,e as S,_ as T,I as U,i as V,S as W,s as X,O as a,A as b,C as c,x as d,B as e,t as f,N as g,T as h,g as i,L as j,c as k,H as l,D as m,b as n,P as o,m as p,Q as q,Y as r,X as s,U as t,$ as u,W as v,d as w,G as x,K as y,M as z};
@@ -1 +0,0 @@
1
- function I(e){const t=e.match(/^[ \t]*(?=\S)/gm);if(!t)return e;let n=Number.POSITIVE_INFINITY;for(const r of t)n=Math.min(n,r.length);return n===0||n===Number.POSITIVE_INFINITY?e:e.replace(new RegExp(`^[ \\t]{${n}}`,"gm"),"")}function c(e){const t=e.replace(/^(?:[ \t]*\r?\n)+|(?:\r?\n[ \t]*)+$/g,"");return I(t)}export{c as dedent,I as default};
@@ -1 +0,0 @@
1
- import{isFullWidth as s,isWide as o,isAmbiguous as r,getCategory as n}from"./_isFullWidth-Dqc3MWgl.js";function t(e){if(!Number.isSafeInteger(e))throw new TypeError(`Expected a code point, got \`${typeof e}\`.`)}function a(e){return t(e),n(e)}function d(e,{ambiguousAsWide:i=!1}={}){return t(e),s(e)||o(e)||i&&r(e)?2:1}export{s as _isFullWidth,o as _isWide,d as eastAsianWidth,a as eastAsianWidthType};
@@ -1 +0,0 @@
1
- const r=(o,n)=>`${o}::${n?.joiner??""}::${n?.locale??""}::${n?.knownAcronyms?.join(",")??""}::${n?.normalize?"true":"false"}`;export{r as n};
@@ -1 +0,0 @@
1
- function i(e,t=1,r={}){const{indent:o=" ",includeEmptyLines:n=!1}=r;if(typeof e!="string")throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof e}\``);if(typeof t!="number")throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof t}\``);if(t<0)throw new RangeError(`Expected \`count\` to be at least 0, got \`${t}\``);if(typeof o!="string")throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof o}\``);if(t===0)return e;const p=n?/^/gm:/^(?!\s*$)/gm;return e.replace(p,o.repeat(t))}export{i as default};
@@ -1 +0,0 @@
1
- import{c as h}from"./constants-aPzGW29R.js";const l=(o,u)=>{const{length:r}=o;if(r===0)return"";if(r===1)return o[0];const t=[];let n="",e="";for(let f=0;f<r;f++){const s=o[f];if(h.test(s)){n?(t.push(n+e+s),n="",e=""):(t.length>0&&t.push(u),n=s);continue}n?(e&&(e+=u),e+=s):(t.length>0&&t.push(u),t.push(s))}return t.join("")};export{l as default};
@@ -1 +0,0 @@
1
- const e=/(?<![a-zß])SS(?![a-z])/g,l=a=>a.replaceAll(e,"ß");export{l as a};
@@ -1 +0,0 @@
1
- import f from"./indent-cz8WMI0e.js";import i from"./dedent-CPjAYUXh.js";function n(r,o=0,t={}){return f(i(r),o,t)}export{n as default};