@visulima/string 3.0.0 → 3.1.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.
- package/CHANGELOG.md +7 -0
- package/dist/align-text.d.ts +29 -29
- package/dist/case/camel-case.d.ts +16 -16
- package/dist/case/camel-case.js +1 -1
- package/dist/case/capital-case.d.ts +13 -13
- package/dist/case/capital-case.js +1 -1
- package/dist/case/constant-case.d.ts +13 -13
- package/dist/case/dot-case.d.ts +13 -13
- package/dist/case/flat-case.d.ts +11 -11
- package/dist/case/flip-case.d.ts +14 -14
- package/dist/case/flip-case.js +1 -1
- package/dist/case/identify-case.d.ts +14 -14
- package/dist/case/index.d.ts +7 -7
- package/dist/case/kebab-case.d.ts +22 -22
- package/dist/case/kebab-case.js +1 -1
- package/dist/case/lower-first.d.ts +12 -12
- package/dist/case/no-case.d.ts +13 -13
- package/dist/case/pascal-case.d.ts +16 -16
- package/dist/case/pascal-case.js +1 -1
- package/dist/case/pascal-snake-case.d.ts +13 -13
- package/dist/case/pascal-snake-case.js +1 -1
- package/dist/case/path-case.d.ts +13 -13
- package/dist/case/sentence-case.d.ts +13 -13
- package/dist/case/sentence-case.js +1 -1
- package/dist/case/snake-case.d.ts +13 -13
- package/dist/case/split-by-case.d.ts +20 -20
- package/dist/case/split-by-case.js +1 -1
- package/dist/case/title-case.d.ts +11 -11
- package/dist/case/title-case.js +1 -1
- package/dist/case/train-case.d.ts +13 -13
- package/dist/case/train-case.js +1 -1
- package/dist/case/upper-first.d.ts +12 -12
- package/dist/closest-string.d.ts +28 -28
- package/dist/compare-similarity.d.ts +33 -33
- package/dist/count-occurrences.d.ts +6 -6
- package/dist/direction.d.ts +4 -4
- package/dist/east-asian-width.d.ts +20 -14
- package/dist/excerpt.d.ts +18 -18
- package/dist/get-string-truncated-width.d.ts +131 -131
- package/dist/get-string-truncated-width.js +1 -1
- package/dist/get-string-width.d.ts +56 -56
- package/dist/indent.d.ts +8 -7
- package/dist/index.d.ts +2 -2
- package/dist/is-fullwidth-code-point.d.ts +4 -4
- package/dist/levenshtein.d.ts +19 -19
- package/dist/native-string-types.d.ts +212 -228
- package/dist/outdent.d.ts +64 -64
- package/dist/packem_shared/generate-cache-key-B_0X7MKm.js +1 -0
- package/dist/packem_shared/strip-vt-control-characters-BW1RglLp.js +1 -0
- package/dist/packem_shared/types.d-CMNqA5bi.d.ts +402 -0
- package/dist/packem_shared/types.d-LgsTR37y.d.ts +360 -0
- package/dist/replace-string.d.ts +7 -7
- package/dist/slice.d.ts +38 -38
- package/dist/slice.js +1 -1
- package/dist/slugify.d.ts +9 -9
- package/dist/test/utils.d.ts +14 -14
- package/dist/test/utils.js +11 -11
- package/dist/test/vitest.d.ts +2 -2
- package/dist/transliterate.d.ts +7 -7
- package/dist/transliterate.js +2 -2
- package/dist/truncate.d.ts +37 -37
- package/dist/utilities.d.ts +23 -23
- package/dist/word-similarity-sort.d.ts +32 -32
- package/dist/word-wrap.d.ts +33 -33
- package/dist/word-wrap.js +7 -7
- package/package.json +1 -1
- package/dist/packem_shared/generate-cache-key-BqU1Cqwm.js +0 -1
- package/dist/packem_shared/types.d-CmNvyl4l.d.ts +0 -360
- package/dist/packem_shared/types.d-fhe030jX.d.ts +0 -402
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { b as CaseOptions, S as SentenceCase } from "../packem_shared/types.d-
|
|
2
|
-
import "../packem_shared/types.d-
|
|
1
|
+
import { b as CaseOptions, S as SentenceCase } from "../packem_shared/types.d-CMNqA5bi.js";
|
|
2
|
+
import "../packem_shared/types.d-LgsTR37y.js";
|
|
3
3
|
/**
|
|
4
|
-
* Converts a string to Sentence case.
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* sentenceCase("foo bar") // => "Foo bar"
|
|
8
|
-
* sentenceCase("foo-bar") // => "Foo bar"
|
|
9
|
-
* sentenceCase("foo_bar") // => "Foo bar"
|
|
10
|
-
* sentenceCase("XMLHttpRequest") // => "Xml http request"
|
|
11
|
-
* sentenceCase("AJAXRequest") // => "Ajax request"
|
|
12
|
-
* sentenceCase("QueryXML123String") // => "Query xml 123 string"
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
4
|
+
* Converts a string to Sentence case.
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* sentenceCase("foo bar") // => "Foo bar"
|
|
8
|
+
* sentenceCase("foo-bar") // => "Foo bar"
|
|
9
|
+
* sentenceCase("foo_bar") // => "Foo bar"
|
|
10
|
+
* sentenceCase("XMLHttpRequest") // => "Xml http request"
|
|
11
|
+
* sentenceCase("AJAXRequest") // => "Ajax request"
|
|
12
|
+
* sentenceCase("QueryXML123String") // => "Query xml 123 string"
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
15
|
declare const sentenceCase: <T extends string = string>(value?: T, options?: CaseOptions) => SentenceCase<T>;
|
|
16
16
|
export { sentenceCase as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c}from"../packem_shared/constants-aPzGW29R.js";import{i as p}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as f}from"./split-by-case.js";import h from"./upper-first.js";import{
|
|
1
|
+
import{c}from"../packem_shared/constants-aPzGW29R.js";import{i as p}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as f}from"./split-by-case.js";import h from"./upper-first.js";import{a as A}from"../packem_shared/generate-cache-key-B_0X7MKm.js";import d from"../packem_shared/joinSegments-CaHT-45s.js";import{a as u}from"../packem_shared/normalize-german-eszett-hNMwtGjd.js";const w=new p(1e3),$=(s,o)=>{if(typeof s!="string")return"";const a=o?.cache??!1,i=o?.cacheStore??w;let r;if(a&&(r=A(s,o)),a&&r&&i.has(r))return i.get(r);let e=!0;const n=d(f(s,{handleAnsi:o?.handleAnsi,handleEmoji:o?.handleEmoji,knownAcronyms:o?.knownAcronyms,locale:o?.locale,normalize:o?.normalize,separators:void 0,stripAnsi:o?.stripAnsi,stripEmoji:o?.stripEmoji}).map(t=>{if(o?.handleAnsi&&c.test(t))return t;const l=o?.locale?.startsWith("de")?u(t):t,m=o?.locale?l.toLocaleLowerCase(o.locale):l.toLowerCase();return e?(e=!1,h(m,o)):m})," ");return a&&r&&i.set(r,n),n};export{$ as default};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { b as CaseOptions, h as SnakeCase } from "../packem_shared/types.d-
|
|
2
|
-
import "../packem_shared/types.d-
|
|
1
|
+
import { b as CaseOptions, h as SnakeCase } from "../packem_shared/types.d-CMNqA5bi.js";
|
|
2
|
+
import "../packem_shared/types.d-LgsTR37y.js";
|
|
3
3
|
/**
|
|
4
|
-
* Converts a string to snake_case.
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* snakeCase("fooBar") // => "foo_bar"
|
|
8
|
-
* snakeCase("foo bar") // => "foo_bar"
|
|
9
|
-
* snakeCase("foo-bar") // => "foo_bar"
|
|
10
|
-
* snakeCase("XMLHttpRequest") // => "xml_http_request"
|
|
11
|
-
* snakeCase("AJAXRequest") // => "ajax_request"
|
|
12
|
-
* snakeCase("QueryXML123String") // => "query_xml_123_string"
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
4
|
+
* Converts a string to snake_case.
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* snakeCase("fooBar") // => "foo_bar"
|
|
8
|
+
* snakeCase("foo bar") // => "foo_bar"
|
|
9
|
+
* snakeCase("foo-bar") // => "foo_bar"
|
|
10
|
+
* snakeCase("XMLHttpRequest") // => "xml_http_request"
|
|
11
|
+
* snakeCase("AJAXRequest") // => "ajax_request"
|
|
12
|
+
* snakeCase("QueryXML123String") // => "query_xml_123_string"
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
15
|
declare const snakeCase: <T extends string = string>(value?: T, options?: CaseOptions) => SnakeCase<T>;
|
|
16
16
|
export { snakeCase as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LocaleOptions, i as SplitByCase } from "../packem_shared/types.d-
|
|
2
|
-
import "../packem_shared/types.d-
|
|
1
|
+
import { L as LocaleOptions, i as SplitByCase } from "../packem_shared/types.d-CMNqA5bi.js";
|
|
2
|
+
import "../packem_shared/types.d-LgsTR37y.js";
|
|
3
3
|
/** Options for the `splitByCase` function. */
|
|
4
4
|
interface SplitOptions extends LocaleOptions {
|
|
5
5
|
/** Whether to handle ANSI escape sequences. (default: false) */
|
|
@@ -18,23 +18,23 @@ interface SplitOptions extends LocaleOptions {
|
|
|
18
18
|
stripEmoji?: boolean;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Splits a string into segments based on various criteria including case changes,
|
|
22
|
-
* separators, Unicode scripts, ANSI codes, and emojis.
|
|
23
|
-
*
|
|
24
|
-
* This is the core splitting logic used by various case conversion functions.
|
|
25
|
-
* @template T - The specific literal type of the input string, if known.
|
|
26
|
-
* @param input The string to split.
|
|
27
|
-
* @param options Configuration options for splitting behavior.
|
|
28
|
-
* @returns An array of string segments.
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* splitByCase("fooBarBaz") // => ["foo", "Bar", "Baz"]
|
|
32
|
-
* splitByCase("foo_bar-baz") // => ["foo", "bar", "baz"]
|
|
33
|
-
* splitByCase("HTMLElement") // => ["HTML", "Element"]
|
|
34
|
-
* splitByCase("HTMLElement", { knownAcronyms: ["HTML"] }) // => ["HTML", "Element"]
|
|
35
|
-
* splitByCase("\u001B[31mhello\u001B[0mWorld", { handleAnsi: true }) // => ["\u001B[31m", "hello", "\u001B[0m", "World"]
|
|
36
|
-
* splitByCase("hello🌍world", { handleEmoji: true }) // => ["hello", "🌍", "world"]
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
21
|
+
* Splits a string into segments based on various criteria including case changes,
|
|
22
|
+
* separators, Unicode scripts, ANSI codes, and emojis.
|
|
23
|
+
*
|
|
24
|
+
* This is the core splitting logic used by various case conversion functions.
|
|
25
|
+
* @template T - The specific literal type of the input string, if known.
|
|
26
|
+
* @param input The string to split.
|
|
27
|
+
* @param options Configuration options for splitting behavior.
|
|
28
|
+
* @returns An array of string segments.
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* splitByCase("fooBarBaz") // => ["foo", "Bar", "Baz"]
|
|
32
|
+
* splitByCase("foo_bar-baz") // => ["foo", "bar", "baz"]
|
|
33
|
+
* splitByCase("HTMLElement") // => ["HTML", "Element"]
|
|
34
|
+
* splitByCase("HTMLElement", { knownAcronyms: ["HTML"] }) // => ["HTML", "Element"]
|
|
35
|
+
* splitByCase("\u001B[31mhello\u001B[0mWorld", { handleAnsi: true }) // => ["\u001B[31m", "hello", "\u001B[0m", "World"]
|
|
36
|
+
* splitByCase("hello🌍world", { handleEmoji: true }) // => ["hello", "🌍", "world"]
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
39
|
declare const splitByCase: <T extends string = string>(input: T, options?: SplitOptions) => SplitByCase<T>;
|
|
40
40
|
export { SplitOptions, splitByCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{b as W,s as v,l as F,c as x,m,n as U,o as b,p as j,q as y,r as $,t as B,u as q,v as G,w as K,x as H,y as V,z as Z,A as Q,B as X,C as tt,D as et,E as st,F as nt,G as lt,H as rt,I as ot,J as at,K as it,L as ht,M as ct,N as ut}from"../packem_shared/constants-aPzGW29R.js";import{i as ft}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{r as pt}from"../packem_shared/strip-vt-control-characters-BW1RglLp.js";const N=new ft(1e3),gt=/[.*+?^${}()|[\]\\]/g,At=t=>{const l=t.join("");if(N.has(l)){const A=N.get(l);return A.lastIndex=0,A}const c=t.map(A=>A.replaceAll(gt,String.raw`\$&`)).join("|"),g=new RegExp(c,"g");return N.set(l,g),g},Et=t=>{const l=[];let c=0,g;for(W.lastIndex=0;(g=W.exec(t))!==null;)g.index>c&&l.push(t.slice(c,g.index)),l.push(g[0]),c=W.lastIndex;return c<t.length&&l.push(t.slice(c)),l.filter(Boolean)},Rt=/[ČŠŽĐ]/i,O=new Uint8Array(128),P=new Uint8Array(128),z=new Uint8Array(128);for(let t=0;t<128;t++)O[t]=t>=65&&t<=90?1:0,P[t]=t>=97&&t<=122?1:0,z[t]=t>=48&&t<=57?1:0;const w=t=>O[t],M=t=>P[t],T=t=>z[t],d=(t,l,c,g,A)=>{if(t.length===0)return[];let f=!1;const C=Object.values(l);for(const r of C)if(r(t[0])){f=!0;break}if(!f&&!c)return[t];const p=[...t],R=[];let s=p[0],o="other";const h=Object.entries(l);for(const r of h){const[n,i]=r;if(i(p[0])){o=n;break}}let e=c&&g?p[0]===p[0].toLocaleUpperCase(g):!1;for(let r=1;r<p.length;r++){const n=p[r];let i="other";for(const E of h){const[L,_]=E;if(_(n)){i=L;break}}const u=c&&g?n===n.toLocaleUpperCase(g):!1;let a=!1;A?a=A(o,i,e,u,n,r,p):(o!==i&&o!=="other"&&i!=="other"&&(a=!0),c&&i!=="other"&&!e&&u&&(a=!0)),a?(R.push(s),s=n):s+=n,o=i,c&&(e=u)}return s&&s.length>0&&R.push(s),R.length>0?R:[t]},Lt=(t,l,c,g)=>{if(c.size===0)return l;for(const A of c)if(t.startsWith(A,l))return g.push(A),l+A.length;return l},D=(t,l=new Set)=>{if(t.length===0)return[];if(t.toUpperCase()===t)return[t];let c=0;const g=[],A=t.length;for(let f=1;f<A;f++){const C=Lt(t,c,l,g);if(C!==c){c=C,f=c-1;continue}const p=t.codePointAt(f-1),R=t.codePointAt(f),s=p&&p<128&&w(p),o=R&&R<128&&w(R),h=p&&p<128&&M(p),e=p&&p<128&&T(p),r=R&&R<128&&T(R);if(h&&o){g.push(t.slice(c,f)),c=f;continue}if(e&&!r||!e&&r){g.push(t.slice(c,f)),c=f;continue}if(r&&!e){let n=!1,i=!1;if(f+1<A){const u=t.codePointAt(f+1);n=u&&u<128&&w(u),i=u&&u<128&&T(u)}if(!i&&n){g.push(t.slice(c,f),t.slice(f,f+1)),c=f+1;continue}}if(f+1<A){const n=t.codePointAt(f+1),i=n&&n<128&&M(n);if(s&&o&&i){const u=t.slice(c,f+1);l.has(u)||(g.push(t.slice(c,f)),c=f)}}}return c<A&&g.push(t.slice(c)),g.filter(f=>f!=="")},J=(t,l,c)=>{if(t.length===0)return[];const g=t===t.toLocaleUpperCase(l);if(l.startsWith("de")){if(!g&&t.replaceAll("ß","SS")===t.toLocaleUpperCase(l))return[t];const s=[...t],o=s.length,h=[];let e=s[0],r=s[0]===s[0].toLocaleUpperCase(l),n=r,i=r?0:-1;for(let u=1;u<o;u++){const a=s[u],E=a===a.toLocaleUpperCase(l);if(E===r)e+=a;else if(E)e&&e.length>0&&(h.push(e),e=a),n=!0,i=u;else{if(n&&u-i>1){const L=s[u-1],_=e.slice(0,-1);_&&_.length>0&&h.push(_),e=L+a}else e+=a;n=!1,i=-1}r=E}return e&&e.length>0&&h.push(e),h}if(l.startsWith("uk")||l.startsWith("ru")||l.startsWith("bg")||l.startsWith("sr")||l.startsWith("mk")||l.startsWith("be")){if(!m.test(t)&&!U.test(t))return[t];const s=[...t],o=s.length,h=[];let e=s[0];const r=s[0];let n;m.test(r)?n=1:U.test(r)?n=2:n=0;let i=r===r.toLocaleUpperCase(l);for(let a=1;a<o;a++){const E=s[a];let L;m.test(E)?L=1:U.test(E)?L=2:L=0;const _=E===E.toLocaleUpperCase(l);n!==L&&(n===1||n===2)&&(L===1||L===2)||L===n&&!i&&_?(h.push(e),e=E):e+=E,n=L,i=_}e&&e.length>0&&h.push(e);const u=[];for(let a=0;a<h.length;a++)a<h.length-1&&h[a].length===1&&U.test(h[a])&&m.test(h[a+1][0])?(u.push(h[a]+h[a+1]),a+=1):u.push(h[a]);return u}if(l.startsWith("el")){if(!b.test(t)&&!U.test(t))return[t];const s=[];j.lastIndex=0;let o;for(;(o=j.exec(t))!==null;)s.push(o[0]);s.length===0&&s.push(t);const h=[];if(s.length===1){const e=s[0];if(!e||!b.test(e[0])||e.length===1)return[e??t]}for(const e of s){if(!e)continue;if(!b.test(e[0])||e.length===1){h.push(e);continue}const r=e.length;let n=e[0],i=e[0]===e[0].toLocaleUpperCase(l);for(let u=1;u<r;u++){const a=e[u],E=a===a.toLocaleUpperCase(l);!i&&E?(h.push(n),n=a):n+=a,i=E}n&&h.push(n)}return h}if(l.startsWith("ja")||l.startsWith("ko")){const s=l.startsWith("ja"),o=s?{hiragana:e=>q.test(e),kanji:e=>B.test(e),katakana:e=>$.test(e),latin:e=>U.test(e)}:{hangul:e=>G.test(e),latin:e=>U.test(e)},h=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(s){const e=d(t,o,!1,l,(n,i)=>n==="hiragana"&&i==="katakana"||n==="katakana"&&i==="hiragana"||n==="hiragana"&&i==="latin"||n==="katakana"&&i==="latin"||n==="kanji"&&i==="latin"||n==="latin"&&(i==="hiragana"||i==="katakana"||i==="kanji")),r=[];for(const n of e){const i=n;i.length===1&&h.has(i)&&r.length>0?r[r.length-1]=r.at(-1)+i:r.push(i)}return r.length>0?r:[t]}return d(t,o,!1,l,(e,r)=>e==="hangul"&&r==="latin"||e==="latin"&&r==="hangul")}if(l.startsWith("sl")){const s=[...t],o=s.length,h=[];let e=s[0],r=s[0]===s[0].toLocaleUpperCase(l);for(let n=1;n<o;n++){const i=s[n],u=i===i.toLocaleUpperCase(l),a=Rt.test(i),E=n<o-1&&s[n+1]===s[n+1].toLocaleUpperCase(l);!r&&u||a&&E?(h.push(e),e=i,a&&E&&(h.push(e),e="")):e+=i,r=u}return e&&e.length>0&&h.push(e),h}if(l.startsWith("zh"))return d(t,{han:s=>B.test(s),latin:s=>U.test(s)},!1,l);if(["ar","fa","he","ur"].includes(l.split("-")[0])){const s=o=>K.test(o)||H.test(o);return d(t,{latin:o=>U.test(o),rtl:o=>s(o)},!1,l)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(l.split("-")[0])){const s=o=>V.test(o)||Z.test(o)||Q.test(o)||X.test(o)||tt.test(o)||et.test(o)||st.test(o)||nt.test(o)||lt.test(o)||rt.test(o)||ot.test(o)||at.test(o)||it.test(o)||ht.test(o)||ct.test(o)||ut.test(o);return d(t,{indic:o=>s(o),latin:o=>U.test(o)},!1,l)}if(["be","bg","ru","sr","uk"].includes(l))return d(t,{cyrillic:s=>m.test(s),latin:s=>U.test(s)},!0,l);if(["ar","fa","he"].includes(l))return d(t,{latin:s=>U.test(s),rtl:s=>K.test(s)||H.test(s)},!1,l);if(l.startsWith("ko"))return d(t,{hangul:s=>G.test(s),latin:s=>U.test(s)},!1,l);if(l.startsWith("uz")){if(!m.test(t)&&!U.test(t))return[t];const s=[...t],o=s.length,h=[];let e=s[0],r=s[0]===s[0].toLocaleUpperCase(l);for(let n=1;n<o;n++){const i=s[n],u=i===i.toLocaleUpperCase(l);if(y.test(i)||y.test(s[n-1])){e+=i;continue}!r&&u?(h.push(e),e=i):e+=i,r=u}return e&&e.length>0&&h.push(e),h}const A=[...t],f=A.length,C=[];let p=A[0],R=A[0]===A[0].toLocaleUpperCase(l);for(const s of c)if(t.startsWith(s)){C.push(s),p=A[s.length],R=p===p.toLocaleUpperCase(l);break}for(let s=1;s<f;s++){const o=A[s],h=o===o.toLocaleUpperCase(l);let e=0;for(const r of c)if(t.startsWith(r,s)){C.push(p,r),e=r.length,p="";const n=r.at(-1);n&&(R=n===n.toLocaleUpperCase(l));break}if(e>0){s+=e-1;continue}!R&&h?(C.push(p),p=o):p+=o,R=h}return p&&C.push(p),C},Ct=(t,l,c)=>{const g=[],A=x.test(t)?t.split(x).filter(Boolean):[t];for(const f of A){const C=f;if(x.test(C))g.push(C);else{W.lastIndex=0;const p=W.test(C)?Et(C).filter(Boolean):[C];for(const R of p)if(W.lastIndex=0,W.test(R))g.push(R);else if(l){const s=l.toLowerCase().split("-")[0];g.push(...J(R,s,c))}else g.push(...D(R,c))}}return g},kt=(t,l={})=>{if(!t||typeof t!="string")return[];const{handleAnsi:c=!1,handleEmoji:g=!1,knownAcronyms:A=[],locale:f,normalize:C=!1,separators:p,stripAnsi:R=!1,stripEmoji:s=!1}=l,o=new Set([...A].toSorted((a,E)=>E.length-a.length));let h=t;R&&(h=pt(h)),s&&(h=v(h));let e;Array.isArray(p)?e=At(p):p instanceof RegExp?e=p:e=F;const r=[];let n=h;const i=e.flags.includes("g")?e:new RegExp(e.source,`${e.flags}g`);for(;n.length>0;){const a=i.exec(n);if(!a){n===".."?r.push(".."):n==="."?r.push("."):n.length>0&&r.push(n);break}const E=a.index,L=a[0],_=L.length,S=n.slice(0,E),Y=n.slice(E+_);if(L.startsWith("../"))r.push(".."),n=n.slice(E+3);else if(L.startsWith("./"))r.push("."),n=n.slice(E+2);else if(E===0&&L==="..")r.push(".."),n=n.slice(2);else if(E===0&&L===".")r.push("."),n=n.slice(1);else{S.length>0&&r.push(S);let I=0;for(;(I=L.indexOf("../",I))!==-1;)r.push(".."),I+=3;for(I=0;(I=L.indexOf("./",I))!==-1;)(I===0||L[I-1]!==".")&&r.push("."),I+=2;let k=Y;for(;k.startsWith("../");)r.push(".."),k=k.slice(3);for(;k.startsWith("./");)r.push("."),k=k.slice(2);if(k===".."){r.push("..");break}else if(k==="."){r.push(".");break}else n=k}i.lastIndex=0}if(r.length===0){const a=h.split(e).filter(Boolean);r.push(...a)}let u=[];for(const a of r)c||g?u.push(...Ct(a,f,o)):f?u.push(...J(a,f,o)):u.push(...D(a,o));return C&&(u=u.map(a=>o.has(a)?a:f&&a===a.toLocaleUpperCase(f)?a[0]+a.slice(1).toLocaleLowerCase(f):a.toUpperCase()===a&&!o.has(a)?a.slice(0,1)+a.slice(1).toLowerCase():a)),u};export{kt as splitByCase};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { b as CaseOptions, T as TitleCase } from "../packem_shared/types.d-
|
|
2
|
-
import "../packem_shared/types.d-
|
|
1
|
+
import { b as CaseOptions, T as TitleCase } from "../packem_shared/types.d-CMNqA5bi.js";
|
|
2
|
+
import "../packem_shared/types.d-LgsTR37y.js";
|
|
3
3
|
/**
|
|
4
|
-
* With Title Case all words are capitalized, except for minor words.
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* titleCase("this-IS-aTitle") // => "This is a Title"
|
|
8
|
-
* titleCase("XMLHttpRequest") // => "XML Http Request"
|
|
9
|
-
* titleCase("AJAXRequest") // => "AJAX Request"
|
|
10
|
-
* titleCase("QueryXML123String") // => "Query XML 123 String"
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
4
|
+
* With Title Case all words are capitalized, except for minor words.
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* titleCase("this-IS-aTitle") // => "This is a Title"
|
|
8
|
+
* titleCase("XMLHttpRequest") // => "XML Http Request"
|
|
9
|
+
* titleCase("AJAXRequest") // => "AJAX Request"
|
|
10
|
+
* titleCase("QueryXML123String") // => "Query XML 123 String"
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
13
|
declare function titleCase<T extends string = string>(value?: T, options?: CaseOptions): TitleCase<T>;
|
|
14
14
|
export { titleCase as default };
|
package/dist/case/title-case.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as c}from"./split-by-case.js";import m from"./upper-first.js";import{
|
|
1
|
+
import{i as e}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as c}from"./split-by-case.js";import m from"./upper-first.js";import{a as p}from"../packem_shared/generate-cache-key-B_0X7MKm.js";import{a as f}from"../packem_shared/normalize-german-eszett-hNMwtGjd.js";const d=new e(1e3);function y(a,o){if(typeof a!="string")return"";const t=o?.cache??!1,s=o?.cacheStore??d;let r;if(t&&(r=p(a,o)),t&&r&&s.has(r))return s.get(r);const i=c(a,{handleAnsi:o?.handleAnsi,handleEmoji:o?.handleEmoji,knownAcronyms:o?.knownAcronyms,locale:o?.locale,normalize:o?.normalize,separators:void 0,stripAnsi:o?.stripAnsi,stripEmoji:o?.stripEmoji}).map(n=>{const l=o?.locale?.startsWith("de")?f(n):n;return m(o?.locale?l.toLocaleLowerCase(o.locale):l.toLowerCase(),{locale:o?.locale})}).join(" ");return t&&r&&s.set(r,i),i}export{y as default};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { b as CaseOptions, j as TrainCase } from "../packem_shared/types.d-
|
|
2
|
-
import "../packem_shared/types.d-
|
|
1
|
+
import { b as CaseOptions, j as TrainCase } from "../packem_shared/types.d-CMNqA5bi.js";
|
|
2
|
+
import "../packem_shared/types.d-LgsTR37y.js";
|
|
3
3
|
/**
|
|
4
|
-
* Converts a string to Train-Case.
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* trainCase("foo bar") // => "Foo-Bar"
|
|
8
|
-
* trainCase("foo-bar") // => "Foo-Bar"
|
|
9
|
-
* trainCase("foo_bar") // => "Foo-Bar"
|
|
10
|
-
* trainCase("XMLHttpRequest") // => "XML-Http-Request"
|
|
11
|
-
* trainCase("AJAXRequest") // => "AJAX-Request"
|
|
12
|
-
* trainCase("QueryXML123String") // => "Query-XML-123-String"
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
4
|
+
* Converts a string to Train-Case.
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* trainCase("foo bar") // => "Foo-Bar"
|
|
8
|
+
* trainCase("foo-bar") // => "Foo-Bar"
|
|
9
|
+
* trainCase("foo_bar") // => "Foo-Bar"
|
|
10
|
+
* trainCase("XMLHttpRequest") // => "XML-Http-Request"
|
|
11
|
+
* trainCase("AJAXRequest") // => "AJAX-Request"
|
|
12
|
+
* trainCase("QueryXML123String") // => "Query-XML-123-String"
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
15
|
declare const trainCase: <T extends string = string>(value?: T, options?: CaseOptions) => TrainCase<T>;
|
|
16
16
|
export { trainCase as default };
|
package/dist/case/train-case.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as
|
|
1
|
+
import{i as m}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as l}from"./split-by-case.js";import e from"./upper-first.js";import{a as p}from"../packem_shared/generate-cache-key-B_0X7MKm.js";import c from"../packem_shared/joinSegments-CaHT-45s.js";const f=new m(1e3),y=(t,o)=>{if(typeof t!="string")return"";const i=o?.cache??!1,n=o?.cacheStore??f;let r;if(i&&(r=p(t,o)),i&&r&&n.has(r))return n.get(r);const s=c(l(t,{handleAnsi:o?.handleAnsi,handleEmoji:o?.handleEmoji,knownAcronyms:o?.knownAcronyms,locale:o?.locale,normalize:o?.normalize,separators:void 0,stripAnsi:o?.stripAnsi,stripEmoji:o?.stripEmoji}).map(a=>e(a,{locale:o?.locale})),"-");return i&&r&&n.set(r,s),s};export{y as default};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { L as LocaleOptions, U as UpperFirst } from "../packem_shared/types.d-
|
|
2
|
-
import "../packem_shared/types.d-
|
|
1
|
+
import { L as LocaleOptions, U as UpperFirst } from "../packem_shared/types.d-CMNqA5bi.js";
|
|
2
|
+
import "../packem_shared/types.d-LgsTR37y.js";
|
|
3
3
|
/**
|
|
4
|
-
* Converts first character to upper case.
|
|
5
|
-
* @param value The string to convert.
|
|
6
|
-
* @param options Options for case conversion.
|
|
7
|
-
* @returns The string with its first character converted to uppercase.
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* upperFirst("hello world!") // => "Hello world!"
|
|
11
|
-
* upperFirst("istanbul", { locale: "tr" }) // => "İstanbul"
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
4
|
+
* Converts first character to upper case.
|
|
5
|
+
* @param value The string to convert.
|
|
6
|
+
* @param options Options for case conversion.
|
|
7
|
+
* @returns The string with its first character converted to uppercase.
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* upperFirst("hello world!") // => "Hello world!"
|
|
11
|
+
* upperFirst("istanbul", { locale: "tr" }) // => "İstanbul"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
14
|
declare const upperFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => UpperFirst<T>;
|
|
15
15
|
export { upperFirst as default };
|
package/dist/closest-string.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
/** Options for {@linkcode closestString}. */
|
|
2
2
|
interface ClosestStringOptions {
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
* Whether the distance should include case.
|
|
5
|
+
* @default {false}
|
|
6
|
+
*/
|
|
7
7
|
caseSensitive?: boolean;
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
* A custom comparison function to use for comparing strings.
|
|
10
|
+
* @param a The first string for comparison.
|
|
11
|
+
* @param b The second string for comparison.
|
|
12
|
+
* @returns The distance between the two strings.
|
|
13
|
+
* @default {levenshteinDistance}
|
|
14
|
+
*/
|
|
15
15
|
compareFn?: (a: string, b: string) => number;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Finds the most similar string from an array of strings.
|
|
19
|
-
*
|
|
20
|
-
* By default, calculates the distance between words using the
|
|
21
|
-
* {@link https://en.wikipedia.org/wiki/Levenshtein_distance | Levenshtein distance}.
|
|
22
|
-
* @example Usage
|
|
23
|
-
* ```ts
|
|
24
|
-
* import { closestString } from "@visulima/string";
|
|
25
|
-
* import assert from "node:assert";
|
|
26
|
-
*
|
|
27
|
-
* const possibleWords = ["length", "size", "blah", "help"];
|
|
28
|
-
* const suggestion = closestString("hep", possibleWords);
|
|
29
|
-
*
|
|
30
|
-
* assert.deepStrictEqual(suggestion, "help");
|
|
31
|
-
* ```
|
|
32
|
-
* @param givenWord The string to measure distance against
|
|
33
|
-
* @param possibleWords The string-array to pick the closest string from
|
|
34
|
-
* @param options The options for the comparison.
|
|
35
|
-
* @returns The closest string from `possibleWords`, or `undefined` if `possibleWords` is empty (though the function throws in this case).
|
|
36
|
-
*/
|
|
18
|
+
* Finds the most similar string from an array of strings.
|
|
19
|
+
*
|
|
20
|
+
* By default, calculates the distance between words using the
|
|
21
|
+
* {@link https://en.wikipedia.org/wiki/Levenshtein_distance | Levenshtein distance}.
|
|
22
|
+
* @example Usage
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { closestString } from "@visulima/string";
|
|
25
|
+
* import assert from "node:assert";
|
|
26
|
+
*
|
|
27
|
+
* const possibleWords = ["length", "size", "blah", "help"];
|
|
28
|
+
* const suggestion = closestString("hep", possibleWords);
|
|
29
|
+
*
|
|
30
|
+
* assert.deepStrictEqual(suggestion, "help");
|
|
31
|
+
* ```
|
|
32
|
+
* @param givenWord The string to measure distance against
|
|
33
|
+
* @param possibleWords The string-array to pick the closest string from
|
|
34
|
+
* @param options The options for the comparison.
|
|
35
|
+
* @returns The closest string from `possibleWords`, or `undefined` if `possibleWords` is empty (though the function throws in this case).
|
|
36
|
+
*/
|
|
37
37
|
declare const closestString: (givenWord: string, possibleWords: ReadonlyArray<string>, options?: ClosestStringOptions) => string | undefined;
|
|
38
38
|
export { ClosestStringOptions, closestString };
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
/** Options for {@linkcode compareSimilarity}. */
|
|
2
2
|
interface CompareSimilarityOptions {
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
* Whether the distance should include case.
|
|
5
|
+
* @default {false}
|
|
6
|
+
*/
|
|
7
7
|
caseSensitive?: boolean;
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
* A custom comparison function to use for comparing strings.
|
|
10
|
+
* @param a The first string for comparison.
|
|
11
|
+
* @param b The second string for comparison.
|
|
12
|
+
* @returns The distance between the two strings.
|
|
13
|
+
* @default {levenshteinDistance}
|
|
14
|
+
*/
|
|
15
15
|
compareFn?: (a: string, b: string) => number;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Takes a string and generates a comparator function to determine which of two
|
|
19
|
-
* strings is more similar to the given one.
|
|
20
|
-
*
|
|
21
|
-
* By default, calculates the distance between words using the
|
|
22
|
-
* {@link https://en.wikipedia.org/wiki/Levenshtein_distance | Levenshtein distance}.
|
|
23
|
-
* @param givenWord The string to measure distance against.
|
|
24
|
-
* @param options Options for the sort.
|
|
25
|
-
* @returns The difference in distance. This will be a negative number if `a`
|
|
26
|
-
* is more similar to `givenWord` than `b`, a positive number if `b` is more
|
|
27
|
-
* similar, or `0` if they are equally similar.
|
|
28
|
-
* @example Usage
|
|
29
|
-
*
|
|
30
|
-
* Most-similar words will be at the start of the array.
|
|
31
|
-
*
|
|
32
|
-
* ```ts
|
|
33
|
-
* import { compareSimilarity } from "@visulima/string";
|
|
34
|
-
* import assert from "node:assert";
|
|
35
|
-
*
|
|
36
|
-
* const words = ["hi", "hello", "help"];
|
|
37
|
-
* const sortedWords = words.toSorted(compareSimilarity("hep"));
|
|
38
|
-
*
|
|
39
|
-
* assert.deepStrictEqual(sortedWords, ["help", "hi", "hello"]);
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
18
|
+
* Takes a string and generates a comparator function to determine which of two
|
|
19
|
+
* strings is more similar to the given one.
|
|
20
|
+
*
|
|
21
|
+
* By default, calculates the distance between words using the
|
|
22
|
+
* {@link https://en.wikipedia.org/wiki/Levenshtein_distance | Levenshtein distance}.
|
|
23
|
+
* @param givenWord The string to measure distance against.
|
|
24
|
+
* @param options Options for the sort.
|
|
25
|
+
* @returns The difference in distance. This will be a negative number if `a`
|
|
26
|
+
* is more similar to `givenWord` than `b`, a positive number if `b` is more
|
|
27
|
+
* similar, or `0` if they are equally similar.
|
|
28
|
+
* @example Usage
|
|
29
|
+
*
|
|
30
|
+
* Most-similar words will be at the start of the array.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { compareSimilarity } from "@visulima/string";
|
|
34
|
+
* import assert from "node:assert";
|
|
35
|
+
*
|
|
36
|
+
* const words = ["hi", "hello", "help"];
|
|
37
|
+
* const sortedWords = words.toSorted(compareSimilarity("hep"));
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(sortedWords, ["help", "hi", "hello"]);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
42
|
declare const compareSimilarity: (givenWord: string, options?: CompareSimilarityOptions) => (a: string, b: string) => number;
|
|
43
43
|
export { CompareSimilarityOptions, compareSimilarity };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get the count of `substring` in `value`.
|
|
3
|
-
* @param value Content to search in. Will be coerced to string.
|
|
4
|
-
* @param substring Substring to look for, typically one character.
|
|
5
|
-
* @returns Count of `substring`s in `value`.
|
|
6
|
-
* @throws {TypeError} When substring is not a string or is empty.
|
|
7
|
-
*/
|
|
2
|
+
* Get the count of `substring` in `value`.
|
|
3
|
+
* @param value Content to search in. Will be coerced to string.
|
|
4
|
+
* @param substring Substring to look for, typically one character.
|
|
5
|
+
* @returns Count of `substring`s in `value`.
|
|
6
|
+
* @throws {TypeError} When substring is not a string or is empty.
|
|
7
|
+
*/
|
|
8
8
|
declare const countOccurrences: (value: unknown, substring: string) => number;
|
|
9
9
|
export { countOccurrences };
|
package/dist/direction.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Detect the direction of text: left-to-right, right-to-left, or neutral.
|
|
3
|
-
* @param value The string to analyze.
|
|
4
|
-
* @returns The text direction: 'rtl' for right-to-left, 'ltr' for left-to-right, or 'neutral' for neutral.
|
|
5
|
-
*/
|
|
2
|
+
* Detect the direction of text: left-to-right, right-to-left, or neutral.
|
|
3
|
+
* @param value The string to analyze.
|
|
4
|
+
* @returns The text direction: 'rtl' for right-to-left, 'ltr' for left-to-right, or 'neutral' for neutral.
|
|
5
|
+
*/
|
|
6
6
|
declare const direction: (value?: string) => "rtl" | "ltr" | "neutral";
|
|
7
7
|
export { direction };
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
|
|
2
2
|
type Options = {
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
Whether to treat an `'ambiguous'` character as wide.
|
|
5
|
+
|
|
6
|
+
@default true
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
11
|
+
|
|
12
|
+
const codePoint = '⛣'.codePointAt(0);
|
|
13
|
+
|
|
14
|
+
console.log(eastAsianWidth(codePoint));
|
|
15
|
+
//=> 1
|
|
16
|
+
|
|
17
|
+
console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
|
|
18
|
+
//=> 2
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
|
|
22
|
+
> - http://www.unicode.org/reports/tr11/
|
|
23
|
+
*/
|
|
18
24
|
readonly ambiguousAsWide?: boolean;
|
|
19
25
|
};
|
|
20
26
|
/**
|
package/dist/excerpt.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { TruncateOptions } from "./truncate.js";
|
|
2
2
|
import "./get-string-truncated-width.js";
|
|
3
3
|
/**
|
|
4
|
-
* Truncates a sentence to be under the given character limit and strips HTML tags from it.
|
|
5
|
-
* This function first removes all HTML tags and decodes HTML entities, then truncates
|
|
6
|
-
* the resulting plain text to the specified character limit using the truncate function.
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* excerpt('<p>Hello <strong>world</strong>!</p>', 10);
|
|
10
|
-
* // => 'Hello worl…'
|
|
11
|
-
*
|
|
12
|
-
* excerpt('<div>This is a <em>long</em> text</div>', 20, { ellipsis: '...' });
|
|
13
|
-
* // => 'This is a long text'
|
|
14
|
-
* ```
|
|
15
|
-
* @param html The HTML string to truncate
|
|
16
|
-
* @param limit Maximum character limit for the truncated string
|
|
17
|
-
* @param options Configuration options for truncation
|
|
18
|
-
* @returns The truncated plain text string with HTML tags removed
|
|
19
|
-
*/
|
|
4
|
+
* Truncates a sentence to be under the given character limit and strips HTML tags from it.
|
|
5
|
+
* This function first removes all HTML tags and decodes HTML entities, then truncates
|
|
6
|
+
* the resulting plain text to the specified character limit using the truncate function.
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* excerpt('<p>Hello <strong>world</strong>!</p>', 10);
|
|
10
|
+
* // => 'Hello worl…'
|
|
11
|
+
*
|
|
12
|
+
* excerpt('<div>This is a <em>long</em> text</div>', 20, { ellipsis: '...' });
|
|
13
|
+
* // => 'This is a long text'
|
|
14
|
+
* ```
|
|
15
|
+
* @param html The HTML string to truncate
|
|
16
|
+
* @param limit Maximum character limit for the truncated string
|
|
17
|
+
* @param options Configuration options for truncation
|
|
18
|
+
* @returns The truncated plain text string with HTML tags removed
|
|
19
|
+
*/
|
|
20
20
|
declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
|
|
21
21
|
/**
|
|
22
|
-
* Options for the excerpt function
|
|
23
|
-
*/
|
|
22
|
+
* Options for the excerpt function
|
|
23
|
+
*/
|
|
24
24
|
type ExcerptOptions = Omit<TruncateOptions, "position">;
|
|
25
25
|
export { ExcerptOptions, excerpt };
|