@visulima/string 1.0.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 (170) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE.md +77 -0
  3. package/README.md +880 -0
  4. package/dist/case/camel-case.cjs +59 -0
  5. package/dist/case/camel-case.d.cts +7 -0
  6. package/dist/case/camel-case.d.mts +7 -0
  7. package/dist/case/camel-case.d.ts +7 -0
  8. package/dist/case/camel-case.mjs +57 -0
  9. package/dist/case/capital-case.cjs +51 -0
  10. package/dist/case/capital-case.d.cts +7 -0
  11. package/dist/case/capital-case.d.mts +7 -0
  12. package/dist/case/capital-case.d.ts +7 -0
  13. package/dist/case/capital-case.mjs +49 -0
  14. package/dist/case/constant-case.cjs +11 -0
  15. package/dist/case/constant-case.d.cts +7 -0
  16. package/dist/case/constant-case.d.mts +7 -0
  17. package/dist/case/constant-case.d.ts +7 -0
  18. package/dist/case/constant-case.mjs +9 -0
  19. package/dist/case/dot-case.cjs +11 -0
  20. package/dist/case/dot-case.d.cts +7 -0
  21. package/dist/case/dot-case.d.mts +7 -0
  22. package/dist/case/dot-case.d.ts +7 -0
  23. package/dist/case/dot-case.mjs +9 -0
  24. package/dist/case/flat-case.cjs +11 -0
  25. package/dist/case/flat-case.d.cts +7 -0
  26. package/dist/case/flat-case.d.mts +7 -0
  27. package/dist/case/flat-case.d.ts +7 -0
  28. package/dist/case/flat-case.mjs +9 -0
  29. package/dist/case/flip-case.cjs +61 -0
  30. package/dist/case/flip-case.d.cts +8 -0
  31. package/dist/case/flip-case.d.mts +8 -0
  32. package/dist/case/flip-case.d.ts +8 -0
  33. package/dist/case/flip-case.mjs +57 -0
  34. package/dist/case/identify-case.cjs +30 -0
  35. package/dist/case/identify-case.d.cts +7 -0
  36. package/dist/case/identify-case.d.mts +7 -0
  37. package/dist/case/identify-case.d.ts +7 -0
  38. package/dist/case/identify-case.mjs +28 -0
  39. package/dist/case/index.cjs +47 -0
  40. package/dist/case/index.d.cts +26 -0
  41. package/dist/case/index.d.mts +26 -0
  42. package/dist/case/index.d.ts +26 -0
  43. package/dist/case/index.mjs +20 -0
  44. package/dist/case/kebab-case.cjs +61 -0
  45. package/dist/case/kebab-case.d.cts +11 -0
  46. package/dist/case/kebab-case.d.mts +11 -0
  47. package/dist/case/kebab-case.d.ts +11 -0
  48. package/dist/case/kebab-case.mjs +57 -0
  49. package/dist/case/lower-first.cjs +13 -0
  50. package/dist/case/lower-first.d.cts +7 -0
  51. package/dist/case/lower-first.d.mts +7 -0
  52. package/dist/case/lower-first.d.ts +7 -0
  53. package/dist/case/lower-first.mjs +11 -0
  54. package/dist/case/no-case.cjs +11 -0
  55. package/dist/case/no-case.d.cts +7 -0
  56. package/dist/case/no-case.d.mts +7 -0
  57. package/dist/case/no-case.d.ts +7 -0
  58. package/dist/case/no-case.mjs +9 -0
  59. package/dist/case/pascal-case.cjs +52 -0
  60. package/dist/case/pascal-case.d.cts +7 -0
  61. package/dist/case/pascal-case.d.mts +7 -0
  62. package/dist/case/pascal-case.d.ts +7 -0
  63. package/dist/case/pascal-case.mjs +50 -0
  64. package/dist/case/pascal-snake-case.cjs +32 -0
  65. package/dist/case/pascal-snake-case.d.cts +7 -0
  66. package/dist/case/pascal-snake-case.d.mts +7 -0
  67. package/dist/case/pascal-snake-case.d.ts +7 -0
  68. package/dist/case/pascal-snake-case.mjs +30 -0
  69. package/dist/case/path-case.cjs +11 -0
  70. package/dist/case/path-case.d.cts +7 -0
  71. package/dist/case/path-case.d.mts +7 -0
  72. package/dist/case/path-case.d.ts +7 -0
  73. package/dist/case/path-case.mjs +9 -0
  74. package/dist/case/sentence-case.cjs +58 -0
  75. package/dist/case/sentence-case.d.cts +7 -0
  76. package/dist/case/sentence-case.d.mts +7 -0
  77. package/dist/case/sentence-case.d.ts +7 -0
  78. package/dist/case/sentence-case.mjs +56 -0
  79. package/dist/case/snake-case.cjs +11 -0
  80. package/dist/case/snake-case.d.cts +7 -0
  81. package/dist/case/snake-case.d.mts +7 -0
  82. package/dist/case/snake-case.d.ts +7 -0
  83. package/dist/case/snake-case.mjs +9 -0
  84. package/dist/case/split-by-case.cjs +638 -0
  85. package/dist/case/split-by-case.d.cts +16 -0
  86. package/dist/case/split-by-case.d.mts +16 -0
  87. package/dist/case/split-by-case.d.ts +16 -0
  88. package/dist/case/split-by-case.mjs +634 -0
  89. package/dist/case/title-case.cjs +47 -0
  90. package/dist/case/title-case.d.cts +7 -0
  91. package/dist/case/title-case.d.mts +7 -0
  92. package/dist/case/title-case.d.ts +7 -0
  93. package/dist/case/title-case.mjs +45 -0
  94. package/dist/case/train-case.cjs +44 -0
  95. package/dist/case/train-case.d.cts +7 -0
  96. package/dist/case/train-case.d.mts +7 -0
  97. package/dist/case/train-case.d.ts +7 -0
  98. package/dist/case/train-case.mjs +42 -0
  99. package/dist/case/upper-first.cjs +13 -0
  100. package/dist/case/upper-first.d.cts +7 -0
  101. package/dist/case/upper-first.d.mts +7 -0
  102. package/dist/case/upper-first.d.ts +7 -0
  103. package/dist/case/upper-first.mjs +11 -0
  104. package/dist/get-string-truncated-width.cjs +386 -0
  105. package/dist/get-string-truncated-width.d.cts +25 -0
  106. package/dist/get-string-truncated-width.d.mts +25 -0
  107. package/dist/get-string-truncated-width.d.ts +25 -0
  108. package/dist/get-string-truncated-width.mjs +382 -0
  109. package/dist/get-string-width.cjs +11 -0
  110. package/dist/get-string-width.d.cts +6 -0
  111. package/dist/get-string-width.d.mts +6 -0
  112. package/dist/get-string-width.d.ts +6 -0
  113. package/dist/get-string-width.mjs +7 -0
  114. package/dist/index.cjs +60 -0
  115. package/dist/index.d.cts +43 -0
  116. package/dist/index.d.mts +43 -0
  117. package/dist/index.d.ts +43 -0
  118. package/dist/index.mjs +26 -0
  119. package/dist/native-string-types.d.cts +128 -0
  120. package/dist/native-string-types.d.mts +128 -0
  121. package/dist/native-string-types.d.ts +128 -0
  122. package/dist/outdent.cjs +122 -0
  123. package/dist/outdent.d.cts +15 -0
  124. package/dist/outdent.d.mts +15 -0
  125. package/dist/outdent.d.ts +15 -0
  126. package/dist/outdent.mjs +118 -0
  127. package/dist/packem_shared/LRUCache-Crb-m7cw.cjs +53 -0
  128. package/dist/packem_shared/LRUCache-udNErhWw.mjs +51 -0
  129. package/dist/packem_shared/WrapMode-BgOOthJV.mjs +545 -0
  130. package/dist/packem_shared/WrapMode-ZqTeXK8X.cjs +550 -0
  131. package/dist/packem_shared/constants-BnVGLrDr.mjs +99 -0
  132. package/dist/packem_shared/constants-HevSYUjU.cjs +149 -0
  133. package/dist/packem_shared/generate-cache-key-D8f1auDB.cjs +10 -0
  134. package/dist/packem_shared/generate-cache-key-YSju5pj2.mjs +8 -0
  135. package/dist/packem_shared/joinSegments-BH1CT4dK.cjs +48 -0
  136. package/dist/packem_shared/joinSegments-BHY8PPnk.mjs +46 -0
  137. package/dist/packem_shared/normalize-german-eszett-DJK0S2qj.cjs +11 -0
  138. package/dist/packem_shared/normalize-german-eszett-fpJ4lZL6.mjs +9 -0
  139. package/dist/packem_shared/types-BAd3WDHo.d.mts +59 -0
  140. package/dist/packem_shared/types-BNbQJg02.d.cts +41 -0
  141. package/dist/packem_shared/types-BNbQJg02.d.mts +41 -0
  142. package/dist/packem_shared/types-BNbQJg02.d.ts +41 -0
  143. package/dist/packem_shared/types-BttWSSIk.d.ts +59 -0
  144. package/dist/packem_shared/types-D2-6p7t1.d.cts +59 -0
  145. package/dist/slice.cjs +413 -0
  146. package/dist/slice.d.cts +10 -0
  147. package/dist/slice.d.mts +10 -0
  148. package/dist/slice.d.ts +10 -0
  149. package/dist/slice.mjs +409 -0
  150. package/dist/test/utils.cjs +77 -0
  151. package/dist/test/utils.d.cts +30 -0
  152. package/dist/test/utils.d.mts +30 -0
  153. package/dist/test/utils.d.ts +30 -0
  154. package/dist/test/utils.mjs +71 -0
  155. package/dist/test/vitest.cjs +11 -0
  156. package/dist/test/vitest.d.cts +8 -0
  157. package/dist/test/vitest.d.mts +8 -0
  158. package/dist/test/vitest.d.ts +8 -0
  159. package/dist/test/vitest.mjs +7 -0
  160. package/dist/truncate.cjs +90 -0
  161. package/dist/truncate.d.cts +12 -0
  162. package/dist/truncate.d.mts +12 -0
  163. package/dist/truncate.d.ts +12 -0
  164. package/dist/truncate.mjs +86 -0
  165. package/dist/utils.cjs +9 -0
  166. package/dist/utils.d.cts +14 -0
  167. package/dist/utils.d.mts +14 -0
  168. package/dist/utils.d.ts +14 -0
  169. package/dist/utils.mjs +1 -0
  170. package/package.json +468 -0
