@visulima/string 1.0.0 → 1.0.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 (36) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/case/camel-case.cjs +2 -2
  3. package/dist/case/camel-case.mjs +2 -2
  4. package/dist/case/capital-case.cjs +2 -2
  5. package/dist/case/capital-case.mjs +2 -2
  6. package/dist/case/flip-case.cjs +1 -1
  7. package/dist/case/flip-case.mjs +1 -1
  8. package/dist/case/index.cjs +1 -1
  9. package/dist/case/index.mjs +1 -1
  10. package/dist/case/kebab-case.cjs +2 -2
  11. package/dist/case/kebab-case.mjs +2 -2
  12. package/dist/case/pascal-case.cjs +2 -2
  13. package/dist/case/pascal-case.mjs +2 -2
  14. package/dist/case/sentence-case.cjs +2 -2
  15. package/dist/case/sentence-case.mjs +2 -2
  16. package/dist/case/split-by-case.cjs +1 -1
  17. package/dist/case/split-by-case.mjs +1 -1
  18. package/dist/case/train-case.cjs +1 -1
  19. package/dist/case/train-case.mjs +1 -1
  20. package/dist/get-string-truncated-width.cjs +4 -2
  21. package/dist/get-string-truncated-width.mjs +4 -2
  22. package/dist/index.cjs +2 -2
  23. package/dist/index.mjs +2 -2
  24. package/dist/outdent.cjs +1 -1
  25. package/dist/outdent.mjs +1 -1
  26. package/dist/packem_shared/{WrapMode-BgOOthJV.mjs → WrapMode-D4OAY7qi.mjs} +1 -1
  27. package/dist/packem_shared/{WrapMode-ZqTeXK8X.cjs → WrapMode-DyodRTmi.cjs} +1 -1
  28. package/dist/packem_shared/{constants-BnVGLrDr.mjs → constants-CKNmLDBQ.mjs} +3 -1
  29. package/dist/packem_shared/{constants-HevSYUjU.cjs → constants-nihvIvk5.cjs} +4 -0
  30. package/dist/packem_shared/{joinSegments-BHY8PPnk.mjs → joinSegments-B2-yNNIj.mjs} +1 -1
  31. package/dist/packem_shared/{joinSegments-BH1CT4dK.cjs → joinSegments-CqLUoCzF.cjs} +1 -1
  32. package/dist/slice.cjs +9 -3
  33. package/dist/slice.mjs +9 -3
  34. package/dist/truncate.cjs +14 -4
  35. package/dist/truncate.mjs +14 -4
  36. package/package.json +11 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## @visulima/string [1.0.1](https://github.com/visulima/visulima/compare/@visulima/string@1.0.0...@visulima/string@1.0.1) (2025-03-21)
