@visulima/string 1.2.2 → 1.3.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 (196) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +46 -0
  4. package/dist/case/camel-case.cjs +1 -59
  5. package/dist/case/camel-case.d.cts +2 -2
  6. package/dist/case/camel-case.d.mts +2 -2
  7. package/dist/case/camel-case.d.ts +2 -2
  8. package/dist/case/camel-case.mjs +1 -57
  9. package/dist/case/capital-case.cjs +1 -51
  10. package/dist/case/capital-case.d.cts +2 -2
  11. package/dist/case/capital-case.d.mts +2 -2
  12. package/dist/case/capital-case.d.ts +2 -2
  13. package/dist/case/capital-case.mjs +1 -49
  14. package/dist/case/constant-case.cjs +1 -11
  15. package/dist/case/constant-case.d.cts +2 -2
  16. package/dist/case/constant-case.d.mts +2 -2
  17. package/dist/case/constant-case.d.ts +2 -2
  18. package/dist/case/constant-case.mjs +1 -9
  19. package/dist/case/dot-case.cjs +1 -11
  20. package/dist/case/dot-case.d.cts +2 -2
  21. package/dist/case/dot-case.d.mts +2 -2
  22. package/dist/case/dot-case.d.ts +2 -2
  23. package/dist/case/dot-case.mjs +1 -9
  24. package/dist/case/flat-case.cjs +1 -11
  25. package/dist/case/flat-case.d.cts +2 -2
  26. package/dist/case/flat-case.d.mts +2 -2
  27. package/dist/case/flat-case.d.ts +2 -2
  28. package/dist/case/flat-case.mjs +1 -9
  29. package/dist/case/flip-case.cjs +1 -61
  30. package/dist/case/flip-case.d.cts +4 -3
  31. package/dist/case/flip-case.d.mts +4 -3
  32. package/dist/case/flip-case.d.ts +4 -3
  33. package/dist/case/flip-case.mjs +1 -57
  34. package/dist/case/identify-case.cjs +1 -69
  35. package/dist/case/identify-case.d.cts +2 -2
  36. package/dist/case/identify-case.d.mts +2 -2
  37. package/dist/case/identify-case.d.ts +2 -2
  38. package/dist/case/identify-case.mjs +1 -67
  39. package/dist/case/index.cjs +1 -47
  40. package/dist/case/index.d.cts +2 -2
  41. package/dist/case/index.d.mts +2 -2
  42. package/dist/case/index.d.ts +2 -2
  43. package/dist/case/index.mjs +1 -20
  44. package/dist/case/kebab-case.cjs +1 -61
  45. package/dist/case/kebab-case.d.cts +4 -3
  46. package/dist/case/kebab-case.d.mts +4 -3
  47. package/dist/case/kebab-case.d.ts +4 -3
  48. package/dist/case/kebab-case.mjs +1 -57
  49. package/dist/case/lower-first.cjs +1 -13
  50. package/dist/case/lower-first.d.cts +2 -2
  51. package/dist/case/lower-first.d.mts +2 -2
  52. package/dist/case/lower-first.d.ts +2 -2
  53. package/dist/case/lower-first.mjs +1 -11
  54. package/dist/case/no-case.cjs +1 -11
  55. package/dist/case/no-case.d.cts +2 -2
  56. package/dist/case/no-case.d.mts +2 -2
  57. package/dist/case/no-case.d.ts +2 -2
  58. package/dist/case/no-case.mjs +1 -9
  59. package/dist/case/pascal-case.cjs +1 -52
  60. package/dist/case/pascal-case.d.cts +2 -2
  61. package/dist/case/pascal-case.d.mts +2 -2
  62. package/dist/case/pascal-case.d.ts +2 -2
  63. package/dist/case/pascal-case.mjs +1 -50
  64. package/dist/case/pascal-snake-case.cjs +1 -32
  65. package/dist/case/pascal-snake-case.d.cts +2 -2
  66. package/dist/case/pascal-snake-case.d.mts +2 -2
  67. package/dist/case/pascal-snake-case.d.ts +2 -2
  68. package/dist/case/pascal-snake-case.mjs +1 -30
  69. package/dist/case/path-case.cjs +1 -11
  70. package/dist/case/path-case.d.cts +2 -2
  71. package/dist/case/path-case.d.mts +2 -2
  72. package/dist/case/path-case.d.ts +2 -2
  73. package/dist/case/path-case.mjs +1 -9
  74. package/dist/case/sentence-case.cjs +1 -58
  75. package/dist/case/sentence-case.d.cts +2 -2
  76. package/dist/case/sentence-case.d.mts +2 -2
  77. package/dist/case/sentence-case.d.ts +2 -2
  78. package/dist/case/sentence-case.mjs +1 -56
  79. package/dist/case/snake-case.cjs +1 -11
  80. package/dist/case/snake-case.d.cts +2 -2
  81. package/dist/case/snake-case.d.mts +2 -2
  82. package/dist/case/snake-case.d.ts +2 -2
  83. package/dist/case/snake-case.mjs +1 -9
  84. package/dist/case/split-by-case.cjs +1 -641
  85. package/dist/case/split-by-case.d.cts +4 -3
  86. package/dist/case/split-by-case.d.mts +4 -3
  87. package/dist/case/split-by-case.d.ts +4 -3
  88. package/dist/case/split-by-case.mjs +1 -637
  89. package/dist/case/title-case.cjs +1 -47
  90. package/dist/case/title-case.d.cts +2 -2
  91. package/dist/case/title-case.d.mts +2 -2
  92. package/dist/case/title-case.d.ts +2 -2
  93. package/dist/case/title-case.mjs +1 -45
  94. package/dist/case/train-case.cjs +1 -44
  95. package/dist/case/train-case.d.cts +2 -2
  96. package/dist/case/train-case.d.mts +2 -2
  97. package/dist/case/train-case.d.ts +2 -2
  98. package/dist/case/train-case.mjs +1 -42
  99. package/dist/case/upper-first.cjs +1 -13
  100. package/dist/case/upper-first.d.cts +2 -2
  101. package/dist/case/upper-first.d.mts +2 -2
  102. package/dist/case/upper-first.d.ts +2 -2
  103. package/dist/case/upper-first.mjs +1 -11
  104. package/dist/get-string-truncated-width.cjs +1 -422
  105. package/dist/get-string-truncated-width.d.cts +2 -1
  106. package/dist/get-string-truncated-width.d.mts +2 -1
  107. package/dist/get-string-truncated-width.d.ts +2 -1
  108. package/dist/get-string-truncated-width.mjs +1 -418
  109. package/dist/get-string-width.cjs +1 -11
  110. package/dist/get-string-width.d.cts +2 -1
  111. package/dist/get-string-width.d.mts +2 -1
  112. package/dist/get-string-width.d.ts +2 -1
  113. package/dist/get-string-width.mjs +1 -7
  114. package/dist/index.cjs +1 -66
  115. package/dist/index.d.cts +15 -5
  116. package/dist/index.d.mts +15 -5
  117. package/dist/index.d.ts +15 -5
  118. package/dist/index.mjs +1 -29
  119. package/dist/native-string-types.d.cts +1 -1
  120. package/dist/native-string-types.d.mts +1 -1
  121. package/dist/native-string-types.d.ts +1 -1
  122. package/dist/outdent.cjs +1 -125
  123. package/dist/outdent.d.cts +2 -1
  124. package/dist/outdent.d.mts +2 -1
  125. package/dist/outdent.d.ts +2 -1
  126. package/dist/outdent.mjs +1 -121
  127. package/dist/packem_shared/LRUCache-Bjo6gsbC.mjs +1 -0
  128. package/dist/packem_shared/LRUCache-TYqfUYE5.cjs +1 -0
  129. package/dist/packem_shared/WrapMode-BL2dnSc8.cjs +8 -0
  130. package/dist/packem_shared/WrapMode-DxH5g69E.mjs +8 -0
  131. package/dist/packem_shared/alignText-BCKbnqhC.mjs +2 -0
  132. package/dist/packem_shared/alignText-CLZJuPP6.cjs +2 -0
  133. package/dist/packem_shared/constants-Cd17VNEv.mjs +1 -0
  134. package/dist/packem_shared/constants-D3K8u3G8.cjs +1 -0
  135. package/dist/packem_shared/generate-cache-key-BZf0GiMs.cjs +1 -0
  136. package/dist/packem_shared/generate-cache-key-DPByFaMH.mjs +1 -0
  137. package/dist/packem_shared/joinSegments-CDHNMXsF.cjs +1 -0
  138. package/dist/packem_shared/joinSegments-H7QJ7rwJ.mjs +1 -0
  139. package/dist/packem_shared/normalize-german-eszett-4k1qRtEP.mjs +1 -0
  140. package/dist/packem_shared/normalize-german-eszett-Bop4wOp9.cjs +1 -0
  141. package/dist/packem_shared/replaceString-Ce8TI_-L.cjs +1 -0
  142. package/dist/packem_shared/replaceString-D7R-5VFX.mjs +1 -0
  143. package/dist/packem_shared/slugify-B1vlQQO1.mjs +1 -0
  144. package/dist/packem_shared/slugify-CH3GI7E5.cjs +1 -0
  145. package/dist/packem_shared/transliterate-BXaP38Sh.mjs +5 -0
  146. package/dist/packem_shared/transliterate-CToQ-aeM.cjs +5 -0
  147. package/dist/packem_shared/{types-DmfKbIaI.d.ts → types-BSdIWVzn.d.cts} +2 -1
  148. package/dist/packem_shared/{types-DmfKbIaI.d.cts → types-BSdIWVzn.d.mts} +2 -1
  149. package/dist/packem_shared/{types-DmfKbIaI.d.mts → types-BSdIWVzn.d.ts} +2 -1
  150. package/dist/packem_shared/{types-DcGtApe2.d.ts → types-BfGNLD2K.d.ts} +1 -1
  151. package/dist/packem_shared/{types-C5Pk8B8Q.d.cts → types-DrtiqNkK.d.cts} +1 -1
  152. package/dist/packem_shared/{types-_jqW_ZOt.d.mts → types-mlwFVBiS.d.mts} +1 -1
  153. package/dist/slice.cjs +1 -419
  154. package/dist/slice.d.cts +2 -1
  155. package/dist/slice.d.mts +2 -1
  156. package/dist/slice.d.ts +2 -1
  157. package/dist/slice.mjs +1 -415
  158. package/dist/test/utils.cjs +13 -74
  159. package/dist/test/utils.d.cts +2 -1
  160. package/dist/test/utils.d.mts +2 -1
  161. package/dist/test/utils.d.ts +2 -1
  162. package/dist/test/utils.mjs +14 -69
  163. package/dist/test/vitest.cjs +1 -11
  164. package/dist/test/vitest.d.cts +2 -1
  165. package/dist/test/vitest.d.mts +2 -1
  166. package/dist/test/vitest.d.ts +2 -1
  167. package/dist/test/vitest.mjs +1 -7
  168. package/dist/truncate.cjs +1 -101
  169. package/dist/truncate.d.cts +2 -1
  170. package/dist/truncate.d.mts +2 -1
  171. package/dist/truncate.d.ts +2 -1
  172. package/dist/truncate.mjs +1 -97
  173. package/dist/utils.cjs +1 -65
  174. package/dist/utils.d.cts +1 -1
  175. package/dist/utils.d.mts +1 -1
  176. package/dist/utils.d.ts +1 -1
  177. package/dist/utils.mjs +1 -56
  178. package/package.json +9 -6
  179. package/dist/packem_shared/LRUCache-Crb-m7cw.cjs +0 -53
  180. package/dist/packem_shared/LRUCache-udNErhWw.mjs +0 -51
  181. package/dist/packem_shared/WrapMode-B-WBY1mj.mjs +0 -545
  182. package/dist/packem_shared/WrapMode-Dsqu9BaX.cjs +0 -550
  183. package/dist/packem_shared/constants-CKuHriHc.cjs +0 -151
  184. package/dist/packem_shared/constants-CsGLUb4U.mjs +0 -100
  185. package/dist/packem_shared/generate-cache-key-D8f1auDB.cjs +0 -10
  186. package/dist/packem_shared/generate-cache-key-YSju5pj2.mjs +0 -8
  187. package/dist/packem_shared/joinSegments-B_7bxy5J.cjs +0 -48
  188. package/dist/packem_shared/joinSegments-BovQ2h_P.mjs +0 -46
  189. package/dist/packem_shared/normalize-german-eszett-DJK0S2qj.cjs +0 -11
  190. package/dist/packem_shared/normalize-german-eszett-fpJ4lZL6.mjs +0 -9
  191. package/dist/packem_shared/replaceString-C7Dp5vAg.mjs +0 -200
  192. package/dist/packem_shared/replaceString-iYo1cDfZ.cjs +0 -202
  193. package/dist/packem_shared/slugify-DhE59J2A.mjs +0 -48
  194. package/dist/packem_shared/slugify-jh6PftAT.cjs +0 -50
  195. package/dist/packem_shared/transliterate-BEci5RC8.cjs +0 -47782
  196. package/dist/packem_shared/transliterate-DwSldp0o.mjs +0 -47780
