@isopodlabs/utilities 1.4.1 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +26 -23
- package/dist/{CaseInsensitive.d.ts → insensitive.d.ts} +2 -2
- package/dist/string.js +17 -7
- package/package.json +36 -28
- /package/dist/{CaseInsensitive.js → insensitive.js} +0 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Adrian Stephens
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
# @isopodlabs/utilities
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
# @isopodlabs/utilities
|
|
2
|
+
[](https://www.npmjs.com/package/@isopodlabs/utilities)
|
|
3
|
+
[](https://github.com/adrianstephens/utilities)
|
|
4
|
+
[](LICENSE.txt)
|
|
5
|
+
|
|
6
|
+
This package provides a set of utilities for TypeScript.
|
|
7
|
+
|
|
8
|
+
## ☕ Support My Work
|
|
9
|
+
If you use this package, consider [buying me a cup of tea](https://coff.ee/adrianstephens) to support future updates!
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Here is a basic example of how to use the package:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import * as utils from '@isopodlabs/utilities';
|
|
17
|
+
````
|
|
18
|
+
|
|
19
|
+
**Interfaces**:
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
**Functions**:
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
24
27
|
This project is licensed under the MIT License.
|
|
@@ -8,7 +8,7 @@ export declare class CaseInsensitiveString {
|
|
|
8
8
|
endsWith(searchString: string, position?: number): boolean;
|
|
9
9
|
indexOf(searchString: string, position?: number): number;
|
|
10
10
|
lastIndexOf(searchString: string, position?: number): number;
|
|
11
|
-
compare(other: string):
|
|
11
|
+
compare(other: string): 0 | 1 | -1;
|
|
12
12
|
}
|
|
13
13
|
export declare class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
14
14
|
private orig;
|
|
@@ -17,6 +17,6 @@ export declare class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
|
17
17
|
}
|
|
18
18
|
export declare function String(value: string): CaseInsensitiveString;
|
|
19
19
|
export declare function String2(value: string): CaseInsensitiveString2;
|
|
20
|
-
export declare function compare(a: string, b: string):
|
|
20
|
+
export declare function compare(a: string, b: string): 0 | 1 | -1;
|
|
21
21
|
export declare function Record<T>(obj: Record<string, T>): Record<string, T>;
|
|
22
22
|
export declare function Record2<T>(obj: Record<string, T>): Record<string, T>;
|
package/dist/string.js
CHANGED
|
@@ -45,25 +45,35 @@ function trim0(value) {
|
|
|
45
45
|
return index === -1 ? value : value.substring(0, index);
|
|
46
46
|
}
|
|
47
47
|
function replace(value, re, process) {
|
|
48
|
-
let m;
|
|
49
48
|
let result = "";
|
|
50
49
|
let i = 0;
|
|
51
|
-
|
|
50
|
+
for (let m; (m = re.exec(value));) {
|
|
52
51
|
result += value.substring(i, m.index) + process(m);
|
|
53
52
|
i = re.lastIndex;
|
|
54
53
|
}
|
|
55
54
|
return result + value.substring(i);
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
/*
|
|
57
|
+
export async function async_replace(value: string, re: RegExp, process: (match: RegExpExecArray)=>Promise<string>): Promise<string> {
|
|
59
58
|
let result = "";
|
|
60
59
|
let i = 0;
|
|
61
|
-
|
|
60
|
+
for (let m; (m = re.exec(value));) {
|
|
62
61
|
result += value.substring(i, m.index) + await process(m);
|
|
63
62
|
i = re.lastIndex;
|
|
64
63
|
}
|
|
65
64
|
return result + value.substring(i);
|
|
66
65
|
}
|
|
66
|
+
*/
|
|
67
|
+
async function async_replace(value, re, process) {
|
|
68
|
+
const combine = async (m) => value.substring(i, m.index) + await process(m);
|
|
69
|
+
const promises = [];
|
|
70
|
+
let i = 0;
|
|
71
|
+
for (let m; (m = re.exec(value));) {
|
|
72
|
+
promises.push(combine(m));
|
|
73
|
+
i = re.lastIndex;
|
|
74
|
+
}
|
|
75
|
+
return (await Promise.all(promises)).join('') + value.substring(i);
|
|
76
|
+
}
|
|
67
77
|
function replace_back(value, re, process) {
|
|
68
78
|
const start = re.lastIndex;
|
|
69
79
|
const m = re.exec(value);
|
|
@@ -88,10 +98,10 @@ function splitEvery(s, n) {
|
|
|
88
98
|
return Array.from({ length: Math.ceil(s.length / n) }, (_, i) => s.slice(i * n, (i + 1) * n));
|
|
89
99
|
}
|
|
90
100
|
function tag(strings, ...keys) {
|
|
91
|
-
return (
|
|
101
|
+
return (...values) => {
|
|
92
102
|
const dict = values.at(-1) || {};
|
|
93
103
|
return keys.map((key, i) => (Number.isInteger(key) ? values[key] : dict[key]) + strings[i + 1]).join('');
|
|
94
|
-
}
|
|
104
|
+
};
|
|
95
105
|
}
|
|
96
106
|
function previousChar(str, pos) {
|
|
97
107
|
return pos === 0
|
package/package.json
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@isopodlabs/utilities",
|
|
3
|
+
"version": "1.5.1",
|
|
4
|
+
"description": "Various typescript helpers.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/adrianstephens/ts-utilities.git"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.js",
|
|
12
|
+
"./insensitive": "./dist/insensitive.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/**/*.{js,d.ts}",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"test": "echo \"No tests specified\" && exit 0"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"typescript",
|
|
24
|
+
"string",
|
|
25
|
+
"iterator",
|
|
26
|
+
"algorithm"
|
|
27
|
+
],
|
|
28
|
+
"author": "Adrian Stephens",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^22.13.8",
|
|
32
|
+
"eslint": "^9.21.0",
|
|
33
|
+
"typescript": "^5.8.2",
|
|
34
|
+
"typescript-eslint": "^8.26.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
File without changes
|