2
+
3
+ ### Bug Fixes
4
+
5
+ * fixed forgotten test change after adjustment ([59b8953](https://github.com/visulima/visulima/commit/59b8953a2aefdb4b6f919039e67809146df6a22e))
6
+ * fixed handling of wrong width calc on the slice ([199c6dd](https://github.com/visulima/visulima/commit/199c6dd57b33b751c067e7a964406583ade5dd28))
7
+
1
8
  ## @visulima/string 1.0.0 (2025-03-21)
2
9
 
3
10
  ### Features
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const constants = require('../packem_shared/constants-HevSYUjU.cjs');
3
+ const constants = require('../packem_shared/constants-nihvIvk5.cjs');
4
4
  const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
5
5
  const case_lowerFirst = require('./lower-first.cjs');
6
6
  const case_splitByCase = require('./split-by-case.cjs');
7
7
  const case_upperFirst = require('./upper-first.cjs');
8
8
  const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
9
- const joinSegments = require('../packem_shared/joinSegments-BH1CT4dK.cjs');
9
+ const joinSegments = require('../packem_shared/joinSegments-CqLUoCzF.cjs');
10
10
  const normalizeGermanEszett = require('../packem_shared/normalize-german-eszett-DJK0S2qj.cjs');
11
11
 
12
12
  var __defProp = Object.defineProperty;
@@ -1,10 +1,10 @@
1
- import { R as RE_FAST_ANSI } from '../packem_shared/constants-BnVGLrDr.mjs';
1
+ import { R as RE_FAST_ANSI } from '../packem_shared/constants-CKNmLDBQ.mjs';
2
2
  import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
3
3
  import lowerFirst from './lower-first.mjs';
4
4
  import { splitByCase } from './split-by-case.mjs';
5
5
  import upperFirst from './upper-first.mjs';
6
6
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
7
- import joinSegments from '../packem_shared/joinSegments-BHY8PPnk.mjs';
7
+ import joinSegments from '../packem_shared/joinSegments-B2-yNNIj.mjs';
8
8
  import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-fpJ4lZL6.mjs';
9
9
 
10
10
  var __defProp = Object.defineProperty;
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const constants = require('../packem_shared/constants-HevSYUjU.cjs');
3
+ const constants = require('../packem_shared/constants-nihvIvk5.cjs');
4
4
  const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
5
5
  const case_splitByCase = require('./split-by-case.cjs');
6
6
  const case_upperFirst = require('./upper-first.cjs');
7
7
  const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
8
- const joinSegments = require('../packem_shared/joinSegments-BH1CT4dK.cjs');
8
+ const joinSegments = require('../packem_shared/joinSegments-CqLUoCzF.cjs');
9
9
  const normalizeGermanEszett = require('../packem_shared/normalize-german-eszett-DJK0S2qj.cjs');
10
10
 
11
11
  var __defProp = Object.defineProperty;
@@ -1,9 +1,9 @@
1
- import { R as RE_FAST_ANSI } from '../packem_shared/constants-BnVGLrDr.mjs';
1
+ import { R as RE_FAST_ANSI } from '../packem_shared/constants-CKNmLDBQ.mjs';
2
2
  import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
3
3
  import { splitByCase } from './split-by-case.mjs';
4
4
  import upperFirst from './upper-first.mjs';
5
5
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
6
- import joinSegments from '../packem_shared/joinSegments-BHY8PPnk.mjs';
6
+ import joinSegments from '../packem_shared/joinSegments-B2-yNNIj.mjs';
7
7
  import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-fpJ4lZL6.mjs';
8
8
 
9
9
  var __defProp = Object.defineProperty;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
5
  const node_util = require('node:util');
6
- const constants = require('../packem_shared/constants-HevSYUjU.cjs');
6
+ const constants = require('../packem_shared/constants-nihvIvk5.cjs');
7
7
  const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
8
8
  const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
9
9
 
@@ -1,5 +1,5 @@
1
1
  import { stripVTControlCharacters } from 'node:util';
2
- import { s as stripEmoji } from '../packem_shared/constants-BnVGLrDr.mjs';
2
+ import { s as stripEmoji } from '../packem_shared/constants-CKNmLDBQ.mjs';
3
3
  import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
4
4
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
5
5
 
@@ -21,7 +21,7 @@ const case_splitByCase = require('./split-by-case.cjs');
21
21
  const case_titleCase = require('./title-case.cjs');
22
22
  const case_trainCase = require('./train-case.cjs');
23
23
  const case_upperFirst = require('./upper-first.cjs');
24
- const joinSegments = require('../packem_shared/joinSegments-BH1CT4dK.cjs');
24
+ const joinSegments = require('../packem_shared/joinSegments-CqLUoCzF.cjs');
25
25
 
26
26
 
27
27
 
@@ -17,4 +17,4 @@ export { splitByCase } from './split-by-case.mjs';
17
17
  export { default as titleCase } from './title-case.mjs';
18
18
  export { default as trainCase } from './train-case.mjs';
19
19
  export { default as upperFirst } from './upper-first.mjs';
20
- export { default as joinSegments } from '../packem_shared/joinSegments-BHY8PPnk.mjs';
20
+ export { default as joinSegments } from '../packem_shared/joinSegments-B2-yNNIj.mjs';
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const constants = require('../packem_shared/constants-HevSYUjU.cjs');
5
+ const constants = require('../packem_shared/constants-nihvIvk5.cjs');
6
6
  const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
7
7
  const case_splitByCase = require('./split-by-case.cjs');
8
8
  const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
9
- const joinSegments = require('../packem_shared/joinSegments-BH1CT4dK.cjs');
9
+ const joinSegments = require('../packem_shared/joinSegments-CqLUoCzF.cjs');
10
10
  const normalizeGermanEszett = require('../packem_shared/normalize-german-eszett-DJK0S2qj.cjs');
11
11
 
12
12
  var __defProp = Object.defineProperty;
@@ -1,8 +1,8 @@
1
- import { R as RE_FAST_ANSI } from '../packem_shared/constants-BnVGLrDr.mjs';
1
+ import { R as RE_FAST_ANSI } from '../packem_shared/constants-CKNmLDBQ.mjs';
2
2
  import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
3
3
  import { splitByCase } from './split-by-case.mjs';
4
4
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
5
- import joinSegments from '../packem_shared/joinSegments-BHY8PPnk.mjs';
5
+ import joinSegments from '../packem_shared/joinSegments-B2-yNNIj.mjs';
6
6
  import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-fpJ4lZL6.mjs';
7
7
 
8
8
  var __defProp = Object.defineProperty;
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const constants = require('../packem_shared/constants-HevSYUjU.cjs');
3
+ const constants = require('../packem_shared/constants-nihvIvk5.cjs');
4
4
  const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
5
5
  const case_splitByCase = require('./split-by-case.cjs');
6
6
  const case_upperFirst = require('./upper-first.cjs');
7
7
  const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
8
- const joinSegments = require('../packem_shared/joinSegments-BH1CT4dK.cjs');
8
+ const joinSegments = require('../packem_shared/joinSegments-CqLUoCzF.cjs');
9
9
  const normalizeGermanEszett = require('../packem_shared/normalize-german-eszett-DJK0S2qj.cjs');
10
10
 
11
11
  var __defProp = Object.defineProperty;
@@ -1,9 +1,9 @@
1
- import { R as RE_FAST_ANSI } from '../packem_shared/constants-BnVGLrDr.mjs';
1
+ import { R as RE_FAST_ANSI } from '../packem_shared/constants-CKNmLDBQ.mjs';
2
2
  import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
3
3
  import { splitByCase } from './split-by-case.mjs';
4
4
  import upperFirst from './upper-first.mjs';
5
5
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
6
- import joinSegments from '../packem_shared/joinSegments-BHY8PPnk.mjs';
6
+ import joinSegments from '../packem_shared/joinSegments-B2-yNNIj.mjs';
7
7
  import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-fpJ4lZL6.mjs';
8
8
 
9
9
  var __defProp = Object.defineProperty;
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const constants = require('../packem_shared/constants-HevSYUjU.cjs');
3
+ const constants = require('../packem_shared/constants-nihvIvk5.cjs');
4
4
  const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
5
5
  const case_splitByCase = require('./split-by-case.cjs');
6
6
  const case_upperFirst = require('./upper-first.cjs');
7
7
  const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
8
- const joinSegments = require('../packem_shared/joinSegments-BH1CT4dK.cjs');
8
+ const joinSegments = require('../packem_shared/joinSegments-CqLUoCzF.cjs');
9
9
  const normalizeGermanEszett = require('../packem_shared/normalize-german-eszett-DJK0S2qj.cjs');
10
10
 
11
11
  var __defProp = Object.defineProperty;
@@ -1,9 +1,9 @@
1
- import { R as RE_FAST_ANSI } from '../packem_shared/constants-BnVGLrDr.mjs';
1
+ import { R as RE_FAST_ANSI } from '../packem_shared/constants-CKNmLDBQ.mjs';
2
2
  import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
3
3
  import { splitByCase } from './split-by-case.mjs';
4
4
  import upperFirst from './upper-first.mjs';
5
5
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
6
- import joinSegments from '../packem_shared/joinSegments-BHY8PPnk.mjs';
6
+ import joinSegments from '../packem_shared/joinSegments-B2-yNNIj.mjs';
7
7
  import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-fpJ4lZL6.mjs';
8
8
 
9
9
  var __defProp = Object.defineProperty;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
5
  const node_util = require('node:util');
6
- const constants = require('../packem_shared/constants-HevSYUjU.cjs');
6
+ const constants = require('../packem_shared/constants-nihvIvk5.cjs');
7
7
  const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
8
8
 
9
9
  var __defProp$2 = Object.defineProperty;
@@ -1,5 +1,5 @@
1
1
  import { stripVTControlCharacters } from 'node:util';
2
- import { h as RE_EMOJI, s as stripEmoji, i as RE_SEPARATORS, R as RE_FAST_ANSI, j as RE_CYRILLIC, k as RE_LATIN, l as RE_GREEK, m as RE_GREEK_LATIN_SPLIT, n as RE_KANJI, o as RE_HEBREW, p as RE_ARABIC, q as RE_HANGUL, r as RE_UZBEK_LATIN_MODIFIER, t as RE_KATAKANA, u as RE_HIRAGANA, v as RE_DEVANAGARI, w as RE_BENGALI, x as RE_GUJARATI, y as RE_GURMUKHI, z as RE_KANNADA, A as RE_TAMIL, B as RE_TELUGU, C as RE_MALAYALAM, D as RE_SINHALA, E as RE_THAI, F as RE_LAO, G as RE_TIBETAN, H as RE_MYANMAR, I as RE_ETHIOPIC, J as RE_KHMER, K as RE_ORIYA } from '../packem_shared/constants-BnVGLrDr.mjs';
2
+ import { j as RE_EMOJI, s as stripEmoji, k as RE_SEPARATORS, R as RE_FAST_ANSI, l as RE_CYRILLIC, m as RE_LATIN, n as RE_GREEK, o as RE_GREEK_LATIN_SPLIT, p as RE_KANJI, q as RE_HEBREW, r as RE_ARABIC, t as RE_HANGUL, u as RE_UZBEK_LATIN_MODIFIER, v as RE_KATAKANA, w as RE_HIRAGANA, x as RE_DEVANAGARI, y as RE_BENGALI, z as RE_GUJARATI, A as RE_GURMUKHI, B as RE_KANNADA, C as RE_TAMIL, D as RE_TELUGU, E as RE_MALAYALAM, F as RE_SINHALA, G as RE_THAI, H as RE_LAO, I as RE_TIBETAN, J as RE_MYANMAR, K as RE_ETHIOPIC, L as RE_KHMER, M as RE_ORIYA } from '../packem_shared/constants-CKNmLDBQ.mjs';
3
3
  import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
4
4
 
5
5
  var __defProp$2 = Object.defineProperty;
@@ -4,7 +4,7 @@ const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
4
4
  const case_splitByCase = require('./split-by-case.cjs');
5
5
  const case_upperFirst = require('./upper-first.cjs');
6
6
  const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
7
- const joinSegments = require('../packem_shared/joinSegments-BH1CT4dK.cjs');
7
+ const joinSegments = require('../packem_shared/joinSegments-CqLUoCzF.cjs');
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -2,7 +2,7 @@ import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
2
2
  import { splitByCase } from './split-by-case.mjs';
3
3
  import upperFirst from './upper-first.mjs';
4
4
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
5
- import joinSegments from '../packem_shared/joinSegments-BHY8PPnk.mjs';
5
+ import joinSegments from '../packem_shared/joinSegments-B2-yNNIj.mjs';
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const constants = require('./packem_shared/constants-HevSYUjU.cjs');
5
+ const constants = require('./packem_shared/constants-nihvIvk5.cjs');
6
6
 
7
7
  var __defProp$2 = Object.defineProperty;
8
8
  var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
@@ -215,7 +215,9 @@ const getStringTruncatedWidth = /* @__PURE__ */ __name((input, options = {}) =>
215
215
  while (index < length) {
216
216
  if (hasAnsi && (input[index] === "\x1B" || input[index] === "›")) {
217
217
  constants.RE_ANSI.lastIndex = index;
218
- if (constants.RE_ANSI.test(input)) {
218
+ constants.RE_VALID_ANSI_PAIRS.lastIndex = index;
219
+ constants.RE_VALID_HYPERLINKS.lastIndex = index;
220
+ if (constants.RE_ANSI.test(input) && (constants.RE_VALID_ANSI_PAIRS.test(input) || constants.RE_VALID_HYPERLINKS.test(input))) {
219
221
  const ansiLength = constants.RE_ANSI.lastIndex - index;
220
222
  const ansiWidth = options.countAnsiEscapeCodes ? ansiLength : config.width.ansi;
221
223
  if (index + 3 < length && input.slice(index, index + 4) === "\x1B]8;") {
@@ -1,4 +1,4 @@
1
- import { a as RE_ANSI, L as RE_ANSI_LINK_END, M as RE_CONTROL, h as RE_EMOJI } from './packem_shared/constants-BnVGLrDr.mjs';
1
+ import { c as RE_ANSI, a as RE_VALID_ANSI_PAIRS, b as RE_VALID_HYPERLINKS, N as RE_ANSI_LINK_END, O as RE_CONTROL, j as RE_EMOJI } from './packem_shared/constants-CKNmLDBQ.mjs';
2
2
 
3
3
  var __defProp$2 = Object.defineProperty;
4
4
  var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
@@ -211,7 +211,9 @@ const getStringTruncatedWidth = /* @__PURE__ */ __name((input, options = {}) =>
211
211
  while (index < length) {
212
212
  if (hasAnsi && (input[index] === "\x1B" || input[index] === "›")) {
213
213
  RE_ANSI.lastIndex = index;
214
- if (RE_ANSI.test(input)) {
214
+ RE_VALID_ANSI_PAIRS.lastIndex = index;
215
+ RE_VALID_HYPERLINKS.lastIndex = index;
216
+ if (RE_ANSI.test(input) && (RE_VALID_ANSI_PAIRS.test(input) || RE_VALID_HYPERLINKS.test(input))) {
215
217
  const ansiLength = RE_ANSI.lastIndex - index;
216
218
  const ansiWidth = options.countAnsiEscapeCodes ? ansiLength : config.width.ansi;
217
219
  if (index + 3 < length && input.slice(index, index + 4) === "\x1B]8;") {
package/dist/index.cjs CHANGED
@@ -21,13 +21,13 @@ const case_splitByCase = require('./case/split-by-case.cjs');
21
21
  const case_titleCase = require('./case/title-case.cjs');
22
22
  const case_trainCase = require('./case/train-case.cjs');
23
23
  const case_upperFirst = require('./case/upper-first.cjs');
24
- const joinSegments = require('./packem_shared/joinSegments-BH1CT4dK.cjs');
24
+ const joinSegments = require('./packem_shared/joinSegments-CqLUoCzF.cjs');
25
25
  const getStringTruncatedWidth = require('./get-string-truncated-width.cjs');
26
26
  const getStringWidth = require('./get-string-width.cjs');
27
27
  const outdent = require('./outdent.cjs');
28
28
  const slice = require('./slice.cjs');
29
29
  const truncate = require('./truncate.cjs');
30
- const WrapMode = require('./packem_shared/WrapMode-ZqTeXK8X.cjs');
30
+ const WrapMode = require('./packem_shared/WrapMode-DyodRTmi.cjs');
31
31
 
32
32
 
33
33
 
package/dist/index.mjs CHANGED
@@ -17,10 +17,10 @@ export { splitByCase } from './case/split-by-case.mjs';
17
17
  export { default as titleCase } from './case/title-case.mjs';
18
18
  export { default as trainCase } from './case/train-case.mjs';
19
19
  export { default as upperFirst } from './case/upper-first.mjs';
20
- export { default as joinSegments } from './packem_shared/joinSegments-BHY8PPnk.mjs';
20
+ export { default as joinSegments } from './packem_shared/joinSegments-B2-yNNIj.mjs';
21
21
  export { getStringTruncatedWidth } from './get-string-truncated-width.mjs';
22
22
  export { getStringWidth } from './get-string-width.mjs';
23
23
  export { outdent } from './outdent.mjs';
24
24
  export { slice } from './slice.mjs';
25
25
  export { truncate } from './truncate.mjs';
26
- export { WrapMode, wordWrap } from './packem_shared/WrapMode-BgOOthJV.mjs';
26
+ export { WrapMode, wordWrap } from './packem_shared/WrapMode-D4OAY7qi.mjs';
package/dist/outdent.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const constants = require('./packem_shared/constants-HevSYUjU.cjs');
5
+ const constants = require('./packem_shared/constants-nihvIvk5.cjs');
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
package/dist/outdent.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { b as RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE, c as RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY, d as RE_LEADING_NEWLINE, e as RE_TRAILING_NEWLINE, f as RE_MATCH_NEWLINES, g as RE_DETECT_INDENTATION } from './packem_shared/constants-BnVGLrDr.mjs';
1
+ import { d as RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE, e as RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY, f as RE_LEADING_NEWLINE, g as RE_TRAILING_NEWLINE, h as RE_MATCH_NEWLINES, i as RE_DETECT_INDENTATION } from './packem_shared/constants-CKNmLDBQ.mjs';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -1,4 +1,4 @@
1
- import { N as ESCAPES, O as ANSI_ESCAPE_LINK, P as ANSI_SGR_TERMINATOR, Q as ANSI_ESCAPE_BELL, S as ANSI_CSI, T as RE_ESCAPE_PATTERN, U as ANSI_RESET_CODES, V as END_CODE, W as RE_ZERO_WIDTH } from './constants-BnVGLrDr.mjs';
1
+ import { P as ESCAPES, Q as ANSI_ESCAPE_LINK, S as ANSI_SGR_TERMINATOR, T as ANSI_ESCAPE_BELL, U as ANSI_CSI, V as RE_ESCAPE_PATTERN, W as ANSI_RESET_CODES, X as END_CODE, Y as RE_ZERO_WIDTH } from './constants-CKNmLDBQ.mjs';
2
2
  import { getStringWidth } from '../get-string-width.mjs';
3
3
 
4
4
  var __defProp$5 = Object.defineProperty;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const constants = require('./constants-HevSYUjU.cjs');
5
+ const constants = require('./constants-nihvIvk5.cjs');
6
6
  const getStringWidth = require('../get-string-width.cjs');
7
7
 
8
8
  var __defProp$5 = Object.defineProperty;
@@ -62,6 +62,8 @@ const RE_DETECT_INDENTATION = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
62
62
  const RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = /^[ \t]*[\r\n][ \t\r\n]*$/;
63
63
  const RE_MATCH_NEWLINES = /\r\n|\n|\r/g;
64
64
  const RE_ANSI = /[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g;
65
+ const RE_VALID_ANSI_PAIRS = /\u001B\[(\d+(?:;\d+)*)?m[^\u001B]*(?:\u001B\[(?:\d+(?:;\d+)*)?m|$)/g;
66
+ const RE_VALID_HYPERLINKS = /\u001B\]8;;[^\u0007]*\u0007[^\u001B]*(?:\u001B\]8;;\u0007|$)/g;
65
67
  const RE_ANSI_LINK_END = /\u001B\]8;;\u0007/y;
66
68
  const RE_CONTROL = /[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y;
67
69
  const RE_EMOJI = emojiRegex();
@@ -96,4 +98,4 @@ const RE_TIBETAN = new RegExp("\\p{Script=Tibetan}", "u");
96
98
  const RE_UZBEK_LATIN_MODIFIER = /[\u02BB\u02BC\u0027]/u;
97
99
  const stripEmoji = /* @__PURE__ */ __name((stringValue) => stringValue.replace(RE_EMOJI, ""), "stripEmoji");
98
100
 
99
- export { RE_TAMIL as A, RE_TELUGU as B, RE_MALAYALAM as C, RE_SINHALA as D, RE_THAI as E, RE_LAO as F, RE_TIBETAN as G, RE_MYANMAR as H, RE_ETHIOPIC as I, RE_KHMER as J, RE_ORIYA as K, RE_ANSI_LINK_END as L, RE_CONTROL as M, ESCAPES as N, ANSI_ESCAPE_LINK as O, ANSI_SGR_TERMINATOR as P, ANSI_ESCAPE_BELL as Q, RE_FAST_ANSI as R, ANSI_CSI as S, RE_ESCAPE_PATTERN as T, ANSI_RESET_CODES as U, END_CODE as V, RE_ZERO_WIDTH as W, RE_ANSI as a, RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE as b, RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY as c, RE_LEADING_NEWLINE as d, RE_TRAILING_NEWLINE as e, RE_MATCH_NEWLINES as f, RE_DETECT_INDENTATION as g, RE_EMOJI as h, RE_SEPARATORS as i, RE_CYRILLIC as j, RE_LATIN as k, RE_GREEK as l, RE_GREEK_LATIN_SPLIT as m, RE_KANJI as n, RE_HEBREW as o, RE_ARABIC as p, RE_HANGUL as q, RE_UZBEK_LATIN_MODIFIER as r, stripEmoji as s, RE_KATAKANA as t, RE_HIRAGANA as u, RE_DEVANAGARI as v, RE_BENGALI as w, RE_GUJARATI as x, RE_GURMUKHI as y, RE_KANNADA as z };
101
+ export { RE_GURMUKHI as A, RE_KANNADA as B, RE_TAMIL as C, RE_TELUGU as D, RE_MALAYALAM as E, RE_SINHALA as F, RE_THAI as G, RE_LAO as H, RE_TIBETAN as I, RE_MYANMAR as J, RE_ETHIOPIC as K, RE_KHMER as L, RE_ORIYA as M, RE_ANSI_LINK_END as N, RE_CONTROL as O, ESCAPES as P, ANSI_ESCAPE_LINK as Q, RE_FAST_ANSI as R, ANSI_SGR_TERMINATOR as S, ANSI_ESCAPE_BELL as T, ANSI_CSI as U, RE_ESCAPE_PATTERN as V, ANSI_RESET_CODES as W, END_CODE as X, RE_ZERO_WIDTH as Y, RE_VALID_ANSI_PAIRS as a, RE_VALID_HYPERLINKS as b, RE_ANSI as c, RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE as d, RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY as e, RE_LEADING_NEWLINE as f, RE_TRAILING_NEWLINE as g, RE_MATCH_NEWLINES as h, RE_DETECT_INDENTATION as i, RE_EMOJI as j, RE_SEPARATORS as k, RE_CYRILLIC as l, RE_LATIN as m, RE_GREEK as n, RE_GREEK_LATIN_SPLIT as o, RE_KANJI as p, RE_HEBREW as q, RE_ARABIC as r, stripEmoji as s, RE_HANGUL as t, RE_UZBEK_LATIN_MODIFIER as u, RE_KATAKANA as v, RE_HIRAGANA as w, RE_DEVANAGARI as x, RE_BENGALI as y, RE_GUJARATI as z };
@@ -64,6 +64,8 @@ const RE_DETECT_INDENTATION = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
64
64
  const RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE = /^[ \t]*[\r\n][ \t\r\n]*$/;
65
65
  const RE_MATCH_NEWLINES = /\r\n|\n|\r/g;
66
66
  const RE_ANSI = /[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g;
67
+ const RE_VALID_ANSI_PAIRS = /\u001B\[(\d+(?:;\d+)*)?m[^\u001B]*(?:\u001B\[(?:\d+(?:;\d+)*)?m|$)/g;
68
+ const RE_VALID_HYPERLINKS = /\u001B\]8;;[^\u0007]*\u0007[^\u001B]*(?:\u001B\]8;;\u0007|$)/g;
67
69
  const RE_ANSI_LINK_END = /\u001B\]8;;\u0007/y;
68
70
  const RE_CONTROL = /[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y;
69
71
  const RE_EMOJI = emojiRegex();
@@ -145,5 +147,7 @@ exports.RE_THAI = RE_THAI;
145
147
  exports.RE_TIBETAN = RE_TIBETAN;
146
148
  exports.RE_TRAILING_NEWLINE = RE_TRAILING_NEWLINE;
147
149
  exports.RE_UZBEK_LATIN_MODIFIER = RE_UZBEK_LATIN_MODIFIER;
150
+ exports.RE_VALID_ANSI_PAIRS = RE_VALID_ANSI_PAIRS;
151
+ exports.RE_VALID_HYPERLINKS = RE_VALID_HYPERLINKS;
148
152
  exports.RE_ZERO_WIDTH = RE_ZERO_WIDTH;
149
153
  exports.stripEmoji = stripEmoji;
@@ -1,4 +1,4 @@
1
- import { R as RE_FAST_ANSI } from './constants-BnVGLrDr.mjs';
1
+ import { R as RE_FAST_ANSI } from './constants-CKNmLDBQ.mjs';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const constants = require('./constants-HevSYUjU.cjs');
3
+ const constants = require('./constants-nihvIvk5.cjs');
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
package/dist/slice.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const constants = require('./packem_shared/constants-HevSYUjU.cjs');
5
+ const constants = require('./packem_shared/constants-nihvIvk5.cjs');
6
6
  const getStringWidth = require('./get-string-width.cjs');
7
7
  const LRUCache = require('./packem_shared/LRUCache-Crb-m7cw.cjs');
8
8
 
@@ -340,7 +340,7 @@ const fastSlice = /* @__PURE__ */ __name((inputString, startIndex, endIndex, opt
340
340
  }
341
341
  return result.join("");
342
342
  }, "fastSlice");
343
- const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = inputString.length, options = {}) => {
343
+ const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = Number.MAX_SAFE_INTEGER, options = {}) => {
344
344
  const config = {
345
345
  segmenter: defaultSegmenter,
346
346
  ...options
@@ -348,7 +348,8 @@ const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = in
348
348
  if (startIndex >= endIndex || inputString === "") {
349
349
  return "";
350
350
  }
351
- if (startIndex === 0 && endIndex >= inputString.length) {
351
+ const inputStringWidth = getStringWidth.getStringWidth(inputString, config.width);
352
+ if (startIndex === 0 && endIndex >= inputStringWidth) {
352
353
  return inputString;
353
354
  }
354
355
  if (startIndex < 0 || endIndex < 0) {
@@ -360,6 +361,11 @@ const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = in
360
361
  }
361
362
  return fastSlice(inputString, startIndex, endIndex, config);
362
363
  }
364
+ constants.RE_VALID_ANSI_PAIRS.lastIndex = 0;
365
+ constants.RE_VALID_HYPERLINKS.lastIndex = 0;
366
+ if (!constants.RE_VALID_ANSI_PAIRS.test(inputString) && !constants.RE_VALID_HYPERLINKS.test(inputString)) {
367
+ return inputString;
368
+ }
363
369
  const segments = processIntoStyledSegments(inputString, config);
364
370
  if (segments.length === 0) {
365
371
  return "";
package/dist/slice.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as RE_ANSI } from './packem_shared/constants-BnVGLrDr.mjs';
1
+ import { a as RE_VALID_ANSI_PAIRS, b as RE_VALID_HYPERLINKS, c as RE_ANSI } from './packem_shared/constants-CKNmLDBQ.mjs';
2
2
  import { getStringWidth } from './get-string-width.mjs';
3
3
  import LRUCache from './packem_shared/LRUCache-udNErhWw.mjs';
4
4
 
@@ -336,7 +336,7 @@ const fastSlice = /* @__PURE__ */ __name((inputString, startIndex, endIndex, opt
336
336
  }
337
337
  return result.join("");
338
338
  }, "fastSlice");
339
- const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = inputString.length, options = {}) => {
339
+ const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = Number.MAX_SAFE_INTEGER, options = {}) => {
340
340
  const config = {
341
341
  segmenter: defaultSegmenter,
342
342
  ...options
@@ -344,7 +344,8 @@ const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = in
344
344
  if (startIndex >= endIndex || inputString === "") {
345
345
  return "";
346
346
  }
347
- if (startIndex === 0 && endIndex >= inputString.length) {
347
+ const inputStringWidth = getStringWidth(inputString, config.width);
348
+ if (startIndex === 0 && endIndex >= inputStringWidth) {
348
349
  return inputString;
349
350
  }
350
351
  if (startIndex < 0 || endIndex < 0) {
@@ -356,6 +357,11 @@ const slice = /* @__PURE__ */ __name((inputString, startIndex = 0, endIndex = in
356
357
  }
357
358
  return fastSlice(inputString, startIndex, endIndex, config);
358
359
  }
360
+ RE_VALID_ANSI_PAIRS.lastIndex = 0;
361
+ RE_VALID_HYPERLINKS.lastIndex = 0;
362
+ if (!RE_VALID_ANSI_PAIRS.test(inputString) && !RE_VALID_HYPERLINKS.test(inputString)) {
363
+ return inputString;
364
+ }
359
365
  const segments = processIntoStyledSegments(inputString, config);
360
366
  if (segments.length === 0) {
361
367
  return "";
package/dist/truncate.cjs CHANGED
@@ -63,7 +63,9 @@ const truncate = /* @__PURE__ */ __name((input, limit, options = {}) => {
63
63
  const nearestSpace = findNearestSpace(input, width - limit + 1, true);
64
64
  return ellipsis + slice.slice(input, nearestSpace, width).trim();
65
65
  }
66
- return ellipsis + slice.slice(input, width - limit + ellipsisWidth, width);
66
+ return ellipsis + slice.slice(input, width - limit + ellipsisWidth, width, {
67
+ width: options.width
68
+ });
67
69
  }
68
70
  case "middle": {
69
71
  const half = Math.floor(limit / 2);
@@ -72,14 +74,22 @@ const truncate = /* @__PURE__ */ __name((input, limit, options = {}) => {
72
74
  const secondBreak = findNearestSpace(input, width - (limit - half) + 1, true);
73
75
  return slice.slice(input, 0, firstBreak) + ellipsis + slice.slice(input, secondBreak, width).trim();
74
76
  }
75
- return slice.slice(input, 0, half) + ellipsis + slice.slice(input, width - (limit - half) + ellipsisWidth, width);
77
+ return slice.slice(input, 0, half, {
78
+ width: options.width
79
+ }) + ellipsis + slice.slice(input, width - (limit - half) + ellipsisWidth, width, {
80
+ width: options.width
81
+ });
76
82
  }
77
83
  case "end": {
78
84
  if (preferTruncationOnSpace) {
79
85
  const nearestSpace = findNearestSpace(input, limit - 1);
80
- return slice.slice(input, 0, nearestSpace) + ellipsis;
86
+ return slice.slice(input, 0, nearestSpace, {
87
+ width: options.width
88
+ }) + ellipsis;
81
89
  }
82
- return slice.slice(input, 0, limit - ellipsisWidth) + ellipsis;
90
+ return slice.slice(input, 0, limit - ellipsisWidth, {
91
+ width: options.width
92
+ }) + ellipsis;
83
93
  }
84
94
  default: {
85
95
  throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${position}'`);
package/dist/truncate.mjs CHANGED
@@ -59,7 +59,9 @@ const truncate = /* @__PURE__ */ __name((input, limit, options = {}) => {
59
59
  const nearestSpace = findNearestSpace(input, width - limit + 1, true);
60
60
  return ellipsis + slice(input, nearestSpace, width).trim();
61
61
  }
62
- return ellipsis + slice(input, width - limit + ellipsisWidth, width);
62
+ return ellipsis + slice(input, width - limit + ellipsisWidth, width, {
63
+ width: options.width
64
+ });
63
65
  }
64
66
  case "middle": {
65
67
  const half = Math.floor(limit / 2);
@@ -68,14 +70,22 @@ const truncate = /* @__PURE__ */ __name((input, limit, options = {}) => {
68
70
  const secondBreak = findNearestSpace(input, width - (limit - half) + 1, true);
69
71
  return slice(input, 0, firstBreak) + ellipsis + slice(input, secondBreak, width).trim();
70
72
  }
71
- return slice(input, 0, half) + ellipsis + slice(input, width - (limit - half) + ellipsisWidth, width);
73
+ return slice(input, 0, half, {
74
+ width: options.width
75
+ }) + ellipsis + slice(input, width - (limit - half) + ellipsisWidth, width, {
76
+ width: options.width
77
+ });
72
78
  }
73
79
  case "end": {
74
80
  if (preferTruncationOnSpace) {
75
81
  const nearestSpace = findNearestSpace(input, limit - 1);
76
- return slice(input, 0, nearestSpace) + ellipsis;
82
+ return slice(input, 0, nearestSpace, {
83
+ width: options.width
84
+ }) + ellipsis;
77
85
  }
78
- return slice(input, 0, limit - ellipsisWidth) + ellipsis;
86
+ return slice(input, 0, limit - ellipsisWidth, {
87
+ width: options.width
88
+ }) + ellipsis;
79
89
  }
80
90
  default: {
81
91
  throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${position}'`);
package/package.json CHANGED
@@ -1,11 +1,21 @@
1
1
  {
2
2
  "name": "@visulima/string",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Functions for manipulating strings.",
5
5
  "keywords": [
6
6
  "visulima",
7
7
  "string",
8
8
  "string-manipulation",
9
+ "unicode",
10
+ "text-processing",
11
+ "i18n",
12
+ "internationalization",
13
+ "cjk",
14
+ "east-asian-width",
15
+ "grapheme-splitter",
16
+ "ansi-styles",
17
+ "text-slicing",
18
+ "text-truncation",
9
19
  "case-conversion",
10
20
  "camelcase",
11
21
  "pascalcase",