@visulima/string 1.2.3 → 1.4.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 (102) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +46 -0
  3. package/dist/case/camel-case.cjs +1 -59
  4. package/dist/case/camel-case.mjs +1 -57
  5. package/dist/case/capital-case.cjs +1 -51
  6. package/dist/case/capital-case.mjs +1 -49
  7. package/dist/case/constant-case.cjs +1 -11
  8. package/dist/case/constant-case.mjs +1 -9
  9. package/dist/case/dot-case.cjs +1 -11
  10. package/dist/case/dot-case.mjs +1 -9
  11. package/dist/case/flat-case.cjs +1 -11
  12. package/dist/case/flat-case.mjs +1 -9
  13. package/dist/case/flip-case.cjs +1 -61
  14. package/dist/case/flip-case.mjs +1 -57
  15. package/dist/case/identify-case.cjs +1 -69
  16. package/dist/case/identify-case.mjs +1 -67
  17. package/dist/case/index.cjs +1 -47
  18. package/dist/case/index.mjs +1 -20
  19. package/dist/case/kebab-case.cjs +1 -61
  20. package/dist/case/kebab-case.mjs +1 -57
  21. package/dist/case/lower-first.cjs +1 -13
  22. package/dist/case/lower-first.mjs +1 -11
  23. package/dist/case/no-case.cjs +1 -11
  24. package/dist/case/no-case.mjs +1 -9
  25. package/dist/case/pascal-case.cjs +1 -52
  26. package/dist/case/pascal-case.mjs +1 -50
  27. package/dist/case/pascal-snake-case.cjs +1 -32
  28. package/dist/case/pascal-snake-case.mjs +1 -30
  29. package/dist/case/path-case.cjs +1 -11
  30. package/dist/case/path-case.mjs +1 -9
  31. package/dist/case/sentence-case.cjs +1 -58
  32. package/dist/case/sentence-case.mjs +1 -56
  33. package/dist/case/snake-case.cjs +1 -11
  34. package/dist/case/snake-case.mjs +1 -9
  35. package/dist/case/split-by-case.cjs +1 -641
  36. package/dist/case/split-by-case.mjs +1 -637
  37. package/dist/case/title-case.cjs +1 -47
  38. package/dist/case/title-case.mjs +1 -45
  39. package/dist/case/train-case.cjs +1 -44
  40. package/dist/case/train-case.mjs +1 -42
  41. package/dist/case/upper-first.cjs +1 -13
  42. package/dist/case/upper-first.mjs +1 -11
  43. package/dist/get-string-truncated-width.cjs +1 -422
  44. package/dist/get-string-truncated-width.mjs +1 -418
  45. package/dist/get-string-width.cjs +1 -11
  46. package/dist/get-string-width.mjs +1 -7
  47. package/dist/index.cjs +1 -66
  48. package/dist/index.d.cts +13 -3
  49. package/dist/index.d.mts +13 -3
  50. package/dist/index.d.ts +13 -3
  51. package/dist/index.mjs +1 -29
  52. package/dist/outdent.cjs +1 -125
  53. package/dist/outdent.mjs +1 -121
  54. package/dist/packem_shared/LRUCache-Bjo6gsbC.mjs +1 -0
  55. package/dist/packem_shared/LRUCache-TYqfUYE5.cjs +1 -0
  56. package/dist/packem_shared/WrapMode-BZ3jkEf1.mjs +8 -0
  57. package/dist/packem_shared/WrapMode-DR7vv3px.cjs +8 -0
  58. package/dist/packem_shared/alignText-BCKbnqhC.mjs +2 -0
  59. package/dist/packem_shared/alignText-CLZJuPP6.cjs +2 -0
  60. package/dist/packem_shared/constants-Cd17VNEv.mjs +1 -0
  61. package/dist/packem_shared/constants-D3K8u3G8.cjs +1 -0
  62. package/dist/packem_shared/generate-cache-key-BZf0GiMs.cjs +1 -0
  63. package/dist/packem_shared/generate-cache-key-DPByFaMH.mjs +1 -0
  64. package/dist/packem_shared/joinSegments-CDHNMXsF.cjs +1 -0
  65. package/dist/packem_shared/joinSegments-H7QJ7rwJ.mjs +1 -0
  66. package/dist/packem_shared/normalize-german-eszett-4k1qRtEP.mjs +1 -0
  67. package/dist/packem_shared/normalize-german-eszett-Bop4wOp9.cjs +1 -0
  68. package/dist/packem_shared/replaceString-Ce8TI_-L.cjs +1 -0
  69. package/dist/packem_shared/replaceString-D7R-5VFX.mjs +1 -0
  70. package/dist/packem_shared/slugify-B1vlQQO1.mjs +1 -0
  71. package/dist/packem_shared/slugify-CH3GI7E5.cjs +1 -0
  72. package/dist/packem_shared/transliterate-BXaP38Sh.mjs +5 -0
  73. package/dist/packem_shared/transliterate-CToQ-aeM.cjs +5 -0
  74. package/dist/slice.cjs +1 -419
  75. package/dist/slice.mjs +1 -415
  76. package/dist/test/utils.cjs +13 -74
  77. package/dist/test/utils.mjs +14 -69
  78. package/dist/test/vitest.cjs +1 -11
  79. package/dist/test/vitest.mjs +1 -7
  80. package/dist/truncate.cjs +1 -101
  81. package/dist/truncate.mjs +1 -97
  82. package/dist/utils.cjs +1 -65
  83. package/dist/utils.mjs +1 -56
  84. package/package.json +8 -1
  85. package/dist/packem_shared/LRUCache-Crb-m7cw.cjs +0 -53
  86. package/dist/packem_shared/LRUCache-udNErhWw.mjs +0 -51
  87. package/dist/packem_shared/WrapMode-BCVbMqYK.mjs +0 -545
  88. package/dist/packem_shared/WrapMode-DebG_Nll.cjs +0 -550
  89. package/dist/packem_shared/constants-6-GJ6zA-.cjs +0 -150
  90. package/dist/packem_shared/constants-CKdlkHVU.mjs +0 -99
  91. package/dist/packem_shared/generate-cache-key-D8f1auDB.cjs +0 -10
  92. package/dist/packem_shared/generate-cache-key-YSju5pj2.mjs +0 -8
  93. package/dist/packem_shared/joinSegments-BfSDBmPF.mjs +0 -46
  94. package/dist/packem_shared/joinSegments-HYXurfoq.cjs +0 -48
  95. package/dist/packem_shared/normalize-german-eszett-DJK0S2qj.cjs +0 -11
  96. package/dist/packem_shared/normalize-german-eszett-fpJ4lZL6.mjs +0 -9
  97. package/dist/packem_shared/replaceString-C7Dp5vAg.mjs +0 -200
  98. package/dist/packem_shared/replaceString-iYo1cDfZ.cjs +0 -202
  99. package/dist/packem_shared/slugify-SKjCL8DF.cjs +0 -50
  100. package/dist/packem_shared/slugify-pbxTlzeQ.mjs +0 -48
  101. package/dist/packem_shared/transliterate-4P32b49d.mjs +0 -47780
  102. package/dist/packem_shared/transliterate-CtOTNpLs.cjs +0 -47782
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;
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.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.3",
3
+ "version": "1.4.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",
@@ -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 };