@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
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../packem_shared/types.d-
|
|
3
|
-
|
|
1
|
+
import { b as CaseOptions, T as TitleCase } from "../packem_shared/types.d-fhe030jX.js";
|
|
2
|
+
import "../packem_shared/types.d-CmNvyl4l.js";
|
|
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
13
|
declare function titleCase<T extends string = string>(value?: T, options?: CaseOptions): TitleCase<T>;
|
|
5
14
|
export { titleCase as default };
|
package/dist/case/title-case.js
CHANGED
|
@@ -1,42 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { splitByCase } from './split-by-case.js';
|
|
3
|
-
import upperFirst from './upper-first.js';
|
|
4
|
-
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
5
|
-
import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
|
|
6
|
-
|
|
7
|
-
const defaultCacheStore = new LRUCache(1e3);
|
|
8
|
-
function titleCase(value, options) {
|
|
9
|
-
if (typeof value !== "string") {
|
|
10
|
-
return "";
|
|
11
|
-
}
|
|
12
|
-
const shouldCache = options?.cache ?? false;
|
|
13
|
-
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
14
|
-
let cacheKey;
|
|
15
|
-
if (shouldCache) {
|
|
16
|
-
cacheKey = generateCacheKey(value, options);
|
|
17
|
-
}
|
|
18
|
-
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
19
|
-
return cacheStore.get(cacheKey);
|
|
20
|
-
}
|
|
21
|
-
const result = splitByCase(value, {
|
|
22
|
-
handleAnsi: options?.handleAnsi,
|
|
23
|
-
handleEmoji: options?.handleEmoji,
|
|
24
|
-
knownAcronyms: options?.knownAcronyms,
|
|
25
|
-
locale: options?.locale,
|
|
26
|
-
normalize: options?.normalize,
|
|
27
|
-
separators: void 0,
|
|
28
|
-
stripAnsi: options?.stripAnsi,
|
|
29
|
-
stripEmoji: options?.stripEmoji
|
|
30
|
-
}).map((word) => {
|
|
31
|
-
if (options?.locale?.startsWith("de")) {
|
|
32
|
-
word = normalizeGermanEszett(word);
|
|
33
|
-
}
|
|
34
|
-
return upperFirst(options?.locale ? word.toLocaleLowerCase(options.locale) : word.toLowerCase(), { locale: options?.locale });
|
|
35
|
-
}).join(" ");
|
|
36
|
-
if (shouldCache && cacheKey) {
|
|
37
|
-
cacheStore.set(cacheKey, result);
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { titleCase as default };
|
|
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{n as p}from"../packem_shared/generate-cache-key-BqU1Cqwm.js";import{a as f}from"../packem_shared/normalize-german-eszett-hNMwtGjd.js";const d=new e(1e3);function y(t,o){if(typeof t!="string")return"";const a=o?.cache??!1,i=o?.cacheStore??d;let r;if(a&&(r=p(t,o)),a&&r&&i.has(r))return i.get(r);const n=c(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(s=>{const l=o?.locale?.startsWith("de")?f(s):s;return m(o?.locale?l.toLocaleLowerCase(o.locale):l.toLowerCase(),{locale:o?.locale})}).join(" ");return a&&r&&i.set(r,n),n}export{y as default};
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../packem_shared/types.d-
|
|
3
|
-
|
|
1
|
+
import { b as CaseOptions, j as TrainCase } from "../packem_shared/types.d-fhe030jX.js";
|
|
2
|
+
import "../packem_shared/types.d-CmNvyl4l.js";
|
|
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
15
|
declare const trainCase: <T extends string = string>(value?: T, options?: CaseOptions) => TrainCase<T>;
|
|
5
16
|
export { trainCase as default };
|
package/dist/case/train-case.js
CHANGED
|
@@ -1,40 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { splitByCase } from './split-by-case.js';
|
|
3
|
-
import upperFirst from './upper-first.js';
|
|
4
|
-
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
5
|
-
import joinSegments from '../packem_shared/joinSegments-BStLas0c.js';
|
|
6
|
-
|
|
7
|
-
const defaultCacheStore = new LRUCache(1e3);
|
|
8
|
-
const trainCase = (value, options) => {
|
|
9
|
-
if (typeof value !== "string") {
|
|
10
|
-
return "";
|
|
11
|
-
}
|
|
12
|
-
const shouldCache = options?.cache ?? false;
|
|
13
|
-
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
14
|
-
let cacheKey;
|
|
15
|
-
if (shouldCache) {
|
|
16
|
-
cacheKey = generateCacheKey(value, options);
|
|
17
|
-
}
|
|
18
|
-
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
19
|
-
return cacheStore.get(cacheKey);
|
|
20
|
-
}
|
|
21
|
-
const result = joinSegments(
|
|
22
|
-
splitByCase(value, {
|
|
23
|
-
handleAnsi: options?.handleAnsi,
|
|
24
|
-
handleEmoji: options?.handleEmoji,
|
|
25
|
-
knownAcronyms: options?.knownAcronyms,
|
|
26
|
-
locale: options?.locale,
|
|
27
|
-
normalize: options?.normalize,
|
|
28
|
-
separators: void 0,
|
|
29
|
-
stripAnsi: options?.stripAnsi,
|
|
30
|
-
stripEmoji: options?.stripEmoji
|
|
31
|
-
}).map((p) => upperFirst(p, { locale: options?.locale })),
|
|
32
|
-
"-"
|
|
33
|
-
);
|
|
34
|
-
if (shouldCache && cacheKey) {
|
|
35
|
-
cacheStore.set(cacheKey, result);
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export { trainCase as default };
|
|
1
|
+
import{i as a}from"../packem_shared/lru-cache-BtMSrYQJ.js";import{splitByCase as l}from"./split-by-case.js";import e from"./upper-first.js";import{n as p}from"../packem_shared/generate-cache-key-BqU1Cqwm.js";import c from"../packem_shared/joinSegments-CaHT-45s.js";const f=new a(1e3),y=(n,o)=>{if(typeof n!="string")return"";const t=o?.cache??!1,i=o?.cacheStore??f;let r;if(t&&(r=p(n,o)),t&&r&&i.has(r))return i.get(r);const s=c(l(n,{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(m=>e(m,{locale:o?.locale})),"-");return t&&r&&i.set(r,s),s};export{y as default};
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import { L as LocaleOptions, U as UpperFirst } from "../packem_shared/types.d-
|
|
2
|
-
import "../packem_shared/types.d-
|
|
3
|
-
|
|
1
|
+
import { L as LocaleOptions, U as UpperFirst } from "../packem_shared/types.d-fhe030jX.js";
|
|
2
|
+
import "../packem_shared/types.d-CmNvyl4l.js";
|
|
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
14
|
declare const upperFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => UpperFirst<T>;
|
|
5
15
|
export { upperFirst as default };
|
package/dist/case/upper-first.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
if (typeof value !== "string" || value === "") {
|
|
3
|
-
return "";
|
|
4
|
-
}
|
|
5
|
-
const firstChar = options?.locale ? value[0].toLocaleUpperCase(options.locale) : value[0].toUpperCase();
|
|
6
|
-
return firstChar + value.slice(1);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export { upperFirst as default };
|
|
1
|
+
const a=(e,o)=>typeof e!="string"||e===""?"":(o?.locale?e[0].toLocaleUpperCase(o.locale):e[0].toUpperCase())+e.slice(1);export{a as default};
|
package/dist/closest-string.d.ts
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
|
+
/** Options for {@linkcode closestString}. */
|
|
1
2
|
interface ClosestStringOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Whether the distance should include case.
|
|
5
|
+
* @default {false}
|
|
6
|
+
*/
|
|
2
7
|
caseSensitive?: boolean;
|
|
8
|
+
/**
|
|
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
|
+
*/
|
|
3
15
|
compareFn?: (a: string, b: string) => number;
|
|
4
16
|
}
|
|
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
|
+
*/
|
|
5
37
|
declare const closestString: (givenWord: string, possibleWords: ReadonlyArray<string>, options?: ClosestStringOptions) => string | undefined;
|
|
6
38
|
export { ClosestStringOptions, closestString };
|
package/dist/closest-string.js
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const closestString = (givenWord, possibleWords, options) => {
|
|
4
|
-
if (possibleWords.length === 0) {
|
|
5
|
-
throw new TypeError("When using closestString(), the possibleWords array must contain at least one word");
|
|
6
|
-
}
|
|
7
|
-
const { caseSensitive, compareFn: compareFunction = distance } = { ...options };
|
|
8
|
-
if (!caseSensitive) {
|
|
9
|
-
givenWord = givenWord.toLowerCase();
|
|
10
|
-
}
|
|
11
|
-
let nearestWord = possibleWords[0] ?? void 0;
|
|
12
|
-
let closestStringDistance = Infinity;
|
|
13
|
-
for (const each of possibleWords) {
|
|
14
|
-
const distance = caseSensitive ? compareFunction(givenWord, each) : compareFunction(givenWord, each.toLowerCase());
|
|
15
|
-
if (distance < closestStringDistance) {
|
|
16
|
-
nearestWord = each;
|
|
17
|
-
closestStringDistance = distance;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return nearestWord;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export { closestString };
|
|
1
|
+
import{distance as p}from"./packem_shared/closest-C6YDQs4m.js";const d=(s,o,l)=>{if(o.length===0)throw new TypeError("When using closestString(), the possibleWords array must contain at least one word");const{caseSensitive:e,compareFn:r=p}={...l},n=e?s:s.toLowerCase();let a=o[0]??void 0,i=1/0;for(const g of o){const t=g,c=e?r(n,t):r(n,t.toLowerCase());c<i&&(a=t,i=c)}return a};export{d as closestString};
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
+
/** Options for {@linkcode compareSimilarity}. */
|
|
1
2
|
interface CompareSimilarityOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Whether the distance should include case.
|
|
5
|
+
* @default {false}
|
|
6
|
+
*/
|
|
2
7
|
caseSensitive?: boolean;
|
|
8
|
+
/**
|
|
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
|
+
*/
|
|
3
15
|
compareFn?: (a: string, b: string) => number;
|
|
4
16
|
}
|
|
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
|
+
*/
|
|
5
42
|
declare const compareSimilarity: (givenWord: string, options?: CompareSimilarityOptions) => (a: string, b: string) => number;
|
|
6
43
|
export { CompareSimilarityOptions, compareSimilarity };
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const compareSimilarity = (givenWord, options) => {
|
|
4
|
-
const { compareFn: compareFunction = distance } = { ...options };
|
|
5
|
-
if (options?.caseSensitive) {
|
|
6
|
-
return (a, b) => compareFunction(givenWord, a) - compareFunction(givenWord, b);
|
|
7
|
-
}
|
|
8
|
-
givenWord = givenWord.toLowerCase();
|
|
9
|
-
return (a, b) => compareFunction(givenWord, a.toLowerCase()) - compareFunction(givenWord, b.toLowerCase());
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { compareSimilarity };
|
|
1
|
+
import{distance as i}from"./packem_shared/closest-C6YDQs4m.js";const n=(o,s)=>{const{compareFn:e=i}={...s};if(s?.caseSensitive)return(t,r)=>e(o,t)-e(o,r);const a=o.toLowerCase();return(t,r)=>e(a,t.toLowerCase())-e(a,r.toLowerCase())};export{n as compareSimilarity};
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
*/
|
|
8
|
+
declare const countOccurrences: (value: unknown, substring: string) => number;
|
|
9
|
+
export { countOccurrences };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const i=(c,r)=>{const n=String(c);if(typeof r!="string")throw new TypeError("Expected character");if(r.length===0)throw new TypeError("Expected non-empty substring");let e=0,t=n.indexOf(r);for(;t!==-1;){e++;const o=t+r.length;if(o<=t)break;t=n.indexOf(r,o)}return e};export{i as countOccurrences};
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
*/
|
|
6
|
+
declare const direction: (value?: string) => "rtl" | "ltr" | "neutral";
|
|
7
|
+
export { direction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e="֑-߿יִ-﷽ﹰ-ﻼ",n="A-Za-zÀ-ÖØ-öø-ʸ̀-ࠀ-Ⰰ-︀--",o=new RegExp(`^[^${n}]*[${e}]`),s=new RegExp(`^[^${e}]*[${n}]`),c=(r="")=>{const t=r;return o.test(t)?"rtl":s.test(t)?"ltr":"neutral"};export{c as direction};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
|
|
2
|
+
type Options = {
|
|
3
|
+
/**
|
|
4
|
+
Whether to treat an `'ambiguous'` character as wide.
|
|
5
|
+
@default true
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
9
|
+
const codePoint = '⛣'.codePointAt(0);
|
|
10
|
+
console.log(eastAsianWidth(codePoint));
|
|
11
|
+
//=> 1
|
|
12
|
+
console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
|
|
13
|
+
//=> 2
|
|
14
|
+
```
|
|
15
|
+
> 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.__
|
|
16
|
+
> - http://www.unicode.org/reports/tr11/
|
|
17
|
+
*/
|
|
18
|
+
readonly ambiguousAsWide?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
Returns the width as a number for the given code point.
|
|
22
|
+
|
|
23
|
+
@param codePoint - A Unicode code point.
|
|
24
|
+
|
|
25
|
+
@example
|
|
26
|
+
```
|
|
27
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
28
|
+
|
|
29
|
+
const codePoint = '字'.codePointAt(0);
|
|
30
|
+
|
|
31
|
+
console.log(eastAsianWidth(codePoint));
|
|
32
|
+
//=> 2
|
|
33
|
+
```
|
|
34
|
+
*/
|
|
35
|
+
declare function eastAsianWidth(codePoint: number, options?: Options): 1 | 2;
|
|
36
|
+
/**
|
|
37
|
+
Returns the type of “East Asian Width” for the given code point.
|
|
38
|
+
|
|
39
|
+
@param codePoint - A Unicode code point.
|
|
40
|
+
|
|
41
|
+
@example
|
|
42
|
+
```
|
|
43
|
+
import {eastAsianWidthType} from 'get-east-asian-width';
|
|
44
|
+
|
|
45
|
+
const codePoint = '字'.codePointAt(0);
|
|
46
|
+
|
|
47
|
+
console.log(eastAsianWidthType(codePoint));
|
|
48
|
+
//=> 'wide'
|
|
49
|
+
```
|
|
50
|
+
*/
|
|
51
|
+
declare function eastAsianWidthType(codePoint: number): WidthType;
|
|
52
|
+
export { type Options as EastAsianWidthOptions, type WidthType as EastAsianWidthType, eastAsianWidth, eastAsianWidthType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{eastAsianWidth as e,eastAsianWidthType as i}from"./packem_shared/eastAsianWidth-DJV8Kqd-.js";export{e as eastAsianWidth,i as eastAsianWidthType};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TruncateOptions } from "./truncate.js";
|
|
2
|
+
import "./get-string-truncated-width.js";
|
|
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
|
+
*/
|
|
20
|
+
declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Options for the excerpt function
|
|
23
|
+
*/
|
|
24
|
+
type ExcerptOptions = Omit<TruncateOptions, "position">;
|
|
25
|
+
export { ExcerptOptions, excerpt };
|