@gtkx/utils 1.6.0 → 2.0.0-beta.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/README.md +5 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/path.d.ts +5 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +10 -0
- package/dist/path.js.map +1 -0
- package/dist/process/resolve-executable.d.ts +2 -2
- package/dist/process/resolve-executable.d.ts.map +1 -1
- package/dist/process/resolve-executable.js +3 -37
- package/dist/process/resolve-executable.js.map +1 -1
- package/package.json +9 -3
- package/src/index.ts +1 -1
- package/src/path.ts +17 -0
- package/src/process/resolve-executable.ts +4 -46
- package/dist/map/get-or-insert.d.ts +0 -8
- package/dist/map/get-or-insert.d.ts.map +0 -1
- package/dist/map/get-or-insert.js +0 -10
- package/dist/map/get-or-insert.js.map +0 -1
- package/dist/map/index.d.ts +0 -2
- package/dist/map/index.d.ts.map +0 -1
- package/dist/map/index.js +0 -2
- package/dist/map/index.js.map +0 -1
- package/src/map/get-or-insert.ts +0 -18
- package/src/map/index.ts +0 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<p align="center">
|
|
14
14
|
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/v/create-gtkx?color=cb3837&logo=npm&label=create-gtkx" alt="npm version" /></a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/dm/create-gtkx?color=cb3837&logo=npm&label=downloads" alt="npm downloads" /></a>
|
|
16
|
-
<img src="https://img.shields.io/badge/node-%E2%89%
|
|
16
|
+
<img src="https://img.shields.io/badge/node-%E2%89%A526.7-339933?logo=node.js&logoColor=white" alt="Node >= 26.7" />
|
|
17
17
|
<a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License: MPL-2.0" /></a>
|
|
18
18
|
<a href="https://github.com/gtkx-org/gtkx/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/gtkx-org/gtkx/ci.yml?branch=main&logo=github&label=CI" alt="CI status" /></a>
|
|
19
19
|
<img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
|
|
@@ -116,7 +116,7 @@ At runtime, the native Rust core calls straight into the system GTK4, Adwaita, a
|
|
|
116
116
|
|
|
117
117
|
## Quick start
|
|
118
118
|
|
|
119
|
-
GTKX is Linux-only and needs Node.js
|
|
119
|
+
GTKX is Linux-only and needs Node.js 26.7 or later. See [Requirements](#requirements).
|
|
120
120
|
|
|
121
121
|
Scaffold a new app with the `create-gtkx` initializer:
|
|
122
122
|
|
|
@@ -145,8 +145,8 @@ The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tu
|
|
|
145
145
|
|
|
146
146
|
GTKX is Linux-only. You need:
|
|
147
147
|
|
|
148
|
-
- Linux with the GTK4 (4.20 or later)
|
|
149
|
-
- Node.js
|
|
148
|
+
- Linux with the GTK4 (4.20 or later), Adwaita (1.8 or later), and GLib development libraries
|
|
149
|
+
- Node.js 26.7 or later
|
|
150
150
|
|
|
151
151
|
The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
|
|
152
152
|
|
|
@@ -167,7 +167,7 @@ GTKX is stable and ready for production use.
|
|
|
167
167
|
|
|
168
168
|
## Contributing
|
|
169
169
|
|
|
170
|
-
Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js
|
|
170
|
+
Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 26.7 or later, pnpm, and a Rust toolchain.
|
|
171
171
|
|
|
172
172
|
## License
|
|
173
173
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export * from "./array/index.ts";
|
|
|
2
2
|
export * from "./class/index.ts";
|
|
3
3
|
export * from "./error/index.ts";
|
|
4
4
|
export * from "./log/index.ts";
|
|
5
|
-
export * from "./map/index.ts";
|
|
6
5
|
export * from "./object/index.ts";
|
|
6
|
+
export * from "./path.ts";
|
|
7
7
|
export * from "./predicate/index.ts";
|
|
8
8
|
export * from "./process/index.ts";
|
|
9
9
|
export * from "./set/index.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ export * from "./array/index.js";
|
|
|
2
2
|
export * from "./class/index.js";
|
|
3
3
|
export * from "./error/index.js";
|
|
4
4
|
export * from "./log/index.js";
|
|
5
|
-
export * from "./map/index.js";
|
|
6
5
|
export * from "./object/index.js";
|
|
6
|
+
export * from "./path.js";
|
|
7
7
|
export * from "./predicate/index.js";
|
|
8
8
|
export * from "./process/index.js";
|
|
9
9
|
export * from "./set/index.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./array/index.ts\";\nexport * from \"./class/index.ts\";\nexport * from \"./error/index.ts\";\nexport * from \"./log/index.ts\";\nexport * from \"./object/index.ts\";\nexport * from \"./path.ts\";\nexport * from \"./predicate/index.ts\";\nexport * from \"./process/index.ts\";\nexport * from \"./set/index.ts\";\nexport * from \"./source/index.ts\";\nexport * from \"./string/index.ts\";\n"]}
|
package/dist/path.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const isPathInside: (parent: string, candidate: string) => boolean;
|
|
2
|
+
declare const isPathWithin: (parent: string, candidate: string) => boolean;
|
|
3
|
+
declare const toPosixPath: (path: string) => string;
|
|
4
|
+
export { isPathInside, isPathWithin, toPosixPath };
|
|
5
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,OAIzD,CAAC;AAEF,QAAA,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,OACX,CAAC;AAEhD,QAAA,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MAAoC,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/path.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isAbsolute, relative, sep } from "node:path";
|
|
2
|
+
const isOutsidePath = (path) => path === ".." || path.startsWith(`..${sep}`) || isAbsolute(path);
|
|
3
|
+
const isPathInside = (parent, candidate) => {
|
|
4
|
+
const path = relative(parent, candidate);
|
|
5
|
+
return path !== "" && !isOutsidePath(path);
|
|
6
|
+
};
|
|
7
|
+
const isPathWithin = (parent, candidate) => !isOutsidePath(relative(parent, candidate));
|
|
8
|
+
const toPosixPath = (path) => path.replaceAll("\\", "/");
|
|
9
|
+
export { isPathInside, isPathWithin, toPosixPath };
|
|
10
|
+
//# sourceMappingURL=path.js.map
|
package/dist/path.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,aAAa,GAAG,CAAC,IAAY,EAAW,EAAE,CAC5C,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAErE,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,SAAiB,EAAW,EAAE;IAChE,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEzC,OAAO,IAAI,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,SAAiB,EAAW,EAAE,CAChE,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAEhD,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { isAbsolute, relative, sep } from \"node:path\";\n\nconst isOutsidePath = (path: string): boolean =>\n path === \"..\" || path.startsWith(`..${sep}`) || isAbsolute(path);\n\nconst isPathInside = (parent: string, candidate: string): boolean => {\n const path = relative(parent, candidate);\n\n return path !== \"\" && !isOutsidePath(path);\n};\n\nconst isPathWithin = (parent: string, candidate: string): boolean =>\n !isOutsidePath(relative(parent, candidate));\n\nconst toPosixPath = (path: string): string => path.replaceAll(\"\\\\\", \"/\");\n\nexport { isPathInside, isPathWithin, toPosixPath };\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare
|
|
2
|
-
declare
|
|
1
|
+
declare const tryResolveExecutable: (command: string) => string | undefined;
|
|
2
|
+
declare const resolveExecutable: (command: string) => string;
|
|
3
3
|
export { resolveExecutable, tryResolveExecutable };
|
|
4
4
|
//# sourceMappingURL=resolve-executable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-executable.d.ts","sourceRoot":"","sources":["../../src/process/resolve-executable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve-executable.d.ts","sourceRoot":"","sources":["../../src/process/resolve-executable.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,oBAAoB,GAAI,SAAS,MAAM,KAAG,MAAM,GAAG,SACF,CAAC;AAExD,QAAA,MAAM,iBAAiB,GAAI,SAAS,MAAM,KAAG,MAA6B,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -1,39 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
try {
|
|
5
|
-
accessSync(path, constants.X_OK);
|
|
6
|
-
return statSync(path).isFile();
|
|
7
|
-
}
|
|
8
|
-
catch {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
const findOnPath = (command) => {
|
|
13
|
-
const searchPaths = (process.env.PATH ?? "").split(delimiter).filter((entry) => entry.length > 0);
|
|
14
|
-
for (const directory of searchPaths) {
|
|
15
|
-
const candidate = join(directory, command);
|
|
16
|
-
if (isExecutable(candidate)) {
|
|
17
|
-
return candidate;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
21
|
-
};
|
|
22
|
-
function tryResolveExecutable(command) {
|
|
23
|
-
if (isAbsolute(command)) {
|
|
24
|
-
return command;
|
|
25
|
-
}
|
|
26
|
-
if (command.includes("/")) {
|
|
27
|
-
return resolve(command);
|
|
28
|
-
}
|
|
29
|
-
return findOnPath(command);
|
|
30
|
-
}
|
|
31
|
-
function resolveExecutable(command) {
|
|
32
|
-
const found = tryResolveExecutable(command);
|
|
33
|
-
if (found === undefined) {
|
|
34
|
-
throw new Error(`Cannot find the "${command}" executable on PATH`);
|
|
35
|
-
}
|
|
36
|
-
return found;
|
|
37
|
-
}
|
|
1
|
+
import which from "which";
|
|
2
|
+
const tryResolveExecutable = (command) => which.sync(command, { nothrow: true }) ?? undefined;
|
|
3
|
+
const resolveExecutable = (command) => which.sync(command);
|
|
38
4
|
export { resolveExecutable, tryResolveExecutable };
|
|
39
5
|
//# sourceMappingURL=resolve-executable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-executable.js","sourceRoot":"","sources":["../../src/process/resolve-executable.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"resolve-executable.js","sourceRoot":"","sources":["../../src/process/resolve-executable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAsB,EAAE,CACjE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,SAAS,CAAC;AAExD,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import which from \"which\";\n\nconst tryResolveExecutable = (command: string): string | undefined =>\n which.sync(command, { nothrow: true }) ?? undefined;\n\nconst resolveExecutable = (command: string): string => which.sync(command);\n\nexport { resolveExecutable, tryResolveExecutable };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Shared utilities for the GTK toolchain: logging, errors, strings.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtkx",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"./package.json": "./package.json",
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": null,
|
|
29
31
|
"default": "./dist/index.js"
|
|
30
32
|
}
|
|
31
33
|
},
|
|
@@ -45,10 +47,14 @@
|
|
|
45
47
|
}
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
|
-
"picocolors": "^1.1.1"
|
|
50
|
+
"picocolors": "^1.1.1",
|
|
51
|
+
"which": "^7.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/which": "^3.0.4"
|
|
49
55
|
},
|
|
50
56
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
57
|
+
"node": ">=26.7.0"
|
|
52
58
|
},
|
|
53
59
|
"scripts": {
|
|
54
60
|
"release": "tsx ../../scripts/release-package.ts"
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,8 @@ export * from "./array/index.ts";
|
|
|
2
2
|
export * from "./class/index.ts";
|
|
3
3
|
export * from "./error/index.ts";
|
|
4
4
|
export * from "./log/index.ts";
|
|
5
|
-
export * from "./map/index.ts";
|
|
6
5
|
export * from "./object/index.ts";
|
|
6
|
+
export * from "./path.ts";
|
|
7
7
|
export * from "./predicate/index.ts";
|
|
8
8
|
export * from "./process/index.ts";
|
|
9
9
|
export * from "./set/index.ts";
|
package/src/path.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isAbsolute, relative, sep } from "node:path";
|
|
2
|
+
|
|
3
|
+
const isOutsidePath = (path: string): boolean =>
|
|
4
|
+
path === ".." || path.startsWith(`..${sep}`) || isAbsolute(path);
|
|
5
|
+
|
|
6
|
+
const isPathInside = (parent: string, candidate: string): boolean => {
|
|
7
|
+
const path = relative(parent, candidate);
|
|
8
|
+
|
|
9
|
+
return path !== "" && !isOutsidePath(path);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const isPathWithin = (parent: string, candidate: string): boolean =>
|
|
13
|
+
!isOutsidePath(relative(parent, candidate));
|
|
14
|
+
|
|
15
|
+
const toPosixPath = (path: string): string => path.replaceAll("\\", "/");
|
|
16
|
+
|
|
17
|
+
export { isPathInside, isPathWithin, toPosixPath };
|
|
@@ -1,50 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
1
|
+
import which from "which";
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
accessSync(path, constants.X_OK);
|
|
3
|
+
const tryResolveExecutable = (command: string): string | undefined =>
|
|
4
|
+
which.sync(command, { nothrow: true }) ?? undefined;
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
} catch {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const findOnPath = (command: string): string | undefined => {
|
|
15
|
-
const searchPaths = (process.env.PATH ?? "").split(delimiter).filter((entry) => entry.length > 0);
|
|
16
|
-
|
|
17
|
-
for (const directory of searchPaths) {
|
|
18
|
-
const candidate = join(directory, command);
|
|
19
|
-
|
|
20
|
-
if (isExecutable(candidate)) {
|
|
21
|
-
return candidate;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return undefined;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function tryResolveExecutable(command: string): string | undefined {
|
|
29
|
-
if (isAbsolute(command)) {
|
|
30
|
-
return command;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (command.includes("/")) {
|
|
34
|
-
return resolve(command);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return findOnPath(command);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function resolveExecutable(command: string): string {
|
|
41
|
-
const found = tryResolveExecutable(command);
|
|
42
|
-
|
|
43
|
-
if (found === undefined) {
|
|
44
|
-
throw new Error(`Cannot find the "${command}" executable on PATH`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return found;
|
|
48
|
-
}
|
|
6
|
+
const resolveExecutable = (command: string): string => which.sync(command);
|
|
49
7
|
|
|
50
8
|
export { resolveExecutable, tryResolveExecutable };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
type GetSet<K, V> = {
|
|
2
|
-
get(key: K): V | undefined;
|
|
3
|
-
set(key: K, value: V): unknown;
|
|
4
|
-
has(key: K): boolean;
|
|
5
|
-
};
|
|
6
|
-
declare function getOrInsert<K, V>(map: GetSet<K, V>, key: K, factory: (key: K) => V): V;
|
|
7
|
-
export { getOrInsert };
|
|
8
|
-
//# sourceMappingURL=get-or-insert.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-or-insert.d.ts","sourceRoot":"","sources":["../../src/map/get-or-insert.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI;IAChB,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC;IAC/B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,iBAAS,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAS/E;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-or-insert.js","sourceRoot":"","sources":["../../src/map/get-or-insert.ts"],"names":[],"mappings":"AAMA,SAAS,WAAW,CAAO,GAAiB,EAAE,GAAM,EAAE,OAAsB;IACxE,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAM,CAAC;IAC7B,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEpB,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["type GetSet<K, V> = {\n get(key: K): V | undefined;\n set(key: K, value: V): unknown;\n has(key: K): boolean;\n};\n\nfunction getOrInsert<K, V>(map: GetSet<K, V>, key: K, factory: (key: K) => V): V {\n if (map.has(key)) {\n return map.get(key) as V;\n }\n\n const value = factory(key);\n map.set(key, value);\n\n return value;\n}\n\nexport { getOrInsert };\n"]}
|
package/dist/map/index.d.ts
DELETED
package/dist/map/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/map/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/map/index.js
DELETED
package/dist/map/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/map/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { getOrInsert } from \"./get-or-insert.ts\";\n"]}
|
package/src/map/get-or-insert.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
type GetSet<K, V> = {
|
|
2
|
-
get(key: K): V | undefined;
|
|
3
|
-
set(key: K, value: V): unknown;
|
|
4
|
-
has(key: K): boolean;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
function getOrInsert<K, V>(map: GetSet<K, V>, key: K, factory: (key: K) => V): V {
|
|
8
|
-
if (map.has(key)) {
|
|
9
|
-
return map.get(key) as V;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const value = factory(key);
|
|
13
|
-
map.set(key, value);
|
|
14
|
-
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { getOrInsert };
|
package/src/map/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { getOrInsert } from "./get-or-insert.ts";
|