@@ -1,7 +1 @@
1
- import { expectAnsiStrings } from './utils.mjs';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- const toEqualAnsi = /* @__PURE__ */ __name((actual, expected) => expectAnsiStrings(actual, expected), "toEqualAnsi");
6
-
7
- export { toEqualAnsi };
1
+ var i=Object.defineProperty;var t=(e,r)=>i(e,"name",{value:r,configurable:!0});import{expectAnsiStrings as n}from"./utils.mjs";var o=Object.defineProperty,a=t((e,r)=>o(e,"name",{value:r,configurable:!0}),"i");const c=a((e,r)=>n(e,r),"toEqualAnsi");export{c as toEqualAnsi};
package/dist/truncate.cjs CHANGED
@@ -1,101 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const getStringTruncatedWidth = require('./get-string-truncated-width.cjs');
6
- const slice = require('./slice.cjs');
7
-
8
- var __defProp = Object.defineProperty;
9
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
- const DEFAULT_ELLIPSIS = "…";
11
- const MAX_SPACE_SEARCH_DISTANCE = 3;
12
- const findNearestSpace = /* @__PURE__ */ __name((string_, startIndex, searchRight = false) => {
13
- if (string_.charAt(startIndex) === " ") {
14
- return startIndex;
15
- }
16
- const direction = searchRight ? 1 : -1;
17
- const limit = Math.min(MAX_SPACE_SEARCH_DISTANCE, searchRight ? string_.length - startIndex : startIndex);
18
- for (let offset = 1; offset <= limit; offset++) {
19
- const index = startIndex + offset * direction;
20
- if (string_.charAt(index) === " ") {
21
- return index;
22
- }
23
- }
24
- return startIndex;
25
- }, "findNearestSpace");
26
- const truncate = /* @__PURE__ */ __name((input, limit, options = {}) => {
27
- if (typeof input !== "string") {
28
- throw new TypeError(`Expected \`input\` to be a string, got ${typeof input}`);
29
- }
30
- if (typeof limit !== "number") {
31
- throw new TypeError(`Expected \`limit\` to be a number, got ${typeof limit}`);
32
- }
33
- if (input === "" || limit <= 0) {
34
- return "";
35
- }
36
- input = input.normalize("NFC");
37
- const { ellipsis = DEFAULT_ELLIPSIS, position = "end", preferTruncationOnSpace = false } = options;
38
- let ellipsisWidth = options.ellipsisWidth ?? ellipsis === DEFAULT_ELLIPSIS ? 1 : void 0;
39
- if (ellipsisWidth === void 0) {
40
- ellipsisWidth = getStringTruncatedWidth.getStringTruncatedWidth(ellipsis, {
41
- ...options.width,
42
- ellipsis: "",
43
- ellipsisWidth: 0,
44
- limit: Number.POSITIVE_INFINITY
45
- }).width;
46
- }
47
- if (limit === 1 && ellipsisWidth === 1) {
48
- return ellipsis;
49
- }
50
- if (limit === 1) {
51
- return "";
52
- }
53
- const { width } = getStringTruncatedWidth.getStringTruncatedWidth(input, {
54
- ...options.width,
55
- ellipsis,
56
- ellipsisWidth
57
- });
58
- if (width <= limit) {
59
- return input;
60
- }
61
- switch (position) {
62
- case "start": {
63
- if (preferTruncationOnSpace) {
64
- const nearestSpace = findNearestSpace(input, width - limit + 1, true);
65
- return ellipsis + slice.slice(input, nearestSpace, width).trim();
66
- }
67
- return ellipsis + slice.slice(input, width - limit + ellipsisWidth, width, {
68
- width: options.width
69
- });
70
- }
71
- case "middle": {
72
- const half = Math.floor(limit / 2);
73
- if (preferTruncationOnSpace) {
74
- const firstBreak = findNearestSpace(input, half);
75
- const secondBreak = findNearestSpace(input, width - (limit - half) + 1, true);
76
- return slice.slice(input, 0, firstBreak) + ellipsis + slice.slice(input, secondBreak, width).trim();
77
- }
78
- return slice.slice(input, 0, half, {
79
- width: options.width
80
- }) + ellipsis + slice.slice(input, width - (limit - half) + ellipsisWidth, width, {
81
- width: options.width
82
- });
83
- }
84
- case "end": {
85
- if (preferTruncationOnSpace) {
86
- const nearestSpace = findNearestSpace(input, limit - 1);
87
- return slice.slice(input, 0, nearestSpace, {
88
- width: options.width
89
- }) + ellipsis;
90
- }
91
- return slice.slice(input, 0, limit - ellipsisWidth, {
92
- width: options.width
93
- }) + ellipsis;
94
- }
95
- default: {
96
- throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${position}'`);
97
- }
98
- }
99
- }, "truncate");
100
-
101
- exports.truncate = truncate;
1
+ "use strict";var m=Object.defineProperty;var a=(t,i)=>m(t,"name",{value:i,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("./get-string-truncated-width.cjs"),c=require("./slice.cjs");var b=Object.defineProperty,p=a((t,i)=>b(t,"name",{value:i,configurable:!0}),"h");const f="…",T=3,u=p((t,i,e=!1)=>{if(t.charAt(i)===" ")return i;const r=e?1:-1,l=Math.min(T,e?t.length-i:i);for(let d=1;d<=l;d++){const n=i+d*r;if(t.charAt(n)===" ")return n}return i},"findNearestSpace"),v=p((t,i,e={})=>{if(typeof t!="string")throw new TypeError(`Expected \`input\` to be a string, got ${typeof t}`);if(typeof i!="number")throw new TypeError(`Expected \`limit\` to be a number, got ${typeof i}`);if(t===""||i<=0)return"";t=t.normalize("NFC");const{ellipsis:r=f,position:l="end",preferTruncationOnSpace:d=!1}=e;let n=e.ellipsisWidth??r===f?1:void 0;if(n===void 0&&(n=h.getStringTruncatedWidth(r,{...e.width,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width),i===1&&n===1)return r;if(i===1)return"";const{width:s}=h.getStringTruncatedWidth(t,{...e.width,ellipsis:r,ellipsisWidth:n});if(s<=i)return t;switch(l){case"start":{if(d){const o=u(t,s-i+1,!0);return r+c.slice(t,o,s).trim()}return r+c.slice(t,s-i+n,s,{width:e.width})}case"middle":{const o=Math.floor(i/2);if(d){const w=u(t,o),g=u(t,s-(i-o)+1,!0);return c.slice(t,0,w)+r+c.slice(t,g,s).trim()}return c.slice(t,0,o,{width:e.width})+r+c.slice(t,s-(i-o)+n,s,{width:e.width})}case"end":{if(d){const o=u(t,i-1);return c.slice(t,0,o,{width:e.width})+r}return c.slice(t,0,i-n,{width:e.width})+r}default:throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${l}'`)}},"truncate");exports.truncate=v;
@@ -9,4 +9,5 @@ type TruncateOptions = {
9
9
  };
10
10
  declare const truncate: (input: string, limit: number, options?: TruncateOptions) => string;
11
11
 
12
- export { type TruncateOptions, truncate };
12
+ export { truncate };
13
+ export type { TruncateOptions };
@@ -9,4 +9,5 @@ type TruncateOptions = {
9
9
  };
10
10
  declare const truncate: (input: string, limit: number, options?: TruncateOptions) => string;
11
11
 
12
- export { type TruncateOptions, truncate };
12
+ export { truncate };
13
+ export type { TruncateOptions };
@@ -9,4 +9,5 @@ type TruncateOptions = {
9
9
  };
10
10
  declare const truncate: (input: string, limit: number, options?: TruncateOptions) => string;
11
11
 
12
- export { type TruncateOptions, truncate };
12
+ export { truncate };
13
+ export type { TruncateOptions };
package/dist/truncate.mjs CHANGED
@@ -1,97 +1 @@
1
- import { getStringTruncatedWidth } from './get-string-truncated-width.mjs';
2
- import { slice } from './slice.mjs';
3
-
4
- var __defProp = Object.defineProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- const DEFAULT_ELLIPSIS = "…";
7
- const MAX_SPACE_SEARCH_DISTANCE = 3;
8
- const findNearestSpace = /* @__PURE__ */ __name((string_, startIndex, searchRight = false) => {
9
- if (string_.charAt(startIndex) === " ") {
10
- return startIndex;
11
- }
12
- const direction = searchRight ? 1 : -1;
13
- const limit = Math.min(MAX_SPACE_SEARCH_DISTANCE, searchRight ? string_.length - startIndex : startIndex);
14
- for (let offset = 1; offset <= limit; offset++) {
15
- const index = startIndex + offset * direction;
16
- if (string_.charAt(index) === " ") {
17
- return index;
18
- }
19
- }
20
- return startIndex;
21
- }, "findNearestSpace");
22
- const truncate = /* @__PURE__ */ __name((input, limit, options = {}) => {
23
- if (typeof input !== "string") {
24
- throw new TypeError(`Expected \`input\` to be a string, got ${typeof input}`);
25
- }
26
- if (typeof limit !== "number") {
27
- throw new TypeError(`Expected \`limit\` to be a number, got ${typeof limit}`);
28
- }
29
- if (input === "" || limit <= 0) {
30
- return "";
31
- }
32
- input = input.normalize("NFC");
33
- const { ellipsis = DEFAULT_ELLIPSIS, position = "end", preferTruncationOnSpace = false } = options;
34
- let ellipsisWidth = options.ellipsisWidth ?? ellipsis === DEFAULT_ELLIPSIS ? 1 : void 0;
35
- if (ellipsisWidth === void 0) {
36
- ellipsisWidth = getStringTruncatedWidth(ellipsis, {
37
- ...options.width,
38
- ellipsis: "",
39
- ellipsisWidth: 0,
40
- limit: Number.POSITIVE_INFINITY
41
- }).width;
42
- }
43
- if (limit === 1 && ellipsisWidth === 1) {
44
- return ellipsis;
45
- }
46
- if (limit === 1) {
47
- return "";
48
- }
49
- const { width } = getStringTruncatedWidth(input, {
50
- ...options.width,
51
- ellipsis,
52
- ellipsisWidth
53
- });
54
- if (width <= limit) {
55
- return input;
56
- }
57
- switch (position) {
58
- case "start": {
59
- if (preferTruncationOnSpace) {
60
- const nearestSpace = findNearestSpace(input, width - limit + 1, true);
61
- return ellipsis + slice(input, nearestSpace, width).trim();
62
- }
63
- return ellipsis + slice(input, width - limit + ellipsisWidth, width, {
64
- width: options.width
65
- });
66
- }
67
- case "middle": {
68
- const half = Math.floor(limit / 2);
69
- if (preferTruncationOnSpace) {
70
- const firstBreak = findNearestSpace(input, half);
71
- const secondBreak = findNearestSpace(input, width - (limit - half) + 1, true);
72
- return slice(input, 0, firstBreak) + ellipsis + slice(input, secondBreak, width).trim();
73
- }
74
- return slice(input, 0, half, {
75
- width: options.width
76
- }) + ellipsis + slice(input, width - (limit - half) + ellipsisWidth, width, {
77
- width: options.width
78
- });
79
- }
80
- case "end": {
81
- if (preferTruncationOnSpace) {
82
- const nearestSpace = findNearestSpace(input, limit - 1);
83
- return slice(input, 0, nearestSpace, {
84
- width: options.width
85
- }) + ellipsis;
86
- }
87
- return slice(input, 0, limit - ellipsisWidth, {
88
- width: options.width
89
- }) + ellipsis;
90
- }
91
- default: {
92
- throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${position}'`);
93
- }
94
- }
95
- }, "truncate");
96
-
97
- export { truncate };
1
+ var g=Object.defineProperty;var h=(t,i)=>g(t,"name",{value:i,configurable:!0});import{getStringTruncatedWidth as l}from"./get-string-truncated-width.mjs";import{slice as d}from"./slice.mjs";var b=Object.defineProperty,p=h((t,i)=>b(t,"name",{value:i,configurable:!0}),"h");const u="…",y=3,f=p((t,i,e=!1)=>{if(t.charAt(i)===" ")return i;const r=e?1:-1,a=Math.min(y,e?t.length-i:i);for(let c=1;c<=a;c++){const n=i+c*r;if(t.charAt(n)===" ")return n}return i},"findNearestSpace"),T=p((t,i,e={})=>{if(typeof t!="string")throw new TypeError(`Expected \`input\` to be a string, got ${typeof t}`);if(typeof i!="number")throw new TypeError(`Expected \`limit\` to be a number, got ${typeof i}`);if(t===""||i<=0)return"";t=t.normalize("NFC");const{ellipsis:r=u,position:a="end",preferTruncationOnSpace:c=!1}=e;let n=e.ellipsisWidth??r===u?1:void 0;if(n===void 0&&(n=l(r,{...e.width,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width),i===1&&n===1)return r;if(i===1)return"";const{width:o}=l(t,{...e.width,ellipsis:r,ellipsisWidth:n});if(o<=i)return t;switch(a){case"start":{if(c){const s=f(t,o-i+1,!0);return r+d(t,s,o).trim()}return r+d(t,o-i+n,o,{width:e.width})}case"middle":{const s=Math.floor(i/2);if(c){const w=f(t,s),m=f(t,o-(i-s)+1,!0);return d(t,0,w)+r+d(t,m,o).trim()}return d(t,0,s,{width:e.width})+r+d(t,o-(i-s)+n,o,{width:e.width})}case"end":{if(c){const s=f(t,i-1);return d(t,0,s,{width:e.width})+r}return d(t,0,i-n,{width:e.width})+r}default:throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${a}'`)}},"truncate");export{T as truncate};
package/dist/utils.cjs CHANGED
@@ -1,65 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const LRUCache = require('./packem_shared/LRUCache-Crb-m7cw.cjs');
6
-
7
- var __defProp = Object.defineProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- const escapeRegExp = /* @__PURE__ */ __name((char) => (
10
- // $& means the whole matched string
11
- char.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&")
12
- ), "escapeRegExp");
13
- const inRange = /* @__PURE__ */ __name((number_, ranges) => ranges.some((range) => number_ >= range[0] && number_ <= range[1]), "inRange");
14
- const hasChinese = /* @__PURE__ */ __name((char) => /[\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]/.test(
15
- char
16
- ), "hasChinese");
17
- const hasPunctuationOrSpace = /* @__PURE__ */ __name((char) => (
18
- // Uses Unicode property escapes for Punctuation and general category for Space
19
- /[\p{P}\p{Z}]/u.test(char)
20
- ), "hasPunctuationOrSpace");
21
- const findStringOccurrences = /* @__PURE__ */ __name((source, needles) => {
22
- const ranges = [];
23
- if (!Array.isArray(needles)) {
24
- return ranges;
25
- }
26
- needles.forEach((needle) => {
27
- if (typeof needle !== "string" || needle.length === 0) {
28
- return;
29
- }
30
- let startIndex = 0;
31
- let index;
32
- while ((index = source.indexOf(needle, startIndex)) > -1) {
33
- const end = index + needle.length - 1;
34
- ranges.push([index, end]);
35
- startIndex = index + 1;
36
- }
37
- });
38
- if (ranges.length === 0) {
39
- return [];
40
- }
41
- ranges.sort((a, b) => a[0] - b[0]);
42
- const merged = [];
43
- let currentRange = null;
44
- for (const range of ranges) {
45
- if (currentRange === null) {
46
- currentRange = [...range];
47
- } else if (range[0] <= currentRange[1] + 1) {
48
- currentRange[1] = Math.max(currentRange[1], range[1]);
49
- } else {
50
- merged.push(currentRange);
51
- currentRange = [...range];
52
- }
53
- }
54
- if (currentRange !== null) {
55
- merged.push(currentRange);
56
- }
57
- return merged;
58
- }, "findStringOccurrences");
59
-
60
- exports.LRUCache = LRUCache;
61
- exports.escapeRegExp = escapeRegExp;
62
- exports.findStringOccurrences = findStringOccurrences;
63
- exports.hasChinese = hasChinese;
64
- exports.hasPunctuationOrSpace = hasPunctuationOrSpace;
65
- exports.inRange = inRange;
1
+ "use strict";var o=Object.defineProperty;var c=(u,n)=>o(u,"name",{value:n,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./packem_shared/LRUCache-TYqfUYE5.cjs");var h=Object.defineProperty,r=c((u,n)=>h(u,"name",{value:n,configurable:!0}),"e");const p=r(u=>u.replaceAll(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRegExp"),g=r((u,n)=>n.some(t=>u>=t[0]&&u<=t[1]),"inRange"),C=r(u=>/[\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]/.test(u),"hasChinese"),E=r(u=>/[\p{P}\p{Z}]/u.test(u),"hasPunctuationOrSpace"),f=r((u,n)=>{const t=[];if(!Array.isArray(n))return t;if(n.forEach(e=>{if(typeof e!="string"||e.length===0)return;let F=0,a;for(;(a=u.indexOf(e,F))>-1;){const i=a+e.length-1;t.push([a,i]),F=a+1}}),t.length===0)return[];t.sort((e,F)=>e[0]-F[0]);const s=[];let D=null;for(const e of t)D===null?D=[...e]:e[0]<=D[1]+1?D[1]=Math.max(D[1],e[1]):(s.push(D),D=[...e]);return D!==null&&s.push(D),s},"findStringOccurrences");exports.LRUCache=l;exports.escapeRegExp=p;exports.findStringOccurrences=f;exports.hasChinese=C;exports.hasPunctuationOrSpace=E;exports.inRange=g;
package/dist/utils.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { k as IntervalArray } from './packem_shared/types-DmfKbIaI.cjs';
1
+ import { k as IntervalArray } from './packem_shared/types-BSdIWVzn.cjs';
2
2
  export { L as LRUCache } from './packem_shared/lru-cache-B_t27XwI.cjs';
3
3
 
4
4
  declare const escapeRegExp: (char: string) => string;
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { k as IntervalArray } from './packem_shared/types-DmfKbIaI.mjs';
1
+ import { k as IntervalArray } from './packem_shared/types-BSdIWVzn.mjs';
2
2
  export { L as LRUCache } from './packem_shared/lru-cache-B_t27XwI.mjs';
3
3
 
4
4
  declare const escapeRegExp: (char: string) => string;
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { k as IntervalArray } from './packem_shared/types-DmfKbIaI.js';
1
+ import { k as IntervalArray } from './packem_shared/types-BSdIWVzn.js';
2
2
  export { L as LRUCache } from './packem_shared/lru-cache-B_t27XwI.js';
3
3
 
4
4
  declare const escapeRegExp: (char: string) => string;
package/dist/utils.mjs CHANGED
@@ -1,56 +1 @@
1
- export { default as LRUCache } from './packem_shared/LRUCache-udNErhWw.mjs';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- const escapeRegExp = /* @__PURE__ */ __name((char) => (
6
- // $& means the whole matched string
7
- char.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&")
8
- ), "escapeRegExp");
9
- const inRange = /* @__PURE__ */ __name((number_, ranges) => ranges.some((range) => number_ >= range[0] && number_ <= range[1]), "inRange");
10
- const hasChinese = /* @__PURE__ */ __name((char) => /[\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]/.test(
11
- char
12
- ), "hasChinese");
13
- const hasPunctuationOrSpace = /* @__PURE__ */ __name((char) => (
14
- // Uses Unicode property escapes for Punctuation and general category for Space
15
- /[\p{P}\p{Z}]/u.test(char)
16
- ), "hasPunctuationOrSpace");
17
- const findStringOccurrences = /* @__PURE__ */ __name((source, needles) => {
18
- const ranges = [];
19
- if (!Array.isArray(needles)) {
20
- return ranges;
21
- }
22
- needles.forEach((needle) => {
23
- if (typeof needle !== "string" || needle.length === 0) {
24
- return;
25
- }
26
- let startIndex = 0;
27
- let index;
28
- while ((index = source.indexOf(needle, startIndex)) > -1) {
29
- const end = index + needle.length - 1;
30
- ranges.push([index, end]);
31
- startIndex = index + 1;
32
- }
33
- });
34
- if (ranges.length === 0) {
35
- return [];
36
- }
37
- ranges.sort((a, b) => a[0] - b[0]);
38
- const merged = [];
39
- let currentRange = null;
40
- for (const range of ranges) {
41
- if (currentRange === null) {
42
- currentRange = [...range];
43
- } else if (range[0] <= currentRange[1] + 1) {
44
- currentRange[1] = Math.max(currentRange[1], range[1]);
45
- } else {
46
- merged.push(currentRange);
47
- currentRange = [...range];
48
- }
49
- }
50
- if (currentRange !== null) {
51
- merged.push(currentRange);
52
- }
53
- return merged;
54
- }, "findStringOccurrences");
55
-
56
- export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange };
1
+ var i=Object.defineProperty;var c=(u,F)=>i(u,"name",{value:F,configurable:!0});import{default as O}from"./packem_shared/LRUCache-Bjo6gsbC.mjs";var l=Object.defineProperty,t=c((u,F)=>l(u,"name",{value:F,configurable:!0}),"e");const f=t(u=>u.replaceAll(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRegExp"),h=t((u,F)=>F.some(n=>u>=n[0]&&u<=n[1]),"inRange"),C=t(u=>/[\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]/.test(u),"hasChinese"),E=t(u=>/[\p{P}\p{Z}]/u.test(u),"hasPunctuationOrSpace"),g=t((u,F)=>{const n=[];if(!Array.isArray(F))return n;if(F.forEach(D=>{if(typeof D!="string"||D.length===0)return;let r=0,a;for(;(a=u.indexOf(D,r))>-1;){const o=a+D.length-1;n.push([a,o]),r=a+1}}),n.length===0)return[];n.sort((D,r)=>D[0]-r[0]);const s=[];let e=null;for(const D of n)e===null?e=[...D]:D[0]<=e[1]+1?e[1]=Math.max(e[1],D[1]):(s.push(e),e=[...D]);return e!==null&&s.push(e),s},"findStringOccurrences");export{O as LRUCache,f as escapeRegExp,g as findStringOccurrences,C as hasChinese,E as hasPunctuationOrSpace,h as inRange};
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@visulima/string",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "Functions for manipulating strings.",
5
5
  "keywords": [
6
6
  "visulima",
7
+ "align",
8
+ "align-text",
9
+ "align-text-left",
10
+ "align-text-center",
11
+ "align-text-right",
12
+ "align-text-justify",
13
+ "align-text-start",
7
14
  "string",
8
15
  "string-manipulation",
9
16
  "unicode",
@@ -41,8 +48,7 @@
41
48
  "slug",
42
49
  "slugify",
43
50
  "utf8",
44
- "utf-8",
45
- "unicode"
51
+ "utf-8"
46
52
  ],
47
53
  "homepage": "https://visulima.com/packages/string",
48
54
  "bugs": {
@@ -480,8 +486,5 @@
480
486
  "publishConfig": {
481
487
  "access": "public",
482
488
  "provenance": true
483
- },
484
- "scripts": {
485
- "postinstall": "node ./scripts/generate-charmap.js"
486
489
  }
487
490
  }
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- class LRUCache {
6
- static {
7
- __name(this, "LRUCache");
8
- }
9
- capacity;
10
- cache;
11
- keyOrder;
12
- constructor(capacity) {
13
- this.capacity = capacity;
14
- this.cache = /* @__PURE__ */ new Map();
15
- this.keyOrder = [];
16
- }
17
- get(key) {
18
- if (!this.cache.has(key)) {
19
- return void 0;
20
- }
21
- this.keyOrder = this.keyOrder.filter((k) => k !== key);
22
- this.keyOrder.push(key);
23
- return this.cache.get(key);
24
- }
25
- has(key) {
26
- return this.cache.has(key);
27
- }
28
- set(key, value) {
29
- if (this.cache.has(key)) {
30
- this.keyOrder = this.keyOrder.filter((k) => k !== key);
31
- } else if (this.cache.size >= this.capacity) {
32
- const lruKey = this.keyOrder.shift();
33
- if (lruKey !== void 0) {
34
- this.cache.delete(lruKey);
35
- }
36
- }
37
- this.cache.set(key, value);
38
- this.keyOrder.push(key);
39
- }
40
- delete(key) {
41
- this.cache.delete(key);
42
- this.keyOrder = this.keyOrder.filter((k) => k !== key);
43
- }
44
- clear() {
45
- this.cache.clear();
46
- this.keyOrder = [];
47
- }
48
- size() {
49
- return this.cache.size;
50
- }
51
- }
52
-
53
- module.exports = LRUCache;
@@ -1,51 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- class LRUCache {
4
- static {
5
- __name(this, "LRUCache");
6
- }
7
- capacity;
8
- cache;
9
- keyOrder;
10
- constructor(capacity) {
11
- this.capacity = capacity;
12
- this.cache = /* @__PURE__ */ new Map();
13
- this.keyOrder = [];
14
- }
15
- get(key) {
16
- if (!this.cache.has(key)) {
17
- return void 0;
18
- }
19
- this.keyOrder = this.keyOrder.filter((k) => k !== key);
20
- this.keyOrder.push(key);
21
- return this.cache.get(key);
22
- }
23
- has(key) {
24
- return this.cache.has(key);
25
- }
26
- set(key, value) {
27
- if (this.cache.has(key)) {
28
- this.keyOrder = this.keyOrder.filter((k) => k !== key);
29
- } else if (this.cache.size >= this.capacity) {
30
- const lruKey = this.keyOrder.shift();
31
- if (lruKey !== void 0) {
32
- this.cache.delete(lruKey);
33
- }
34
- }
35
- this.cache.set(key, value);
36
- this.keyOrder.push(key);
37
- }
38
- delete(key) {
39
- this.cache.delete(key);
40
- this.keyOrder = this.keyOrder.filter((k) => k !== key);
41
- }
42
- clear() {
43
- this.cache.clear();
44
- this.keyOrder = [];
45
- }
46
- size() {
47
- return this.cache.size;
48
- }
49
- }
50
-
51
- export { LRUCache as default };