@vltpkg/fast-split 1.0.0-rc.2 → 1.0.0-rc.23

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/package.json CHANGED
@@ -1,67 +1,57 @@
1
1
  {
2
2
  "name": "@vltpkg/fast-split",
3
3
  "description": "A fast way to split small-to-medium sized strings by small string delimiters",
4
- "version": "1.0.0-rc.2",
4
+ "version": "1.0.0-rc.23",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
8
8
  "directory": "src/fast-split"
9
9
  },
10
- "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
11
- "tshy": {
12
- "selfLink": false,
13
- "liveDev": true,
14
- "dialects": [
15
- "esm"
16
- ],
17
- "exports": {
18
- "./package.json": "./package.json",
19
- ".": "./src/index.ts"
20
- }
10
+ "author": {
11
+ "name": "vlt technology inc.",
12
+ "email": "support@vlt.sh"
21
13
  },
22
14
  "devDependencies": {
23
- "@eslint/js": "^9.34.0",
24
- "@types/node": "^22.17.2",
25
- "eslint": "^9.34.0",
26
- "prettier": "^3.6.2",
27
- "tap": "^21.1.0",
28
- "tshy": "^3.0.2",
15
+ "@eslint/js": "^9.39.1",
16
+ "@types/node": "^22.19.2",
17
+ "eslint": "^9.39.1",
18
+ "prettier": "^3.7.4",
19
+ "tap": "^21.5.0",
29
20
  "typedoc": "~0.27.9",
30
21
  "typescript": "5.7.3",
31
- "typescript-eslint": "^8.40.0"
22
+ "typescript-eslint": "^8.49.0"
32
23
  },
33
24
  "license": "BSD-2-Clause-Patent",
34
25
  "engines": {
35
- "node": ">=22"
26
+ "node": ">=22.22.0"
27
+ },
28
+ "scripts": {
29
+ "benchmark:split": "./test/fixtures/split-vs-fast-split.ts",
30
+ "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
31
+ "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
32
+ "lint": "eslint . --fix",
33
+ "lint:check": "eslint .",
34
+ "prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
35
+ "snap": "tap",
36
+ "test": "tap",
37
+ "posttest": "tsc --noEmit",
38
+ "typecheck": "tsc --noEmit"
36
39
  },
37
40
  "tap": {
38
41
  "extends": "../../tap-config.yaml"
39
42
  },
40
43
  "prettier": "../../.prettierrc.js",
41
- "module": "./dist/esm/index.js",
44
+ "module": "./dist/index.js",
42
45
  "type": "module",
43
46
  "exports": {
44
47
  "./package.json": "./package.json",
45
48
  ".": {
46
49
  "import": {
47
- "types": "./dist/esm/index.d.ts",
48
- "default": "./dist/esm/index.js"
50
+ "default": "./dist/index.js"
49
51
  }
50
52
  }
51
53
  },
52
54
  "files": [
53
55
  "dist"
54
- ],
55
- "scripts": {
56
- "benchmark:split": "./test/fixtures/split-vs-fast-split.ts",
57
- "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
58
- "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
59
- "lint": "eslint . --fix",
60
- "lint:check": "eslint .",
61
- "snap": "tap",
62
- "test": "tap",
63
- "posttest": "tsc --noEmit",
64
- "tshy": "tshy",
65
- "typecheck": "tsc --noEmit"
66
- }
67
- }
56
+ ]
57
+ }
@@ -1,44 +0,0 @@
1
- /** utility types to turn a null/undefined/void return into string */
2
- export type NullToString<T> = VoidReplace<T>;
3
- /** Utility type to replace null/undefined with a given type */
4
- export type NullReplace<T, R = string> = T extends NonNullable<T> ? T : NonNullable<T> | R;
5
- /** Utility type to replace void with a given type */
6
- export type VoidReplace<T, R = string> = undefined extends T ? NullReplace<Exclude<T, void>, R> | R : NullReplace<T, R>;
7
- /**
8
- * Split a string by a string delimiter, optionally limiting the number
9
- * of parts parsed, and/or transforming the string parts into some other
10
- * type of value.
11
- *
12
- * Pass `-1` as the `limit` parameter to get all parts (useful if an `onPart`
13
- * method is provided)
14
- *
15
- * If an `onPart` method is provided, and returns `undefined`, then the
16
- * original string part is included in the result set.
17
- *
18
- * ```ts
19
- * import { fastSplit } from '@vltpkg/fast-split'
20
- *
21
- * // say we want to split a string on '.' characters
22
- * const str = getSomeStringSomehow()
23
- *
24
- * // basic usage, just like str.split('.'), gives us an array
25
- * const parts = fastSplit(str, '.')
26
- *
27
- * // get just the first two parts, leave the rest intact
28
- * // Note: unlike str.split('.', 3), the 'rest' here will
29
- * // include the entire rest of the string.
30
- * // If you do `str.split('.', 3)`, then the last item in the
31
- * // returned array is truncated at the next delimiter
32
- * const [first, second, rest] = fastSplit(str, '.', 3)
33
- *
34
- * // If you need to transform it, say if it's an IPv4 address
35
- * // that you want to turn into numbers, you can do that by
36
- * // providing the onPart method, which will be slightly faster
37
- * // than getting an array and subsequently looping over it
38
- * // pass `-1` as the limit to give us all parts
39
- * const nums = fastSplit(str, '.', -1, (part, parts, index) => Number(s))
40
- * ```
41
- */
42
- export declare function fastSplit<T = string>(str: string, delim: string, limit: number, onPart: (part: string, parts: NullToString<T>[], i: number) => T): NullToString<T>[];
43
- export declare function fastSplit(str: string, delim: string, limit?: number): string[];
44
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAA;AAE5C,+DAA+D;AAC/D,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,IACnC,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEnD,qDAAqD;AACrD,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,IACnC,SAAS,SAAS,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GACxD,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,MAAM,EAClC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC,GAC/D,YAAY,CAAC,CAAC,CAAC,EAAE,CAAA;AACpB,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,EAAE,CAAA"}
package/dist/esm/index.js DELETED
@@ -1,20 +0,0 @@
1
- export function fastSplit(str, delim, limit = -1, onPart) {
2
- let i = 0;
3
- let p = 0;
4
- const l = delim.length;
5
- const parts = [];
6
- while (i !== -1) {
7
- i = str.indexOf(delim, p);
8
- const part = i === -1 || parts.length === limit - 1 ?
9
- str.substring(p)
10
- : str.substring(p, i);
11
- parts.push((onPart?.(part, parts, i) ?? part));
12
- if (parts.length === limit) {
13
- // push the rest into the last part
14
- return parts;
15
- }
16
- p = i + l;
17
- }
18
- return parts;
19
- }
20
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA0DA,MAAM,UAAU,SAAS,CACvB,GAAW,EACX,KAAa,EACb,KAAK,GAAG,CAAC,CAAC,EACV,MAIkB;IAElB,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAA;IACtB,MAAM,KAAK,GAAsB,EAAE,CAAA;IACnC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAChB,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QACzB,MAAM,IAAI,GACR,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC;YACtC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACvB,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,IAAI,CAAoB,CAAC,CAAA;QACjE,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YAC3B,mCAAmC;YACnC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACX,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["/** utility types to turn a null/undefined/void return into string */\nexport type NullToString<T> = VoidReplace<T>\n\n/** Utility type to replace null/undefined with a given type */\nexport type NullReplace<T, R = string> =\n T extends NonNullable<T> ? T : NonNullable<T> | R\n\n/** Utility type to replace void with a given type */\nexport type VoidReplace<T, R = string> =\n undefined extends T ? NullReplace<Exclude<T, void>, R> | R\n : NullReplace<T, R>\n\n/**\n * Split a string by a string delimiter, optionally limiting the number\n * of parts parsed, and/or transforming the string parts into some other\n * type of value.\n *\n * Pass `-1` as the `limit` parameter to get all parts (useful if an `onPart`\n * method is provided)\n *\n * If an `onPart` method is provided, and returns `undefined`, then the\n * original string part is included in the result set.\n *\n * ```ts\n * import { fastSplit } from '@vltpkg/fast-split'\n *\n * // say we want to split a string on '.' characters\n * const str = getSomeStringSomehow()\n *\n * // basic usage, just like str.split('.'), gives us an array\n * const parts = fastSplit(str, '.')\n *\n * // get just the first two parts, leave the rest intact\n * // Note: unlike str.split('.', 3), the 'rest' here will\n * // include the entire rest of the string.\n * // If you do `str.split('.', 3)`, then the last item in the\n * // returned array is truncated at the next delimiter\n * const [first, second, rest] = fastSplit(str, '.', 3)\n *\n * // If you need to transform it, say if it's an IPv4 address\n * // that you want to turn into numbers, you can do that by\n * // providing the onPart method, which will be slightly faster\n * // than getting an array and subsequently looping over it\n * // pass `-1` as the limit to give us all parts\n * const nums = fastSplit(str, '.', -1, (part, parts, index) => Number(s))\n * ```\n */\nexport function fastSplit<T = string>(\n str: string,\n delim: string,\n limit: number,\n onPart: (part: string, parts: NullToString<T>[], i: number) => T,\n): NullToString<T>[]\nexport function fastSplit(\n str: string,\n delim: string,\n limit?: number,\n): string[]\nexport function fastSplit<T = string>(\n str: string,\n delim: string,\n limit = -1,\n onPart?: (\n part: string,\n parts: NullToString<T>[],\n i: number,\n ) => T | undefined,\n): NullToString<T>[] {\n let i = 0\n let p = 0\n const l = delim.length\n const parts: NullToString<T>[] = []\n while (i !== -1) {\n i = str.indexOf(delim, p)\n const part =\n i === -1 || parts.length === limit - 1 ?\n str.substring(p)\n : str.substring(p, i)\n parts.push((onPart?.(part, parts, i) ?? part) as NullToString<T>)\n if (parts.length === limit) {\n // push the rest into the last part\n return parts\n }\n p = i + l\n }\n return parts\n}\n"]}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }