@visulima/string 3.0.0-alpha.8 → 3.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.
- package/CHANGELOG.md +326 -0
- package/LICENSE.md +119 -0
- package/README.md +88 -4
- package/dist/align-text.d.ts +35 -0
- package/dist/align-text.js +2 -32
- package/dist/case/camel-case.d.ts +17 -3
- package/dist/case/camel-case.js +1 -55
- package/dist/case/capital-case.d.ts +14 -3
- package/dist/case/capital-case.js +1 -47
- package/dist/case/constant-case.d.ts +14 -3
- package/dist/case/constant-case.js +1 -7
- package/dist/case/dot-case.d.ts +14 -3
- package/dist/case/dot-case.js +1 -7
- package/dist/case/flat-case.d.ts +12 -3
- package/dist/case/flat-case.js +1 -7
- package/dist/case/flip-case.d.ts +16 -3
- package/dist/case/flip-case.js +1 -82
- package/dist/case/identify-case.d.ts +15 -3
- package/dist/case/identify-case.js +1 -65
- package/dist/case/index.d.ts +9 -4
- package/dist/case/index.js +1 -20
- package/dist/case/kebab-case.d.ts +25 -3
- package/dist/case/kebab-case.js +1 -55
- package/dist/case/lower-first.d.ts +13 -3
- package/dist/case/lower-first.js +1 -9
- package/dist/case/no-case.d.ts +14 -3
- package/dist/case/no-case.js +1 -7
- package/dist/case/pascal-case.d.ts +17 -3
- package/dist/case/pascal-case.js +1 -48
- package/dist/case/pascal-snake-case.d.ts +14 -3
- package/dist/case/pascal-snake-case.js +1 -28
- package/dist/case/path-case.d.ts +14 -3
- package/dist/case/path-case.js +1 -7
- package/dist/case/sentence-case.d.ts +14 -3
- package/dist/case/sentence-case.js +1 -54
- package/dist/case/snake-case.d.ts +14 -3
- package/dist/case/snake-case.js +1 -7
- package/dist/case/split-by-case.d.ts +29 -3
- package/dist/case/split-by-case.js +1 -747
- package/dist/case/title-case.d.ts +12 -3
- package/dist/case/title-case.js +1 -42
- package/dist/case/train-case.d.ts +14 -3
- package/dist/case/train-case.js +1 -40
- package/dist/case/upper-first.d.ts +13 -3
- package/dist/case/upper-first.js +1 -9
- package/dist/closest-string.d.ts +32 -0
- package/dist/closest-string.js +1 -23
- package/dist/compare-similarity.d.ts +37 -0
- package/dist/compare-similarity.js +1 -12
- package/dist/count-occurrences.d.ts +9 -0
- package/dist/count-occurrences.js +1 -0
- package/dist/direction.d.ts +7 -0
- package/dist/direction.js +1 -0
- package/dist/east-asian-width.d.ts +52 -0
- package/dist/east-asian-width.js +1 -0
- package/dist/excerpt.d.ts +25 -0
- package/dist/excerpt.js +53 -0
- package/dist/get-string-truncated-width.d.ts +151 -0
- package/dist/get-string-truncated-width.js +1 -444
- package/dist/get-string-width.d.ts +58 -0
- package/dist/get-string-width.js +1 -5
- package/dist/indent.d.ts +87 -0
- package/dist/indent.js +1 -0
- package/dist/index.d.ts +12 -15
- package/dist/index.js +1 -39
- package/dist/is-fullwidth-code-point.d.ts +7 -0
- package/dist/is-fullwidth-code-point.js +1 -0
- package/dist/levenshtein.d.ts +25 -0
- package/dist/levenshtein.js +1 -0
- package/dist/native-string-types.d.ts +239 -0
- package/dist/outdent.d.ts +74 -0
- package/dist/outdent.js +1 -117
- package/dist/packem_shared/_isFullWidth-Dqc3MWgl.js +1 -0
- package/dist/packem_shared/closest-C6YDQs4m.js +1 -0
- package/dist/packem_shared/constants-aPzGW29R.js +1 -0
- package/dist/packem_shared/dedent-CPjAYUXh.js +1 -0
- package/dist/packem_shared/eastAsianWidth-DJV8Kqd-.js +1 -0
- package/dist/packem_shared/generate-cache-key-BqU1Cqwm.js +1 -0
- package/dist/packem_shared/indent-cz8WMI0e.js +1 -0
- package/dist/packem_shared/joinSegments-CaHT-45s.js +1 -0
- package/dist/packem_shared/lru-cache-BtMSrYQJ.js +1 -0
- package/dist/packem_shared/normalize-german-eszett-hNMwtGjd.js +1 -0
- package/dist/packem_shared/redent-ByOoJ6fN.js +1 -0
- package/dist/packem_shared/types.d-CmNvyl4l.d.ts +360 -0
- package/dist/packem_shared/types.d-fhe030jX.d.ts +402 -0
- package/dist/replace-string.d.ts +10 -0
- package/dist/replace-string.js +1 -0
- package/dist/slice.d.ts +42 -0
- package/dist/slice.js +1 -413
- package/dist/slugify.d.ts +10 -1
- package/dist/slugify.js +1 -46
- package/dist/test/utils.d.ts +17 -0
- package/dist/test/utils.js +13 -88
- package/dist/test/vitest.d.ts +3 -0
- package/dist/test/vitest.js +1 -5
- package/dist/transliterate.d.ts +10 -0
- package/dist/transliterate.js +5 -0
- package/dist/truncate.d.ts +43 -0
- package/dist/truncate.js +1 -114
- package/dist/utilities.d.ts +28 -2
- package/dist/utilities.js +1 -54
- package/dist/word-similarity-sort.d.ts +34 -0
- package/dist/word-similarity-sort.js +1 -22
- package/dist/word-wrap.d.ts +44 -0
- package/dist/word-wrap.js +8 -637
- package/package.json +70 -39
- package/dist/packem_shared/LRUCache-3r3SovvR.js +0 -46
- package/dist/packem_shared/closest-IHuSvnSn.js +0 -139
- package/dist/packem_shared/closestN-Cvsw0Fue.js +0 -24
- package/dist/packem_shared/constants-D5qaproB.js +0 -95
- package/dist/packem_shared/countOccurrences-CS9XprQN.js +0 -22
- package/dist/packem_shared/direction-BVhR8MOQ.js +0 -10
- package/dist/packem_shared/excerpt-COsVNttN.js +0 -1502
- package/dist/packem_shared/generate-cache-key-DdayDfjV.js +0 -6
- package/dist/packem_shared/joinSegments-BStLas0c.js +0 -44
- package/dist/packem_shared/lru-cache.d-BsP6kbVJ.d.ts +0 -13
- package/dist/packem_shared/normalize-german-eszett-DEB8-ZPT.js +0 -7
- package/dist/packem_shared/replaceString-BVlxk27d.js +0 -190
- package/dist/packem_shared/transliterate-DGlx-woj.js +0 -47756
- package/dist/packem_shared/types.d-BVNv675q.d.ts +0 -61
- package/dist/packem_shared/types.d-DfgbcNKh.d.ts +0 -57
package/dist/index.js
CHANGED
|
@@ -1,39 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as camelCase } from './case/camel-case.js';
|
|
3
|
-
export { default as capitalCase } from './case/capital-case.js';
|
|
4
|
-
export { default as constantCase } from './case/constant-case.js';
|
|
5
|
-
export { default as dotCase } from './case/dot-case.js';
|
|
6
|
-
export { default as flatCase } from './case/flat-case.js';
|
|
7
|
-
export { flipCase } from './case/flip-case.js';
|
|
8
|
-
export { default as identifyCase } from './case/identify-case.js';
|
|
9
|
-
export { kebabCase } from './case/kebab-case.js';
|
|
10
|
-
export { default as lowerFirst } from './case/lower-first.js';
|
|
11
|
-
export { default as noCase } from './case/no-case.js';
|
|
12
|
-
export { default as pascalCase } from './case/pascal-case.js';
|
|
13
|
-
export { default as pascalSnakeCase } from './case/pascal-snake-case.js';
|
|
14
|
-
export { default as pathCase } from './case/path-case.js';
|
|
15
|
-
export { default as sentenceCase } from './case/sentence-case.js';
|
|
16
|
-
export { default as snakeCase } from './case/snake-case.js';
|
|
17
|
-
export { splitByCase } from './case/split-by-case.js';
|
|
18
|
-
export { default as titleCase } from './case/title-case.js';
|
|
19
|
-
export { default as trainCase } from './case/train-case.js';
|
|
20
|
-
export { default as upperFirst } from './case/upper-first.js';
|
|
21
|
-
export { default as joinSegments } from './packem_shared/joinSegments-BStLas0c.js';
|
|
22
|
-
export { closestString } from './closest-string.js';
|
|
23
|
-
export { compareSimilarity } from './compare-similarity.js';
|
|
24
|
-
export { countOccurrences } from './packem_shared/countOccurrences-CS9XprQN.js';
|
|
25
|
-
export { direction } from './packem_shared/direction-BVhR8MOQ.js';
|
|
26
|
-
export { excerpt } from './packem_shared/excerpt-COsVNttN.js';
|
|
27
|
-
export { getStringTruncatedWidth } from './get-string-truncated-width.js';
|
|
28
|
-
export { getStringWidth } from './get-string-width.js';
|
|
29
|
-
export { closestN } from './packem_shared/closestN-Cvsw0Fue.js';
|
|
30
|
-
export { outdent } from './outdent.js';
|
|
31
|
-
export { default as replaceString } from './packem_shared/replaceString-BVlxk27d.js';
|
|
32
|
-
export { slice } from './slice.js';
|
|
33
|
-
export { default as slugify } from './slugify.js';
|
|
34
|
-
export { default as transliterate } from './packem_shared/transliterate-DGlx-woj.js';
|
|
35
|
-
export { truncate } from './truncate.js';
|
|
36
|
-
export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from './utilities.js';
|
|
37
|
-
export { wordSimilaritySort } from './word-similarity-sort.js';
|
|
38
|
-
export { WrapMode, wordWrap } from './word-wrap.js';
|
|
39
|
-
export { closest, distance } from './packem_shared/closest-IHuSvnSn.js';
|
|
1
|
+
import{alignText as r}from"./align-text.js";import{default as a}from"./case/camel-case.js";import{default as s}from"./case/capital-case.js";import{default as m}from"./case/constant-case.js";import{default as i}from"./case/dot-case.js";import{default as d}from"./case/flat-case.js";import{flipCase as u}from"./case/flip-case.js";import{default as C}from"./case/identify-case.js";import{kebabCase as S}from"./case/kebab-case.js";import{default as y}from"./case/lower-first.js";import{default as w}from"./case/no-case.js";import{default as F}from"./case/pascal-case.js";import{default as T}from"./case/pascal-snake-case.js";import{default as A}from"./case/path-case.js";import{default as R}from"./case/sentence-case.js";import{default as B}from"./case/snake-case.js";import{splitByCase as I}from"./case/split-by-case.js";import{default as N}from"./case/title-case.js";import{default as v}from"./case/train-case.js";import{default as D}from"./case/upper-first.js";import{default as H}from"./packem_shared/joinSegments-CaHT-45s.js";import{closestString as K}from"./closest-string.js";import{compareSimilarity as Q}from"./compare-similarity.js";import{countOccurrences as V}from"./count-occurrences.js";import{direction as Y}from"./direction.js";import{excerpt as _}from"./excerpt.js";import{getStringTruncatedWidth as ee}from"./get-string-truncated-width.js";import{getStringWidth as re}from"./get-string-width.js";import{default as ae}from"./is-fullwidth-code-point.js";import{closestN as se,similarity as pe}from"./levenshtein.js";import{outdent as xe}from"./outdent.js";import{default as le}from"./replace-string.js";import{slice as ne}from"./slice.js";import{default as ce}from"./slugify.js";import{default as ge}from"./transliterate.js";import{truncate as he}from"./truncate.js";import{escapeRegExp as We,findStringOccurrences as we,hasChinese as ke,hasPunctuationOrSpace as Fe,inRange as Oe}from"./utilities.js";import{wordSimilaritySort as be}from"./word-similarity-sort.js";import{WrapMode as Pe,wordWrap as Re}from"./word-wrap.js";import{default as Be}from"./packem_shared/indent-cz8WMI0e.js";import{default as Ie}from"./packem_shared/redent-ByOoJ6fN.js";import{dedent as Ne,default as qe}from"./packem_shared/dedent-CPjAYUXh.js";import{closest as ze,distance as De}from"./packem_shared/closest-C6YDQs4m.js";import{eastAsianWidth as He,eastAsianWidthType as Je}from"./packem_shared/eastAsianWidth-DJV8Kqd-.js";export{Pe as WrapMode,r as alignText,a as camelCase,s as capitalCase,ze as closest,se as closestN,K as closestString,Q as compareSimilarity,m as constantCase,V as countOccurrences,Ne as dedent,Y as direction,De as distance,i as dotCase,He as eastAsianWidth,Je as eastAsianWidthType,We as escapeRegExp,_ as excerpt,we as findStringOccurrences,d as flatCase,u as flipCase,ee as getStringTruncatedWidth,re as getStringWidth,ke as hasChinese,Fe as hasPunctuationOrSpace,C as identifyCase,Oe as inRange,Be as indent,ae as isFullwidthCodePoint,H as joinSegments,S as kebabCase,y as lowerFirst,w as noCase,xe as outdent,F as pascalCase,T as pascalSnakeCase,A as pathCase,Ie as redent,le as replaceString,R as sentenceCase,pe as similarity,ne as slice,ce as slugify,B as snakeCase,I as splitByCase,qe as stripIndent,N as titleCase,v as trainCase,ge as transliterate,he as truncate,D as upperFirst,be as wordSimilaritySort,Re as wordWrap};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the given code point is a fullwidth character.
|
|
3
|
+
* @param codePoint The code point to check.
|
|
4
|
+
* @returns Whether the code point is a fullwidth character.
|
|
5
|
+
*/
|
|
6
|
+
declare const isFullwidthCodePoint: (codePoint: number) => boolean;
|
|
7
|
+
export { isFullwidthCodePoint as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isFullWidth as i,isWide as t}from"./packem_shared/_isFullWidth-Dqc3MWgl.js";const r=s=>Number.isInteger(s)?i(s)||t(s):!1;export{r as default};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const distance: (a: string, b: string) => number;
|
|
2
|
+
declare const closest: (str: string, arr: readonly string[]) => string;
|
|
3
|
+
declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | undefined)[];
|
|
4
|
+
/**
|
|
5
|
+
* Computes a normalized similarity score between two strings in the range `[0, 1]`,
|
|
6
|
+
* where `1` means the strings are identical and `0` means maximally different.
|
|
7
|
+
*
|
|
8
|
+
* The score is derived from the Levenshtein edit distance, normalized by the
|
|
9
|
+
* length of the longer string: `1 - distance(a, b) / max(a.length, b.length)`.
|
|
10
|
+
* Two empty strings are considered identical (`1`).
|
|
11
|
+
*
|
|
12
|
+
* This is convenient for threshold-based "did you mean?" UX, complementing the
|
|
13
|
+
* raw {@link distance} and the sort-based helpers.
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* similarity("kitten", "sitting"); // => ~0.571
|
|
17
|
+
* similarity("foo", "foo"); // => 1
|
|
18
|
+
* similarity("", ""); // => 1
|
|
19
|
+
* ```
|
|
20
|
+
* @param a The first string.
|
|
21
|
+
* @param b The second string.
|
|
22
|
+
* @returns A similarity score between 0 and 1 (inclusive).
|
|
23
|
+
*/
|
|
24
|
+
declare const similarity: (a: string, b: string) => number;
|
|
25
|
+
export { closest, closestN, distance, similarity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{distance as c}from"./packem_shared/closest-C6YDQs4m.js";import{closest as y}from"./packem_shared/closest-C6YDQs4m.js";const u=(r,s,o)=>{const e=Array.from({length:o}).fill(1/0),n=Array.from({length:o}).fill(void 0);for(const a of s){const f=a;let l=c(r,f),i=f;for(let t=0;t<o;t+=1)if(l<e[t]){const m=e[t],h=n[t];e[t]=l,n[t]=i,l=m,i=h}}return n},d=(r,s)=>{if(r===s)return 1;const o=Math.max(r.length,s.length);return o===0?1:1-c(r,s)/o};export{y as closest,u as closestN,c as distance,d as similarity};
|
|
@@ -1,38 +1,277 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Creates a tuple type of specified length filled with a given type.
|
|
4
|
+
* @template L - The desired length of the tuple
|
|
5
|
+
* @template T - The type to fill the tuple with (defaults to unknown)
|
|
6
|
+
* @template Result - Internal accumulator for recursive type building
|
|
7
|
+
* @returns A tuple type of length L filled with type T
|
|
8
|
+
*/
|
|
1
9
|
type TupleOf<L extends number, T = unknown, Result extends any[] = []> = Result["length"] extends L ? Result : TupleOf<L, T, [...Result, T]>;
|
|
10
|
+
/**
|
|
11
|
+
* Internal type for implementing string slicing with both start and end indices.
|
|
12
|
+
* Handles edge cases and type safety for string literal types.
|
|
13
|
+
* @template T - The input string type
|
|
14
|
+
* @template StartIndex - The starting index for the slice
|
|
15
|
+
* @template EndIndex - The ending index for the slice
|
|
16
|
+
* @template Result - Internal accumulator for building the result string
|
|
17
|
+
*/
|
|
2
18
|
type InternalSliceType<T extends string, StartIndex extends number, EndIndex extends number, Result extends string = ""> = IsNumberLiteral<EndIndex | StartIndex> extends true ? T extends `${infer Head}${infer Rest}` ? IsStringLiteral<Head> extends true ? StartIndex extends 0 ? EndIndex extends 0 ? Result : InternalSliceType<Rest, 0, Math.Subtract<Math.GetPositiveIndex<T, EndIndex>, 1>, `${Result}${Head}`> : InternalSliceType<Rest, Math.Subtract<Math.GetPositiveIndex<T, StartIndex>, 1>, Math.Subtract<Math.GetPositiveIndex<T, EndIndex>, 1>, Result> : EndIndex | StartIndex extends 0 ? Result : string : IsStringLiteral<T> extends true ? Result : EndIndex | StartIndex extends 0 ? Result : string : string;
|
|
19
|
+
/**
|
|
20
|
+
* Internal type for implementing string slicing with only a start index.
|
|
21
|
+
* Provides type-safe string slicing functionality for string literal types.
|
|
22
|
+
* @template T - The input string type
|
|
23
|
+
* @template StartIndex - The starting index for the slice
|
|
24
|
+
* @template Result - Internal accumulator for building the result string
|
|
25
|
+
*/
|
|
3
26
|
type SliceStartType<T extends string, StartIndex extends number, Result extends string = ""> = IsNumberLiteral<StartIndex> extends true ? T extends `${infer Head}${infer Rest}` ? IsStringLiteral<Head> extends true ? StartIndex extends 0 ? T : SliceStartType<Rest, Math.Subtract<Math.GetPositiveIndex<T, StartIndex>, 1>, Result> : string : IsStringLiteral<T> extends true ? Result : StartIndex extends 0 ? Result : string : string;
|
|
4
27
|
type InternalEndsWithType<T extends string, S extends string, P extends number> = All<[IsStringLiteral<S>, IsNumberLiteral<P>]> extends true ? Math.IsNegative<P> extends false ? P extends Length<T> ? IsStringLiteral<T> extends true ? S extends Slice<T, Math.Subtract<Length<T>, Length<S>>, Length<T>> ? true : false : EndsWithNoPositionType<Slice<T, 0, P>, S> : EndsWithNoPositionType<Slice<T, 0, P>, S> : false : boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Internal type for implementing EndsWith functionality without a position parameter.
|
|
30
|
+
* Uses string reversal to check if a string ends with another string.
|
|
31
|
+
* @template T - The string to check
|
|
32
|
+
* @template S - The suffix to check for
|
|
33
|
+
*/
|
|
5
34
|
type EndsWithNoPositionType<T extends string, S extends string> = StartsWith<Reverse<T>, Reverse<S>>;
|
|
35
|
+
/**
|
|
36
|
+
* Namespace containing type-level mathematical operations.
|
|
37
|
+
* These utilities provide type-safe arithmetic and number manipulation.
|
|
38
|
+
*/
|
|
6
39
|
declare namespace Math {
|
|
7
40
|
type Subtract<A extends number, B extends number> = number extends A | B ? number : TupleOf<A> extends [...infer U, ...TupleOf<B>] ? U["length"] : 0;
|
|
8
41
|
type IsNegative<T extends number> = number extends T ? boolean : `${T}` extends `-${number}` ? true : false;
|
|
9
42
|
type Abs<T extends number> = `${T}` extends `-${infer U extends number}` ? U : T;
|
|
10
43
|
type GetPositiveIndex<T extends string, I extends number> = IsNegative<I> extends false ? I : Subtract<Length<T>, Abs<I>>;
|
|
11
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Type predicate that determines if a number type is a literal type rather than the general 'number' type.
|
|
47
|
+
* For example: IsNumberLiteral<42> is true, but IsNumberLiteral<number> is false.
|
|
48
|
+
* @template T - The number type to check
|
|
49
|
+
* @returns true if T is a number literal type, false otherwise
|
|
50
|
+
*/
|
|
12
51
|
type IsNumberLiteral<T extends number> = [T] extends [number] ? ([number] extends [T] ? false : true) : false;
|
|
13
52
|
type IsBooleanLiteral<T extends boolean> = [T] extends [boolean] ? ([boolean] extends [T] ? false : true) : false;
|
|
53
|
+
/**
|
|
54
|
+
* Type-level string reversal utility.
|
|
55
|
+
* Recursively builds the reversed string using template literal types.
|
|
56
|
+
* @template T - The string type to reverse
|
|
57
|
+
* @template Accumulator - Internal accumulator for building the reversed string
|
|
58
|
+
* @returns A type representing the reversed string
|
|
59
|
+
* @example
|
|
60
|
+
* type ReversedHello = Reverse<'hello'> // type ReversedHello = 'olleh'
|
|
61
|
+
*/
|
|
14
62
|
type Reverse<T extends string, Accumulator extends string = ""> = T extends `${infer Head}${infer Tail}` ? Reverse<Tail, `${Head}${Accumulator}`> : Accumulator extends "" ? T : `${T}${Accumulator}`;
|
|
63
|
+
/**
|
|
64
|
+
* Type predicate that checks if all elements in a boolean array type are the literal 'true'.
|
|
65
|
+
* Distinguishes between literal true/false and the general boolean type.
|
|
66
|
+
* @template T - Array of boolean types to check
|
|
67
|
+
* @returns true if all elements are the literal true, false otherwise
|
|
68
|
+
* @example
|
|
69
|
+
* type AllTrue = All<[true, true]> // type AllTrue = true
|
|
70
|
+
* type NotAllTrue = All<[true, false]> // type NotAllTrue = false
|
|
71
|
+
*/
|
|
15
72
|
type All<BoolArray extends boolean[]> = IsBooleanLiteral<BoolArray[number]> extends true ? BoolArray extends [infer Head extends boolean, ...infer Rest extends boolean[]] ? Head extends true ? All<Rest> : false : true : false;
|
|
73
|
+
/**
|
|
74
|
+
* Type predicate that determines if a string type is a literal type rather than the general 'string' type.
|
|
75
|
+
* @template T - The string type to check
|
|
76
|
+
* @returns true if T is a string literal type, false if it's the general string type
|
|
77
|
+
* @example
|
|
78
|
+
* type IsLiteral = IsStringLiteral<'hello'> // type IsLiteral = true
|
|
79
|
+
* type NotLiteral = IsStringLiteral<string> // type NotLiteral = false
|
|
80
|
+
*/
|
|
16
81
|
type IsStringLiteral<T extends string> = [T] extends [string] ? [string] extends [T] ? false : Uppercase<T> extends Uppercase<Lowercase<T>> ? Lowercase<T> extends Lowercase<Uppercase<T>> ? true : false : false : false;
|
|
17
82
|
type IsStringLiteralArray<StringArray extends ReadonlyArray<string>> = IsStringLiteral<StringArray[number]> extends true ? true : false;
|
|
83
|
+
/**
|
|
84
|
+
* Type-safe utility to get the character at a specific index in a string literal type.
|
|
85
|
+
* @template T - The string type to extract a character from
|
|
86
|
+
* @template Index - The numeric index of the desired character
|
|
87
|
+
* @returns The character type at the specified index, or never if the index is invalid
|
|
88
|
+
* @example
|
|
89
|
+
* type FirstChar = CharAt<'hello', 0> // type FirstChar = 'h'
|
|
90
|
+
*/
|
|
18
91
|
type CharAt<T extends string, Index extends number> = All<[IsStringLiteral<T>, IsNumberLiteral<Index>]> extends true ? Split<T>[Index] : string;
|
|
92
|
+
/**
|
|
93
|
+
* Type-level string concatenation for tuples of string literals.
|
|
94
|
+
* Joins all strings in the tuple into a single string type.
|
|
95
|
+
* @template T - Tuple of string types to concatenate
|
|
96
|
+
* @returns A single string type representing the concatenated result
|
|
97
|
+
* @example
|
|
98
|
+
* type Combined = Concat<['hello', ' ', 'world']> // type Combined = 'hello world'
|
|
99
|
+
*/
|
|
19
100
|
type Concat<T extends string[]> = Join<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Type-level implementation of string.endsWith() functionality.
|
|
103
|
+
* Checks if a string type ends with another string type at a given position.
|
|
104
|
+
* @template T - The string type to check
|
|
105
|
+
* @template S - The suffix to check for
|
|
106
|
+
* @template P - Optional position at which to end the search
|
|
107
|
+
* @returns A boolean type indicating if T ends with S at position P
|
|
108
|
+
* @example
|
|
109
|
+
* type EndsWithWorld = EndsWith<'hello world', 'world'> // type EndsWithWorld = true
|
|
110
|
+
* type DoesNotEnd = EndsWith<'hello world', 'hello'> // type DoesNotEnd = false
|
|
111
|
+
*/
|
|
20
112
|
type EndsWith<T extends string, S extends string, P extends number | undefined = undefined> = P extends number ? InternalEndsWithType<T, S, P> : EndsWithNoPositionType<T, S>;
|
|
113
|
+
/**
|
|
114
|
+
* Type-level implementation of string.includes() functionality.
|
|
115
|
+
* Determines if one string type contains another string type starting at an optional position.
|
|
116
|
+
* @template T - The string type to search within
|
|
117
|
+
* @template S - The string type to search for
|
|
118
|
+
* @template P - Optional position to start the search from
|
|
119
|
+
* @returns A boolean type indicating if S is found within T starting at P
|
|
120
|
+
* @example
|
|
121
|
+
* type HasWorld = Includes<'hello world', 'world'> // type HasWorld = true
|
|
122
|
+
* type NoWorld = Includes<'hello', 'world'> // type NoWorld = false
|
|
123
|
+
*/
|
|
21
124
|
type Includes<T extends string, S extends string, P extends number = 0> = string extends S | T ? boolean : Math.IsNegative<P> extends false ? P extends 0 ? T extends `${string}${S}${string}` ? true : false : Includes<Slice<T, P>, S> : Includes<T, S>;
|
|
125
|
+
/**
|
|
126
|
+
* Type-level implementation of Array.join() functionality for string tuples.
|
|
127
|
+
* Combines string literal types in a tuple using a delimiter.
|
|
128
|
+
* @template T - Tuple of string types to join
|
|
129
|
+
* @template Delimiter - The delimiter to insert between elements
|
|
130
|
+
* @returns A string type representing the joined result
|
|
131
|
+
* @example
|
|
132
|
+
* type Joined = Join<['a', 'b', 'c'], '.'> // type Joined = 'a.b.c'
|
|
133
|
+
*/
|
|
22
134
|
type Join<T extends ReadonlyArray<string>, Delimiter extends string = ""> = All<[IsStringLiteralArray<T>, IsStringLiteral<Delimiter>]> extends true ? T extends readonly [infer First extends string, ...infer Rest extends string[]] ? Rest extends [] ? First : `${First}${Delimiter}${Join<Rest, Delimiter>}` : "" : string;
|
|
135
|
+
/**
|
|
136
|
+
* Type-level utility to compute the length of a string literal type.
|
|
137
|
+
* @template T - The string type to measure
|
|
138
|
+
* @returns A number literal type representing the string's length
|
|
139
|
+
* @example
|
|
140
|
+
* type Len = Length<'hello'> // type Len = 5
|
|
141
|
+
*/
|
|
23
142
|
type Length<T extends string> = IsStringLiteral<T> extends true ? Split<T>["length"] : number;
|
|
143
|
+
/**
|
|
144
|
+
* Type-level implementation of string.padEnd() functionality.
|
|
145
|
+
* Adds padding to the end of a string type until it reaches a specified length.
|
|
146
|
+
* @template T - The string type to pad
|
|
147
|
+
* @template Times - Target total length of the padded string
|
|
148
|
+
* @template Pad - The string to use as padding (defaults to space)
|
|
149
|
+
* @returns A string type with the padding added to the end
|
|
150
|
+
* @example
|
|
151
|
+
* type Padded = PadEnd<'hello', 7, '_'> // type Padded = 'hello__'
|
|
152
|
+
*/
|
|
24
153
|
type PadEnd<T extends string, Times extends number = 0, Pad extends string = " "> = All<[IsStringLiteral<Pad | T>, IsNumberLiteral<Times>]> extends true ? Math.IsNegative<Times> extends false ? Math.Subtract<Times, Length<T>> extends infer Missing extends number ? `${T}${Slice<Repeat<Pad, Missing>, 0, Missing>}` : never : T : string;
|
|
154
|
+
/**
|
|
155
|
+
* Type-level implementation of string.padStart() functionality.
|
|
156
|
+
* Adds padding to the beginning of a string type until it reaches a specified length.
|
|
157
|
+
* @template T - The string type to pad
|
|
158
|
+
* @template Times - Target total length of the padded string
|
|
159
|
+
* @template Pad - The string to use as padding (defaults to space)
|
|
160
|
+
* @returns A string type with the padding added to the start
|
|
161
|
+
* @example
|
|
162
|
+
* type Padded = PadStart<'hello', 7, '_'> // type Padded = '__hello'
|
|
163
|
+
*/
|
|
25
164
|
type PadStart<T extends string, Times extends number = 0, Pad extends string = " "> = All<[IsStringLiteral<Pad | T>, IsNumberLiteral<Times>]> extends true ? Math.IsNegative<Times> extends false ? Math.Subtract<Times, Length<T>> extends infer Missing extends number ? `${Slice<Repeat<Pad, Missing>, 0, Missing>}${T}` : never : T : string;
|
|
165
|
+
/**
|
|
166
|
+
* Type-level implementation of string.repeat() functionality.
|
|
167
|
+
* Creates a new string type by repeating the input string a specified number of times.
|
|
168
|
+
* @template T - The string type to repeat
|
|
169
|
+
* @template Times - The number of times to repeat the string
|
|
170
|
+
* @returns A string type containing T repeated Times times
|
|
171
|
+
* @example
|
|
172
|
+
* type Repeated = Repeat<'abc', 2> // type Repeated = 'abcabc'
|
|
173
|
+
*/
|
|
26
174
|
type Repeat<T extends string, Times extends number = 0> = All<[IsStringLiteral<T>, IsNumberLiteral<Times>]> extends true ? Times extends 0 ? "" : Math.IsNegative<Times> extends false ? Join<TupleOf<Times, T>> : never : string;
|
|
175
|
+
/**
|
|
176
|
+
* Type-level implementation of string.replaceAll() functionality.
|
|
177
|
+
* Replaces all occurrences of a substring with another string.
|
|
178
|
+
* @template Sentence - The string type to perform replacements on
|
|
179
|
+
* @template Lookup - The string or RegExp pattern to search for. When a RegExp is used, the result type widens to string.
|
|
180
|
+
* @template Replacement - The string type to replace matches with
|
|
181
|
+
* @returns A string type with all occurrences of Lookup replaced with Replacement. When Lookup is a RegExp, returns string.
|
|
182
|
+
* @example
|
|
183
|
+
* type Replaced = ReplaceAll<'hello hello', 'hello', 'hi'> // type Replaced = 'hi hi'
|
|
184
|
+
*/
|
|
27
185
|
type ReplaceAll<Sentence extends string, Lookup extends RegExp | string, Replacement extends string = ""> = Lookup extends string ? IsStringLiteral<Lookup | Replacement | Sentence> extends true ? Sentence extends `${infer Rest}${Lookup}${infer Rest2}` ? `${Rest}${Replacement}${ReplaceAll<Rest2, Lookup, Replacement>}` : Sentence : string : string;
|
|
186
|
+
/**
|
|
187
|
+
* Type-level implementation of string.replace() functionality.
|
|
188
|
+
* Replaces the first occurrence of a substring with another string.
|
|
189
|
+
* @template Sentence - The string type to perform replacement on
|
|
190
|
+
* @template Lookup - The string or RegExp pattern to search for. When a RegExp is used, the result type widens to string.
|
|
191
|
+
* @template Replacement - The string type to replace the match with
|
|
192
|
+
* @returns A string type with the first occurrence of Lookup replaced with Replacement. When Lookup is a RegExp, returns string.
|
|
193
|
+
* @example
|
|
194
|
+
* type Replaced = Replace<'hello hello', 'hello', 'hi'> // type Replaced = 'hi hello'
|
|
195
|
+
*/
|
|
28
196
|
type Replace<Sentence extends string, Lookup extends RegExp | string, Replacement extends string = ""> = Lookup extends string ? IsStringLiteral<Lookup | Replacement | Sentence> extends true ? Sentence extends `${infer Rest}${Lookup}${infer Rest2}` ? `${Rest}${Replacement}${Rest2}` : Sentence : string : string;
|
|
197
|
+
/**
|
|
198
|
+
* Type-level implementation of string.slice() functionality.
|
|
199
|
+
* Extracts a portion of a string type between start and end indices.
|
|
200
|
+
* @template T - The string type to slice
|
|
201
|
+
* @template StartIndex - The starting index of the slice
|
|
202
|
+
* @template EndIndex - The ending index of the slice (optional)
|
|
203
|
+
* @returns A string type containing the characters between the indices
|
|
204
|
+
* @example
|
|
205
|
+
* type Sliced = Slice<'hello world', 0, 5> // type Sliced = 'hello'
|
|
206
|
+
* type ToEnd = Slice<'hello world', 6> // type ToEnd = 'world'
|
|
207
|
+
*/
|
|
29
208
|
type Slice<T extends string, StartIndex extends number = 0, EndIndex extends number | undefined = undefined> = EndIndex extends number ? InternalSliceType<T, StartIndex, EndIndex> : SliceStartType<T, StartIndex>;
|
|
209
|
+
/**
|
|
210
|
+
* Type-level implementation of string.split() functionality.
|
|
211
|
+
* Splits a string type into a tuple of string types based on a delimiter.
|
|
212
|
+
* @template T - The string type to split
|
|
213
|
+
* @template Delimiter - The string type to use as a separator
|
|
214
|
+
* @returns A tuple type containing the split string parts
|
|
215
|
+
* @example
|
|
216
|
+
* type Parts = Split<'a,b,c', ','> // type Parts = ['a', 'b', 'c']
|
|
217
|
+
*/
|
|
30
218
|
type Split<T extends string, Delimiter extends string = ""> = IsStringLiteral<Delimiter | T> extends true ? T extends `${infer First}${Delimiter}${infer Rest}` ? [First, ...Split<Rest, Delimiter>] : T extends "" ? [] : [T] : string[];
|
|
219
|
+
/**
|
|
220
|
+
* Type-level implementation of string.startsWith() functionality.
|
|
221
|
+
* Checks if a string type begins with another string type at a given position.
|
|
222
|
+
* @template T - The string type to check
|
|
223
|
+
* @template S - The prefix to check for
|
|
224
|
+
* @template P - Optional position at which to start the search
|
|
225
|
+
* @returns A boolean type indicating if T starts with S at position P
|
|
226
|
+
* @example
|
|
227
|
+
* type StartsWithHello = StartsWith<'hello world', 'hello'> // type StartsWithHello = true
|
|
228
|
+
* type DoesNotStart = StartsWith<'hello world', 'world'> // type DoesNotStart = false
|
|
229
|
+
*/
|
|
31
230
|
type StartsWith<T extends string, S extends string, P extends number = 0> = All<[IsStringLiteral<S>, IsNumberLiteral<P>]> extends true ? Math.IsNegative<P> extends false ? P extends 0 ? S extends `${infer SHead}${infer SRest}` ? T extends `${infer THead}${infer TRest}` ? IsStringLiteral<SHead | THead> extends true ? THead extends SHead ? StartsWith<TRest, SRest> : false : boolean : IsStringLiteral<T> extends true ? false : boolean : true : StartsWith<Slice<T, P>, S> : StartsWith<T, S> : boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Type-level implementation of string.trimEnd() functionality.
|
|
233
|
+
* Removes whitespace characters from the end of a string type.
|
|
234
|
+
* @template T - The string type to trim
|
|
235
|
+
* @returns A string type with trailing whitespace removed
|
|
236
|
+
* @example
|
|
237
|
+
* type Trimmed = TrimEnd<'hello '> // type Trimmed = 'hello'
|
|
238
|
+
*/
|
|
32
239
|
type TrimEnd<T extends string> = T extends `${infer Rest} ` ? TrimEnd<Rest> : T;
|
|
240
|
+
/**
|
|
241
|
+
* Type-level implementation of string.trimStart() functionality.
|
|
242
|
+
* Removes whitespace characters from the beginning of a string type.
|
|
243
|
+
* @template T - The string type to trim
|
|
244
|
+
* @returns A string type with leading whitespace removed
|
|
245
|
+
* @example
|
|
246
|
+
* type Trimmed = TrimStart<' hello'> // type Trimmed = 'hello'
|
|
247
|
+
*/
|
|
33
248
|
type TrimStart<T extends string> = T extends ` ${infer Rest}` ? TrimStart<Rest> : T;
|
|
249
|
+
/**
|
|
250
|
+
* Type-level implementation of string.trim() functionality.
|
|
251
|
+
* Removes whitespace characters from both ends of a string type.
|
|
252
|
+
* @template T - The string type to trim
|
|
253
|
+
* @returns A string type with both leading and trailing whitespace removed
|
|
254
|
+
* @example
|
|
255
|
+
* type Trimmed = Trim<' hello '> // type Trimmed = 'hello'
|
|
256
|
+
*/
|
|
34
257
|
type Trim<T extends string> = TrimEnd<TrimStart<T>>;
|
|
258
|
+
/**
|
|
259
|
+
* Type-level implementation of string.toLowerCase() functionality.
|
|
260
|
+
* Converts all alphabetic characters in a string type to lowercase.
|
|
261
|
+
* @template T - The string type to convert
|
|
262
|
+
* @returns A string type with all characters converted to lowercase
|
|
263
|
+
* @example
|
|
264
|
+
* type Lower = ToLowerCase<'HELLO'> // type Lower = 'hello'
|
|
265
|
+
*/
|
|
35
266
|
type ToLowerCase<T extends string> = IsStringLiteral<T> extends true ? Lowercase<T> : string;
|
|
267
|
+
/**
|
|
268
|
+
* Type-level implementation of string.toUpperCase() functionality.
|
|
269
|
+
* Converts all alphabetic characters in a string type to uppercase.
|
|
270
|
+
* @template T - The string type to convert
|
|
271
|
+
* @returns A string type with all characters converted to uppercase
|
|
272
|
+
* @example
|
|
273
|
+
* type Upper = ToUpperCase<'hello'> // type Upper = 'HELLO'
|
|
274
|
+
*/
|
|
36
275
|
type ToUpperCase<T extends string> = IsStringLiteral<T> extends true ? Uppercase<T> : string;
|
|
37
276
|
declare global {
|
|
38
277
|
interface String {
|
package/dist/outdent.d.ts
CHANGED
|
@@ -1,14 +1,88 @@
|
|
|
1
1
|
declare const outdent: Outdent;
|
|
2
|
+
/**
|
|
3
|
+
* Represents the outdent function, which can be called as a template tag
|
|
4
|
+
* or as a function to create a new instance with specific options.
|
|
5
|
+
* It also includes a `.string()` method for processing regular strings.
|
|
6
|
+
*/
|
|
2
7
|
interface Outdent {
|
|
8
|
+
/**
|
|
9
|
+
* Remove indentation from a template literal.
|
|
10
|
+
* Tag function for template literals.
|
|
11
|
+
* @param strings The static string parts of the template literal.
|
|
12
|
+
* @param values The interpolated values.
|
|
13
|
+
* @returns The processed string with indentation removed.
|
|
14
|
+
*/
|
|
3
15
|
(strings: TemplateStringsArray, ...values: any[]): string;
|
|
16
|
+
/**
|
|
17
|
+
* Create and return a new Outdent instance with the given options.
|
|
18
|
+
* @param options Configuration options for the new instance.
|
|
19
|
+
* @returns A new Outdent function instance.
|
|
20
|
+
*/
|
|
4
21
|
(options: Options): Outdent;
|
|
22
|
+
/**
|
|
23
|
+
* Remove indentation from a string
|
|
24
|
+
* @param string_ The raw string to process.
|
|
25
|
+
* @returns The processed string with indentation removed.
|
|
26
|
+
*/
|
|
5
27
|
string: (string_: string) => string;
|
|
6
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration options for the outdent function.
|
|
31
|
+
*/
|
|
7
32
|
interface Options {
|
|
33
|
+
/**
|
|
34
|
+
* Whether to cache processed template literals for better performance when
|
|
35
|
+
* using the same template multiple times.
|
|
36
|
+
*
|
|
37
|
+
* Enabling caching can significantly improve performance when the same template
|
|
38
|
+
* is used repeatedly, such as in loops or frequently called functions.
|
|
39
|
+
* @example
|
|
40
|
+
* // Create an outdent function with caching enabled (default)
|
|
41
|
+
* const dedent = outdent();
|
|
42
|
+
*
|
|
43
|
+
* // Create an outdent function with caching disabled
|
|
44
|
+
* const noCacheDedent = outdent({ cache: false });
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
8
47
|
cache?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Custom cache store to use instead of the default WeakMap.
|
|
50
|
+
* Must be a WeakMap instance.
|
|
51
|
+
*
|
|
52
|
+
* This allows you to provide your own WeakMap instance for caching,
|
|
53
|
+
* which can be useful for advanced use cases or for sharing cache
|
|
54
|
+
* between multiple outdent instances.
|
|
55
|
+
* @example
|
|
56
|
+
* // Create a custom cache
|
|
57
|
+
* const customCache = new WeakMap();
|
|
58
|
+
*
|
|
59
|
+
* // Create an outdent function with a custom cache
|
|
60
|
+
* const customCacheDedent = outdent({ cacheStore: customCache });
|
|
61
|
+
*/
|
|
9
62
|
cacheStore?: WeakMap<TemplateStringsArray, string[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Normalize all newlines in the template literal to this value.
|
|
65
|
+
*
|
|
66
|
+
* If `null`, newlines are left untouched.
|
|
67
|
+
*
|
|
68
|
+
* Newlines that get normalized are '\r\n', '\r', and '\n'.
|
|
69
|
+
*
|
|
70
|
+
* Newlines within interpolated values are *never* normalized.
|
|
71
|
+
*
|
|
72
|
+
* Although intended for normalizing to '\n' or '\r\n',
|
|
73
|
+
* you can also set to any string; for example ' '.
|
|
74
|
+
* @default null
|
|
75
|
+
*/
|
|
10
76
|
newline?: string | null;
|
|
77
|
+
/**
|
|
78
|
+
* Whether to trim the leading newline in the template literal.
|
|
79
|
+
* @default true
|
|
80
|
+
*/
|
|
11
81
|
trimLeadingNewline?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to trim the trailing newline in the template literal.
|
|
84
|
+
* @default true
|
|
85
|
+
*/
|
|
12
86
|
trimTrailingNewline?: boolean;
|
|
13
87
|
}
|
|
14
88
|
export { Options, Outdent, outdent };
|
package/dist/outdent.js
CHANGED
|
@@ -1,117 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const hop = Object.prototype.hasOwnProperty;
|
|
4
|
-
const has = (object, property) => hop.call(object, property);
|
|
5
|
-
const extend = (target, source) => {
|
|
6
|
-
for (const property of Object.keys(source)) {
|
|
7
|
-
target[property] = source[property];
|
|
8
|
-
}
|
|
9
|
-
return target;
|
|
10
|
-
};
|
|
11
|
-
const internalOutdentArray = (strings, firstInterpolatedValueSetsIndentationLevel, options) => {
|
|
12
|
-
if (strings.length === 0) {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
let indentationLevel = 0;
|
|
16
|
-
const match = RE_DETECT_INDENTATION.exec(strings[0]);
|
|
17
|
-
if (match) {
|
|
18
|
-
indentationLevel = match[1].length;
|
|
19
|
-
}
|
|
20
|
-
const reSource = String.raw`(\r\n|\r|\n).{0,${indentationLevel}}`;
|
|
21
|
-
const reMatchIndent = new RegExp(reSource, "g");
|
|
22
|
-
if (firstInterpolatedValueSetsIndentationLevel) {
|
|
23
|
-
strings = strings.slice(1);
|
|
24
|
-
}
|
|
25
|
-
const { newline, trimLeadingNewline, trimTrailingNewline } = options;
|
|
26
|
-
const normalizeNewlines = typeof newline === "string";
|
|
27
|
-
const l = strings.length;
|
|
28
|
-
const outdentedStrings = Array.from({ length: l });
|
|
29
|
-
for (let index = 0; index < l; index++) {
|
|
30
|
-
let v = strings[index];
|
|
31
|
-
v = v.replace(reMatchIndent, "$1");
|
|
32
|
-
if (index === 0 && trimLeadingNewline) {
|
|
33
|
-
v = v.replace(RE_LEADING_NEWLINE, "");
|
|
34
|
-
}
|
|
35
|
-
if (index === l - 1 && trimTrailingNewline) {
|
|
36
|
-
v = v.replace(RE_TRAILING_NEWLINE, "");
|
|
37
|
-
}
|
|
38
|
-
if (normalizeNewlines) {
|
|
39
|
-
v = v.replaceAll(RE_MATCH_NEWLINES, newline);
|
|
40
|
-
}
|
|
41
|
-
outdentedStrings[index] = v;
|
|
42
|
-
}
|
|
43
|
-
return outdentedStrings;
|
|
44
|
-
};
|
|
45
|
-
const concatStringsAndValues = (strings, values) => {
|
|
46
|
-
const chunks = Array.from({ length: strings.length + values.length });
|
|
47
|
-
let index = 0;
|
|
48
|
-
const l = strings.length;
|
|
49
|
-
for (; index < l - 1; index++) {
|
|
50
|
-
chunks[index * 2] = strings[index];
|
|
51
|
-
chunks[index * 2 + 1] = String(values[index]);
|
|
52
|
-
}
|
|
53
|
-
chunks[index * 2] = strings[index];
|
|
54
|
-
return chunks.join("");
|
|
55
|
-
};
|
|
56
|
-
const isTemplateStringsArray = (v) => has(v, "raw") && has(v, "length");
|
|
57
|
-
const templateCache = /* @__PURE__ */ new WeakMap();
|
|
58
|
-
const createInstance = (options) => {
|
|
59
|
-
const enableCache = options.cache !== false;
|
|
60
|
-
const cache = enableCache ? options.cacheStore ?? templateCache : void 0;
|
|
61
|
-
const hasNewlineOption = options.newline !== void 0;
|
|
62
|
-
function outdent2(stringsOrOptions, ...values) {
|
|
63
|
-
if (isTemplateStringsArray(stringsOrOptions)) {
|
|
64
|
-
const strings = stringsOrOptions;
|
|
65
|
-
const valuesLength = values.length;
|
|
66
|
-
if (strings.length === 1 && strings[0] === "") {
|
|
67
|
-
return "";
|
|
68
|
-
}
|
|
69
|
-
if (valuesLength === 0) {
|
|
70
|
-
if (enableCache && cache && !hasNewlineOption) {
|
|
71
|
-
const cached = cache.get(strings);
|
|
72
|
-
if (cached) {
|
|
73
|
-
return cached[0];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const result = internalOutdentArray(strings, false, options);
|
|
77
|
-
if (enableCache && cache) {
|
|
78
|
-
cache.set(strings, result);
|
|
79
|
-
}
|
|
80
|
-
return result[0];
|
|
81
|
-
}
|
|
82
|
-
const firstValueIsOutdent = values[0] === outdent2 || values[0] === defaultOutdent;
|
|
83
|
-
const firstInterpolatedValueSetsIndentationLevel = firstValueIsOutdent && RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE.test(strings[0]) && RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY.test(strings[1]);
|
|
84
|
-
let renderedArray;
|
|
85
|
-
if (enableCache && cache && !hasNewlineOption) {
|
|
86
|
-
renderedArray = cache.get(strings);
|
|
87
|
-
}
|
|
88
|
-
if (!renderedArray) {
|
|
89
|
-
renderedArray = internalOutdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
|
|
90
|
-
if (enableCache && cache) {
|
|
91
|
-
cache.set(strings, renderedArray);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
|
|
95
|
-
}
|
|
96
|
-
return createInstance(extend(extend({}, options), stringsOrOptions));
|
|
97
|
-
}
|
|
98
|
-
return extend(outdent2, {
|
|
99
|
-
string(string_) {
|
|
100
|
-
if (string_ === "" || !string_) {
|
|
101
|
-
return "";
|
|
102
|
-
}
|
|
103
|
-
return internalOutdentArray([string_], false, options)[0];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
const defaultOutdent = createInstance({
|
|
108
|
-
cache: true,
|
|
109
|
-
// Enable caching by default
|
|
110
|
-
// eslint-disable-next-line unicorn/no-null
|
|
111
|
-
newline: null,
|
|
112
|
-
trimLeadingNewline: true,
|
|
113
|
-
trimTrailingNewline: true
|
|
114
|
-
});
|
|
115
|
-
const outdent = defaultOutdent;
|
|
116
|
-
|
|
117
|
-
export { outdent };
|
|
1
|
+
import{f as A,g as R,h as p,i as S,j as W,k as m}from"./packem_shared/constants-aPzGW29R.js";const I=(e,r)=>Object.hasOwn(e,r),T=(e,r)=>Object.assign(e,r),h=(e,r,n)=>{if(e.length===0)return[];let t=0;const s=m.exec(e[0]);s&&(t=s[1].length);const i=String.raw`(\r\n|\r|\n).{0,${t}}`,g=new RegExp(i,"g"),l=r?e.slice(1):e,{newline:N,trimLeadingNewline:_,trimTrailingNewline:o}=n,f=typeof N=="string",E=l.length,u=Array.from({length:E});for(let c=0;c<E;c++){let a=l[c];a=a.replace(g,"$1"),c===0&&_&&(a=a.replace(A,"")),c===E-1&&o&&(a=a.replace(R,"")),f&&(a=a.replaceAll(W,N)),u[c]=a}return u},O=(e,r)=>{const n=Array.from({length:e.length+r.length});let t=0;const s=e.length;for(;t<s-1;t++)n[t*2]=e[t],n[t*2+1]=String(r[t]);return n[t*2]=e[t],n.join("")},d=e=>I(e,"raw")&&I(e,"length"),j=new WeakMap,w=e=>{const r=e.cache!==!1,n=r?e.cacheStore??j:void 0,t=e.newline!==void 0;function s(i,...g){if(d(i)){const l=i,N=g.length;if(l.length===1&&l[0]==="")return"";if(N===0){if(r&&n&&!t){const E=n.get(l);if(E)return E[0]}const f=h(l,!1,e);return r&&n&&n.set(l,f),f[0]}const _=(g[0]===s||g[0]===L)&&p.test(l[0])&&S.test(l[1]);let o;return r&&n&&!t&&(o=n.get(l)),o||(o=h(l,_,e),r&&n&&n.set(l,o)),O(o,_?g.slice(1):g)}return w(T(T({},e),i))}return T(s,{string(i){return i===""||!i?"":h([i],!1,e)[0]}})},L=w({cache:!0,newline:null,trimLeadingNewline:!0,trimTrailingNewline:!0}),b=L;export{b as outdent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],d=12288,m=65510,f=[12288,12288,65281,65376,65504,65510],g=8361,h=65518,w=[8361,8361,65377,65470,65474,65479,65482,65487,65490,65495,65498,65500,65512,65518],M=32,C=10630,P=[32,126,162,163,165,166,172,172,175,175,10214,10221,10629,10630],c=4352,b=262141,t=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141],u=(i,l)=>{let e=0,o=Math.floor(i.length/2)-1;for(;e<=o;){const n=Math.floor((e+o)/2),a=n*2;if(l<i[a])o=n-1;else if(l>i[a+1])e=n+1;else return!0}return!1},s=19968,[x,R]=W(t);function W(i){let l=i[0],e=i[1];for(let o=0;o<i.length;o+=2){const n=i[o],a=i[o+1];if(s>=n&&s<=a)return[n,a];a-n>e-l&&(l=n,e=a)}return[l,e]}const j=i=>i<161||i>1114109?!1:u(r,i),k=i=>i<d||i>m?!1:u(f,i),p=i=>i<g||i>h?!1:u(w,i),y=i=>i<M||i>C?!1:u(P,i),A=i=>i>=x&&i<=R?!0:i<c||i>b?!1:u(t,i);function E(i){return j(i)?"ambiguous":k(i)?"fullwidth":p(i)?"halfwidth":y(i)?"narrow":A(i)?"wide":"neutral"}export{E as getCategory,j as isAmbiguous,k as isFullWidth,A as isWide};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const i=new Uint32Array(65536),q=(r,l)=>{const o=r.length,n=l.length,a=1<<o-1;let c=-1,d=0,p=o,h=o;for(;h--;)i[r.charCodeAt(h)]|=1<<h;for(h=0;h<n;h++){let A=i[l.charCodeAt(h)];const g=A|d;A|=(A&c)+c^c,d|=~(A|c),c&=A,d&a&&p++,c&a&&p--,d=d<<1|1,c=c<<1|~(g|d),d&=g}for(h=o;h--;)i[r.charCodeAt(h)]=0;return p},z=(r,l)=>{const o=l.length,n=r.length,a=[],c=[],d=Math.ceil(o/32),p=Math.ceil(n/32);for(let t=0;t<d;t++)c[t]=-1,a[t]=0;let h=0;for(;h<p-1;h++){let t=0,s=-1;const M=h*32,u=Math.min(32,n)+M;for(let e=M;e<u;e++)i[r.charCodeAt(e)]|=1<<e;for(let e=0;e<o;e++){const m=i[l.charCodeAt(e)],C=c[e/32|0]>>>e&1,f=a[e/32|0]>>>e&1,j=m|t,k=((m|f)&s)+s^s|m|f;let x=t|~(k|s),w=s&k;x>>>31^C&&(c[e/32|0]^=1<<e),w>>>31^f&&(a[e/32|0]^=1<<e),x=x<<1|C,w=w<<1|f,s=w|~(j|x),t=x&j}for(let e=M;e<u;e++)i[r.charCodeAt(e)]=0}let A=0,g=-1;const v=h*32,U=Math.min(32,n-v)+v;for(let t=v;t<U;t++)i[r.charCodeAt(t)]|=1<<t;let y=n;for(let t=0;t<o;t++){const s=i[l.charCodeAt(t)],M=c[t/32|0]>>>t&1,u=a[t/32|0]>>>t&1,e=s|A,m=((s|u)&g)+g^g|s|u;let C=A|~(m|g),f=g&m;y+=C>>>n-1&1,y-=f>>>n-1&1,C>>>31^M&&(c[t/32|0]^=1<<t),f>>>31^u&&(a[t/32|0]^=1<<t),C=C<<1|M,f=f<<1|u,g=f|~(e|C),A=C&e}for(let t=v;t<U;t++)i[r.charCodeAt(t)]=0;return y},I=(r,l)=>{if(r.length<l.length){const o=l;l=r,r=o}return l.length===0?r.length:r.length<=32?q(r,l):z(r,l)},_=(r,l)=>{let o=1/0,n=0;for(let a=0;a<l.length;a++){const c=I(r,l[a]);c<o&&(o=c,n=a)}return l[n]};export{_ as closest,I as distance};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const R=String.raw,E=R`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,a=()=>new RegExp(R`\p{RI}{2}|(?)${E}(?:\u200D${E})*`,"gu"),n=new Set(["\x1B",""]),e="\x07",_="[",r="m",u="]8;;",S=39,s=/[\u200B\uFEFF\u2060-\u2064]/g,I=new RegExp(`(?:\\${_}(?<code>\\d+)m|\\${u}(?<uri>.*)${e})`),i=Object.freeze(new Map([[0,0],[1,22],[2,22],[3,23],[4,24],[7,27],[8,28],[9,29],[30,39],[31,39],[32,39],[33,39],[34,39],[35,39],[36,39],[37,39],[40,49],[41,49],[42,49],[43,49],[44,49],[45,49],[46,49],[47,49],[90,39]])),t=/^[ \t]*(?:\r\n|\r|\n)/,N=/(?:\r\n|\r|\n)[ \t]*$/,g=/^(?:[\r\n]|$)/,c=/(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/,T=/^[ \t]*[\r\n][ \t\r\n]*$/,L=/\r\n|\n|\r/g,w=/[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g,x=/\u001B\[[\d;]*m[^\u001B]*(?:\u001B\[[\d;]*m|$)/g,B=/\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)[^\u001B]*\u001B\]8;;(?:\u0007|\u001B\\)/g,O=/[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y,A=a(),H=/[-_./\s]+/g,C=/(\u001B\[[0-9;]*[a-z])/i,G=new RegExp("\\p{Script=Arabic}","u"),M=new RegExp("\\p{Script=Bengali}","u"),D=new RegExp("\\p{Script=Cyrillic}","u"),K=new RegExp("\\p{Script=Devanagari}","u"),F=new RegExp("\\p{Script=Ethiopic}","u"),P=new RegExp("\\p{Script=Greek}","u"),m=new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+","gu"),l=new RegExp("\\p{Script=Gujarati}","u"),o=new RegExp("\\p{Script=Gurmukhi}","u"),W=new RegExp("\\p{Script=Hangul}","u"),d=new RegExp("\\p{Script=Hebrew}","u"),$=new RegExp("\\p{Script=Hiragana}","u"),U=new RegExp("\\p{Script=Han}","u"),y=new RegExp("\\p{Script=Kannada}","u"),Y=new RegExp("\\p{Script=Katakana}","u"),h=new RegExp("\\p{Script=Khmer}","u"),k=new RegExp("\\p{Script=Lao}","u"),b=new RegExp("\\p{Script=Latin}","u"),j=new RegExp("\\p{Script=Malayalam}","u"),J=new RegExp("\\p{Script=Myanmar}","u"),V=new RegExp("\\p{Script=Oriya}","u"),f=new RegExp("\\p{Script=Sinhala}","u"),z=new RegExp("\\p{Script=Tamil}","u"),Z=new RegExp("\\p{Script=Telugu}","u"),q=new RegExp("\\p{Script=Thai}","u"),v=new RegExp("\\p{Script=Tibetan}","u"),Q=/[\u02BB\u02BC\u0027]/u,X=p=>p.replace(A,"");export{l as A,o as B,y as C,z as D,Z as E,j as F,f as G,q as H,k as I,v as J,J as K,F as L,h as M,V as N,n as O,r as P,u as Q,w as R,e as S,_ as T,I as U,i as V,S as W,s as X,O as a,A as b,C as c,x as d,B as e,t as f,N as g,T as h,g as i,L as j,c as k,H as l,D as m,b as n,P as o,m as p,Q as q,Y as r,X as s,U as t,$ as u,W as v,d as w,G as x,K as y,M as z};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function I(e){const t=e.match(/^[ \t]*(?=\S)/gm);if(!t)return e;let n=Number.POSITIVE_INFINITY;for(const r of t)n=Math.min(n,r.length);return n===0||n===Number.POSITIVE_INFINITY?e:e.replace(new RegExp(`^[ \\t]{${n}}`,"gm"),"")}function c(e){const t=e.replace(/^(?:[ \t]*\r?\n)+|(?:\r?\n[ \t]*)+$/g,"");return I(t)}export{c as dedent,I as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isFullWidth as s,isWide as o,isAmbiguous as r,getCategory as n}from"./_isFullWidth-Dqc3MWgl.js";function t(e){if(!Number.isSafeInteger(e))throw new TypeError(`Expected a code point, got \`${typeof e}\`.`)}function a(e){return t(e),n(e)}function d(e,{ambiguousAsWide:i=!1}={}){return t(e),s(e)||o(e)||i&&r(e)?2:1}export{s as _isFullWidth,o as _isWide,d as eastAsianWidth,a as eastAsianWidthType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=(o,n)=>`${o}::${n?.joiner??""}::${n?.locale??""}::${n?.knownAcronyms?.join(",")??""}::${n?.normalize?"true":"false"}`;export{r as n};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function i(e,t=1,r={}){const{indent:o=" ",includeEmptyLines:n=!1}=r;if(typeof e!="string")throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof e}\``);if(typeof t!="number")throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof t}\``);if(t<0)throw new RangeError(`Expected \`count\` to be at least 0, got \`${t}\``);if(typeof o!="string")throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof o}\``);if(t===0)return e;const p=n?/^/gm:/^(?!\s*$)/gm;return e.replace(p,o.repeat(t))}export{i as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as h}from"./constants-aPzGW29R.js";const l=(o,u)=>{const{length:r}=o;if(r===0)return"";if(r===1)return o[0];const t=[];let n="",e="";for(let f=0;f<r;f++){const s=o[f];if(h.test(s)){n?(t.push(n+e+s),n="",e=""):(t.length>0&&t.push(u),n=s);continue}n?(e&&(e+=u),e+=s):(t.length>0&&t.push(u),t.push(s))}return t.join("")};export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class s{capacity;cache;constructor(e){this.capacity=e,this.cache=new Map}get(e){if(!this.cache.has(e))return;const c=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,c),c}has(e){return this.cache.has(e)}set(e,c){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.capacity){const t=this.cache.keys().next().value;t!==void 0&&this.cache.delete(t)}this.cache.set(e,c)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}size(){return this.cache.size}}export{s as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=/(?<![a-zß])SS(?![a-z])/g,l=a=>a.replaceAll(e,"ß");export{l as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import f from"./indent-cz8WMI0e.js";import i from"./dedent-CPjAYUXh.js";function n(r,o=0,t={}){return f(i(r),o,t)}export{n as default};
|