@@ -0,0 +1,7 @@
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 };
@@ -0,0 +1,90 @@
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
+ const { ellipsis = DEFAULT_ELLIPSIS, position = "end", preferTruncationOnSpace = false } = options;
37
+ let ellipsisWidth = options.ellipsisWidth ?? ellipsis === DEFAULT_ELLIPSIS ? 2 : void 0;
38
+ if (ellipsisWidth === void 0) {
39
+ ellipsisWidth = getStringTruncatedWidth.getStringTruncatedWidth(ellipsis, {
40
+ ...options.width,
41
+ ellipsis: "",
42
+ ellipsisWidth: 0,
43
+ limit: Number.POSITIVE_INFINITY
44
+ }).width;
45
+ }
46
+ if (limit === 1 && ellipsisWidth === 1) {
47
+ return ellipsis;
48
+ }
49
+ if (limit === 1) {
50
+ return "";
51
+ }
52
+ const { width } = getStringTruncatedWidth.getStringTruncatedWidth(input, {
53
+ ...options.width,
54
+ ellipsis,
55
+ ellipsisWidth
56
+ });
57
+ if (width <= limit) {
58
+ return input;
59
+ }
60
+ switch (position) {
61
+ case "start": {
62
+ if (preferTruncationOnSpace) {
63
+ const nearestSpace = findNearestSpace(input, width - limit + 1, true);
64
+ return ellipsis + slice.slice(input, nearestSpace, width).trim();
65
+ }
66
+ return ellipsis + slice.slice(input, width - limit + ellipsisWidth, width);
67
+ }
68
+ case "middle": {
69
+ const half = Math.floor(limit / 2);
70
+ if (preferTruncationOnSpace) {
71
+ const firstBreak = findNearestSpace(input, half);
72
+ const secondBreak = findNearestSpace(input, width - (limit - half) + 1, true);
73
+ return slice.slice(input, 0, firstBreak) + ellipsis + slice.slice(input, secondBreak, width).trim();
74
+ }
75
+ return slice.slice(input, 0, half) + ellipsis + slice.slice(input, width - (limit - half) + ellipsisWidth, width);
76
+ }
77
+ case "end": {
78
+ if (preferTruncationOnSpace) {
79
+ const nearestSpace = findNearestSpace(input, limit - 1);
80
+ return slice.slice(input, 0, nearestSpace) + ellipsis;
81
+ }
82
+ return slice.slice(input, 0, limit - ellipsisWidth) + ellipsis;
83
+ }
84
+ default: {
85
+ throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${position}'`);
86
+ }
87
+ }
88
+ }, "truncate");
89
+
90
+ exports.truncate = truncate;
@@ -0,0 +1,12 @@
1
+ import { StringTruncatedWidthOptions } from './get-string-truncated-width.cjs';
2
+
3
+ type TruncateOptions = {
4
+ ellipsis?: string;
5
+ ellipsisWidth?: number;
6
+ position?: "end" | "middle" | "start";
7
+ preferTruncationOnSpace?: boolean;
8
+ width?: Omit<StringTruncatedWidthOptions, "ellipsis" | "ellipsisWidth" | "limit">;
9
+ };
10
+ declare const truncate: (input: string, limit: number, options?: TruncateOptions) => string;
11
+
12
+ export { type TruncateOptions, truncate };
@@ -0,0 +1,12 @@
1
+ import { StringTruncatedWidthOptions } from './get-string-truncated-width.mjs';
2
+
3
+ type TruncateOptions = {
4
+ ellipsis?: string;
5
+ ellipsisWidth?: number;
6
+ position?: "end" | "middle" | "start";
7
+ preferTruncationOnSpace?: boolean;
8
+ width?: Omit<StringTruncatedWidthOptions, "ellipsis" | "ellipsisWidth" | "limit">;
9
+ };
10
+ declare const truncate: (input: string, limit: number, options?: TruncateOptions) => string;
11
+
12
+ export { type TruncateOptions, truncate };
@@ -0,0 +1,12 @@
1
+ import { StringTruncatedWidthOptions } from './get-string-truncated-width.js';
2
+
3
+ type TruncateOptions = {
4
+ ellipsis?: string;
5
+ ellipsisWidth?: number;
6
+ position?: "end" | "middle" | "start";
7
+ preferTruncationOnSpace?: boolean;
8
+ width?: Omit<StringTruncatedWidthOptions, "ellipsis" | "ellipsisWidth" | "limit">;
9
+ };
10
+ declare const truncate: (input: string, limit: number, options?: TruncateOptions) => string;
11
+
12
+ export { type TruncateOptions, truncate };
@@ -0,0 +1,86 @@
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
+ const { ellipsis = DEFAULT_ELLIPSIS, position = "end", preferTruncationOnSpace = false } = options;
33
+ let ellipsisWidth = options.ellipsisWidth ?? ellipsis === DEFAULT_ELLIPSIS ? 2 : void 0;
34
+ if (ellipsisWidth === void 0) {
35
+ ellipsisWidth = getStringTruncatedWidth(ellipsis, {
36
+ ...options.width,
37
+ ellipsis: "",
38
+ ellipsisWidth: 0,
39
+ limit: Number.POSITIVE_INFINITY
40
+ }).width;
41
+ }
42
+ if (limit === 1 && ellipsisWidth === 1) {
43
+ return ellipsis;
44
+ }
45
+ if (limit === 1) {
46
+ return "";
47
+ }
48
+ const { width } = getStringTruncatedWidth(input, {
49
+ ...options.width,
50
+ ellipsis,
51
+ ellipsisWidth
52
+ });
53
+ if (width <= limit) {
54
+ return input;
55
+ }
56
+ switch (position) {
57
+ case "start": {
58
+ if (preferTruncationOnSpace) {
59
+ const nearestSpace = findNearestSpace(input, width - limit + 1, true);
60
+ return ellipsis + slice(input, nearestSpace, width).trim();
61
+ }
62
+ return ellipsis + slice(input, width - limit + ellipsisWidth, width);
63
+ }
64
+ case "middle": {
65
+ const half = Math.floor(limit / 2);
66
+ if (preferTruncationOnSpace) {
67
+ const firstBreak = findNearestSpace(input, half);
68
+ const secondBreak = findNearestSpace(input, width - (limit - half) + 1, true);
69
+ return slice(input, 0, firstBreak) + ellipsis + slice(input, secondBreak, width).trim();
70
+ }
71
+ return slice(input, 0, half) + ellipsis + slice(input, width - (limit - half) + ellipsisWidth, width);
72
+ }
73
+ case "end": {
74
+ if (preferTruncationOnSpace) {
75
+ const nearestSpace = findNearestSpace(input, limit - 1);
76
+ return slice(input, 0, nearestSpace) + ellipsis;
77
+ }
78
+ return slice(input, 0, limit - ellipsisWidth) + ellipsis;
79
+ }
80
+ default: {
81
+ throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${position}'`);
82
+ }
83
+ }
84
+ }, "truncate");
85
+
86
+ export { truncate };
package/dist/utils.cjs ADDED
@@ -0,0 +1,9 @@
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
+
8
+
9
+ exports.LRUCache = LRUCache;
@@ -0,0 +1,14 @@
1
+ declare class LRUCache<K, V> {
2
+ private readonly capacity;
3
+ private readonly cache;
4
+ private keyOrder;
5
+ constructor(capacity: number);
6
+ get(key: K): V | undefined;
7
+ has(key: K): boolean;
8
+ set(key: K, value: V): void;
9
+ delete(key: K): void;
10
+ clear(): void;
11
+ size(): number;
12
+ }
13
+
14
+ export { LRUCache };
@@ -0,0 +1,14 @@
1
+ declare class LRUCache<K, V> {
2
+ private readonly capacity;
3
+ private readonly cache;
4
+ private keyOrder;
5
+ constructor(capacity: number);
6
+ get(key: K): V | undefined;
7
+ has(key: K): boolean;
8
+ set(key: K, value: V): void;
9
+ delete(key: K): void;
10
+ clear(): void;
11
+ size(): number;
12
+ }
13
+
14
+ export { LRUCache };
@@ -0,0 +1,14 @@
1
+ declare class LRUCache<K, V> {
2
+ private readonly capacity;
3
+ private readonly cache;
4
+ private keyOrder;
5
+ constructor(capacity: number);
6
+ get(key: K): V | undefined;
7
+ has(key: K): boolean;
8
+ set(key: K, value: V): void;
9
+ delete(key: K): void;
10
+ clear(): void;
11
+ size(): number;
12
+ }
13
+
14
+ export { LRUCache };
package/dist/utils.mjs ADDED
@@ -0,0 +1 @@
1
+ export { default as LRUCache } from './packem_shared/LRUCache-udNErhWw.mjs';