@powerlines/plugin-id 0.9.130 → 0.9.132
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/dist/components/index.cjs +3 -2
- package/dist/components/index.d.cts +3 -1
- package/dist/components/index.d.mts +3 -1
- package/dist/components/index.mjs +2 -1
- package/dist/components/nanoid.cjs +2 -103
- package/dist/components/nanoid.d.cts +2 -12
- package/dist/components/nanoid.d.mts +2 -12
- package/dist/components/nanoid.mjs +1 -102
- package/dist/components-BWLXb7a2.cjs +0 -0
- package/dist/components-kh0CpIG2.mjs +1 -0
- package/dist/index-9iG2qHLe.d.mts +1 -0
- package/dist/index-D4ELpJXS.d.cts +1 -0
- package/dist/index-D6CnpA_r.d.cts +1 -0
- package/dist/index-DL0uimUT.d.mts +1 -0
- package/dist/index.cjs +35 -6
- package/dist/index.d.cts +4 -3
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +4 -2
- package/dist/nanoid-BnZ5rqH7.d.cts +13 -0
- package/dist/nanoid-CDBSPS2R.d.mts +13 -0
- package/dist/nanoid-Ck7ultxE.mjs +122 -0
- package/dist/nanoid-DvIF2L1a.cjs +128 -0
- package/dist/plugin-C39QU9V6.d.mts +1789 -0
- package/dist/plugin-ifZVa20V.mjs +1 -0
- package/dist/plugin-mX-X7dCb.d.cts +1789 -0
- package/dist/plugin-pBKbb5K9.cjs +0 -0
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.d.cts +2 -1
- package/dist/types/index.d.mts +2 -1
- package/dist/types/index.mjs +3 -0
- package/dist/types/plugin.cjs +1 -0
- package/dist/types/plugin.d.cts +1 -37
- package/dist/types/plugin.d.mts +1 -37
- package/dist/types/plugin.mjs +2 -0
- package/dist/types-U3zd8PTP.mjs +1 -0
- package/dist/types-o3zWarRp.cjs +0 -0
- package/package.json +4 -4
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/powerlines/src/lib/utilities/file-header.cjs +0 -22
- package/dist/powerlines/src/lib/utilities/file-header.mjs +0 -21
- package/dist/powerlines/src/types/babel.d.mts +0 -2
- package/dist/powerlines/src/types/build.d.cts +0 -145
- package/dist/powerlines/src/types/build.d.mts +0 -145
- package/dist/powerlines/src/types/commands.d.cts +0 -8
- package/dist/powerlines/src/types/commands.d.mts +0 -9
- package/dist/powerlines/src/types/config.d.cts +0 -369
- package/dist/powerlines/src/types/config.d.mts +0 -369
- package/dist/powerlines/src/types/context.d.cts +0 -403
- package/dist/powerlines/src/types/context.d.mts +0 -405
- package/dist/powerlines/src/types/fs.d.cts +0 -486
- package/dist/powerlines/src/types/fs.d.mts +0 -486
- package/dist/powerlines/src/types/hooks.d.mts +0 -2
- package/dist/powerlines/src/types/plugin.d.cts +0 -231
- package/dist/powerlines/src/types/plugin.d.mts +0 -231
- package/dist/powerlines/src/types/resolved.d.cts +0 -81
- package/dist/powerlines/src/types/resolved.d.mts +0 -81
- package/dist/powerlines/src/types/tsconfig.d.cts +0 -69
- package/dist/powerlines/src/types/tsconfig.d.mts +0 -69
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_nanoid = require('../nanoid-DvIF2L1a.cjs');
|
|
2
|
+
require('../components-BWLXb7a2.cjs');
|
|
2
3
|
|
|
3
|
-
exports.nanoidModule =
|
|
4
|
+
exports.nanoidModule = require_nanoid.nanoidModule;
|
|
@@ -1,104 +1,3 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_nanoid = require('../nanoid-DvIF2L1a.cjs');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generates the nanoid module content.
|
|
6
|
-
*
|
|
7
|
-
* @param context - The build context containing runtime information.
|
|
8
|
-
* @returns A string representing the nanoid module code.
|
|
9
|
-
*/
|
|
10
|
-
function nanoidModule(context) {
|
|
11
|
-
return `
|
|
12
|
-
/**
|
|
13
|
-
* The ID module provides a set of utilities for generating unique identifiers.
|
|
14
|
-
*
|
|
15
|
-
* @module ${context.config.output.builtinPrefix}:id
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
${require_file_header.getFileHeader(context)}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Generate a random string
|
|
22
|
-
*
|
|
23
|
-
* @param array - The array to fill with random values
|
|
24
|
-
* @returns The array filled with random values
|
|
25
|
-
*/
|
|
26
|
-
export function getRandom(array: Uint8Array) {
|
|
27
|
-
if (array === null) {
|
|
28
|
-
throw new StormError({ type: "general", code: 9 });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Fill the array with random values
|
|
32
|
-
for (let i = 0; i < array.length; i++) {
|
|
33
|
-
array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return array;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
41
|
-
*
|
|
42
|
-
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
43
|
-
* @returns A unique identifier following the nanoid format
|
|
44
|
-
*/
|
|
45
|
-
export function uniqueId(size?: number | undefined): string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
49
|
-
*
|
|
50
|
-
* @param prefix - The prefix to use for the unique identifier
|
|
51
|
-
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
52
|
-
* @returns A unique identifier following the nanoid format
|
|
53
|
-
*/
|
|
54
|
-
export function uniqueId(prefix?: string, size?: number | undefined): string;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
58
|
-
*
|
|
59
|
-
* @param param - The parameter to use for the unique identifier, can be a string or number
|
|
60
|
-
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
61
|
-
* @returns A unique identifier following the nanoid format
|
|
62
|
-
*/
|
|
63
|
-
export function uniqueId(param?: string | number | undefined, size?: number | undefined): string {
|
|
64
|
-
if (typeof param === "number") {
|
|
65
|
-
size = param;
|
|
66
|
-
} else if (!param || !size) {
|
|
67
|
-
size = 21; // Default size if not provided
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Use our custom getRandom function to fill a Uint8Array with random values.
|
|
71
|
-
const randomBytes = getRandom(new Uint8Array(typeof param === "string" ? size - (param.length + 1) : size));
|
|
72
|
-
|
|
73
|
-
let result = "";
|
|
74
|
-
if (typeof param === "string") {
|
|
75
|
-
// If the parameter is a string, use it as a prefix.
|
|
76
|
-
result = param + "_";
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return result + randomBytes.reduce((id, byte) => {
|
|
80
|
-
// It is incorrect to use bytes exceeding the alphabet size.
|
|
81
|
-
// The following mask reduces the random byte in the 0-255 value
|
|
82
|
-
// range to the 0-63 value range. Therefore, adding hacks, such
|
|
83
|
-
// as empty string fallback or magic numbers, is unnecessary because
|
|
84
|
-
// the bitmask trims bytes down to the alphabet size.
|
|
85
|
-
byte &= 63;
|
|
86
|
-
if (byte < 36) {
|
|
87
|
-
// \`0-9a-z\`
|
|
88
|
-
id += byte.toString(36);
|
|
89
|
-
} else if (byte < 62) {
|
|
90
|
-
// \`A-Z\`
|
|
91
|
-
id += (byte - 26).toString(36).toUpperCase();
|
|
92
|
-
} else if (byte > 62) {
|
|
93
|
-
id += "-";
|
|
94
|
-
} else {
|
|
95
|
-
id += "_";
|
|
96
|
-
}
|
|
97
|
-
return id;
|
|
98
|
-
}, "");
|
|
99
|
-
}
|
|
100
|
-
`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
exports.nanoidModule = nanoidModule;
|
|
3
|
+
exports.nanoidModule = require_nanoid.nanoidModule;
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/components/nanoid.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generates the nanoid module content.
|
|
7
|
-
*
|
|
8
|
-
* @param context - The build context containing runtime information.
|
|
9
|
-
* @returns A string representing the nanoid module code.
|
|
10
|
-
*/
|
|
11
|
-
declare function nanoidModule(context: IdPluginContext): string;
|
|
12
|
-
//#endregion
|
|
1
|
+
import "../plugin-mX-X7dCb.cjs";
|
|
2
|
+
import { t as nanoidModule } from "../nanoid-BnZ5rqH7.cjs";
|
|
13
3
|
export { nanoidModule };
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/components/nanoid.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generates the nanoid module content.
|
|
7
|
-
*
|
|
8
|
-
* @param context - The build context containing runtime information.
|
|
9
|
-
* @returns A string representing the nanoid module code.
|
|
10
|
-
*/
|
|
11
|
-
declare function nanoidModule(context: IdPluginContext): string;
|
|
12
|
-
//#endregion
|
|
1
|
+
import "../plugin-C39QU9V6.mjs";
|
|
2
|
+
import { t as nanoidModule } from "../nanoid-CDBSPS2R.mjs";
|
|
13
3
|
export { nanoidModule };
|
|
@@ -1,104 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as nanoidModule } from "../nanoid-Ck7ultxE.mjs";
|
|
2
2
|
|
|
3
|
-
//#region src/components/nanoid.ts
|
|
4
|
-
/**
|
|
5
|
-
* Generates the nanoid module content.
|
|
6
|
-
*
|
|
7
|
-
* @param context - The build context containing runtime information.
|
|
8
|
-
* @returns A string representing the nanoid module code.
|
|
9
|
-
*/
|
|
10
|
-
function nanoidModule(context) {
|
|
11
|
-
return `
|
|
12
|
-
/**
|
|
13
|
-
* The ID module provides a set of utilities for generating unique identifiers.
|
|
14
|
-
*
|
|
15
|
-
* @module ${context.config.output.builtinPrefix}:id
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
${getFileHeader(context)}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Generate a random string
|
|
22
|
-
*
|
|
23
|
-
* @param array - The array to fill with random values
|
|
24
|
-
* @returns The array filled with random values
|
|
25
|
-
*/
|
|
26
|
-
export function getRandom(array: Uint8Array) {
|
|
27
|
-
if (array === null) {
|
|
28
|
-
throw new StormError({ type: "general", code: 9 });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Fill the array with random values
|
|
32
|
-
for (let i = 0; i < array.length; i++) {
|
|
33
|
-
array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return array;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
41
|
-
*
|
|
42
|
-
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
43
|
-
* @returns A unique identifier following the nanoid format
|
|
44
|
-
*/
|
|
45
|
-
export function uniqueId(size?: number | undefined): string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
49
|
-
*
|
|
50
|
-
* @param prefix - The prefix to use for the unique identifier
|
|
51
|
-
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
52
|
-
* @returns A unique identifier following the nanoid format
|
|
53
|
-
*/
|
|
54
|
-
export function uniqueId(prefix?: string, size?: number | undefined): string;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
58
|
-
*
|
|
59
|
-
* @param param - The parameter to use for the unique identifier, can be a string or number
|
|
60
|
-
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
61
|
-
* @returns A unique identifier following the nanoid format
|
|
62
|
-
*/
|
|
63
|
-
export function uniqueId(param?: string | number | undefined, size?: number | undefined): string {
|
|
64
|
-
if (typeof param === "number") {
|
|
65
|
-
size = param;
|
|
66
|
-
} else if (!param || !size) {
|
|
67
|
-
size = 21; // Default size if not provided
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Use our custom getRandom function to fill a Uint8Array with random values.
|
|
71
|
-
const randomBytes = getRandom(new Uint8Array(typeof param === "string" ? size - (param.length + 1) : size));
|
|
72
|
-
|
|
73
|
-
let result = "";
|
|
74
|
-
if (typeof param === "string") {
|
|
75
|
-
// If the parameter is a string, use it as a prefix.
|
|
76
|
-
result = param + "_";
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return result + randomBytes.reduce((id, byte) => {
|
|
80
|
-
// It is incorrect to use bytes exceeding the alphabet size.
|
|
81
|
-
// The following mask reduces the random byte in the 0-255 value
|
|
82
|
-
// range to the 0-63 value range. Therefore, adding hacks, such
|
|
83
|
-
// as empty string fallback or magic numbers, is unnecessary because
|
|
84
|
-
// the bitmask trims bytes down to the alphabet size.
|
|
85
|
-
byte &= 63;
|
|
86
|
-
if (byte < 36) {
|
|
87
|
-
// \`0-9a-z\`
|
|
88
|
-
id += byte.toString(36);
|
|
89
|
-
} else if (byte < 62) {
|
|
90
|
-
// \`A-Z\`
|
|
91
|
-
id += (byte - 26).toString(36).toUpperCase();
|
|
92
|
-
} else if (byte > 62) {
|
|
93
|
-
id += "-";
|
|
94
|
-
} else {
|
|
95
|
-
id += "_";
|
|
96
|
-
}
|
|
97
|
-
return id;
|
|
98
|
-
}, "");
|
|
99
|
-
}
|
|
100
|
-
`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
3
|
export { nanoidModule };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
//#region rolldown:runtime
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
const require_nanoid = require('./nanoid-DvIF2L1a.cjs');
|
|
30
|
+
require('./components-BWLXb7a2.cjs');
|
|
31
|
+
require('./plugin-pBKbb5K9.cjs');
|
|
32
|
+
require('./types-o3zWarRp.cjs');
|
|
5
33
|
let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
6
34
|
let defu = require("defu");
|
|
7
|
-
defu =
|
|
35
|
+
defu = __toESM(defu);
|
|
8
36
|
|
|
9
37
|
//#region src/index.ts
|
|
10
38
|
/**
|
|
@@ -29,7 +57,7 @@ function plugin(options = {}) {
|
|
|
29
57
|
switch (this.config.id.type) {
|
|
30
58
|
case "nanoid":
|
|
31
59
|
default:
|
|
32
|
-
idModule =
|
|
60
|
+
idModule = require_nanoid.nanoidModule;
|
|
33
61
|
break;
|
|
34
62
|
}
|
|
35
63
|
await this.emitBuiltin(await Promise.resolve(idModule(this)), "id", "id.ts");
|
|
@@ -39,6 +67,7 @@ function plugin(options = {}) {
|
|
|
39
67
|
var src_default = plugin;
|
|
40
68
|
|
|
41
69
|
//#endregion
|
|
70
|
+
exports.__toESM = __toESM;
|
|
42
71
|
exports.default = src_default;
|
|
43
|
-
exports.nanoidModule =
|
|
72
|
+
exports.nanoidModule = require_nanoid.nanoidModule;
|
|
44
73
|
exports.plugin = plugin;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Plugin } from "./
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { a as UniqueIdFormatType, c as __ΩIdPluginResolvedConfig, d as Plugin, i as IdPluginUserConfig, l as __ΩIdPluginUserConfig, n as IdPluginOptions, o as __ΩIdPluginContext, r as IdPluginResolvedConfig, s as __ΩIdPluginOptions, t as IdPluginContext, u as __ΩUniqueIdFormatType } from "./plugin-mX-X7dCb.cjs";
|
|
2
|
+
import { t as nanoidModule } from "./nanoid-BnZ5rqH7.cjs";
|
|
3
|
+
import "./index-D6CnpA_r.cjs";
|
|
4
|
+
import "./index-D4ELpJXS.cjs";
|
|
4
5
|
|
|
5
6
|
//#region src/index.d.ts
|
|
6
7
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Plugin } from "./
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import "./
|
|
5
|
-
import "./types/index.mjs";
|
|
1
|
+
import { a as UniqueIdFormatType, c as __ΩIdPluginResolvedConfig, d as Plugin, i as IdPluginUserConfig, l as __ΩIdPluginUserConfig, n as IdPluginOptions, o as __ΩIdPluginContext, r as IdPluginResolvedConfig, s as __ΩIdPluginOptions, t as IdPluginContext, u as __ΩUniqueIdFormatType } from "./plugin-C39QU9V6.mjs";
|
|
2
|
+
import { t as nanoidModule } from "./nanoid-CDBSPS2R.mjs";
|
|
3
|
+
import "./index-DL0uimUT.mjs";
|
|
4
|
+
import "./index-9iG2qHLe.mjs";
|
|
6
5
|
|
|
7
6
|
//#region src/index.d.ts
|
|
7
|
+
|
|
8
8
|
/**
|
|
9
9
|
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
10
10
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { nanoidModule } from "./
|
|
2
|
-
import "./components
|
|
1
|
+
import { t as nanoidModule } from "./nanoid-Ck7ultxE.mjs";
|
|
2
|
+
import "./components-kh0CpIG2.mjs";
|
|
3
|
+
import "./plugin-ifZVa20V.mjs";
|
|
4
|
+
import "./types-U3zd8PTP.mjs";
|
|
3
5
|
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
4
6
|
import defu from "defu";
|
|
5
7
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as IdPluginContext } from "./plugin-mX-X7dCb.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/components/nanoid.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates the nanoid module content.
|
|
7
|
+
*
|
|
8
|
+
* @param context - The build context containing runtime information.
|
|
9
|
+
* @returns A string representing the nanoid module code.
|
|
10
|
+
*/
|
|
11
|
+
declare function nanoidModule(context: IdPluginContext): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { nanoidModule as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as IdPluginContext } from "./plugin-C39QU9V6.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/components/nanoid.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates the nanoid module content.
|
|
7
|
+
*
|
|
8
|
+
* @param context - The build context containing runtime information.
|
|
9
|
+
* @returns A string representing the nanoid module code.
|
|
10
|
+
*/
|
|
11
|
+
declare function nanoidModule(context: IdPluginContext): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { nanoidModule as t };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
2
|
+
|
|
3
|
+
//#region ../powerlines/src/lib/utilities/file-header.ts
|
|
4
|
+
function getBaseFileHeader(context) {
|
|
5
|
+
return `
|
|
6
|
+
// Generated with ${titleCase(context.config.framework)}
|
|
7
|
+
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
8
|
+
`;
|
|
9
|
+
}
|
|
10
|
+
function getFileHeader(context, options = {}) {
|
|
11
|
+
const { directive = null, prettierIgnore = false } = options;
|
|
12
|
+
return `/* eslint-disable */
|
|
13
|
+
// biome-ignore lint: disable
|
|
14
|
+
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `\n\n${directive}\n` : "\n"}
|
|
15
|
+
${getBaseFileHeader(context)}
|
|
16
|
+
|
|
17
|
+
`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/components/nanoid.ts
|
|
22
|
+
/**
|
|
23
|
+
* Generates the nanoid module content.
|
|
24
|
+
*
|
|
25
|
+
* @param context - The build context containing runtime information.
|
|
26
|
+
* @returns A string representing the nanoid module code.
|
|
27
|
+
*/
|
|
28
|
+
function nanoidModule(context) {
|
|
29
|
+
return `
|
|
30
|
+
/**
|
|
31
|
+
* The ID module provides a set of utilities for generating unique identifiers.
|
|
32
|
+
*
|
|
33
|
+
* @module ${context.config.output.builtinPrefix}:id
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
${getFileHeader(context)}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generate a random string
|
|
40
|
+
*
|
|
41
|
+
* @param array - The array to fill with random values
|
|
42
|
+
* @returns The array filled with random values
|
|
43
|
+
*/
|
|
44
|
+
export function getRandom(array: Uint8Array) {
|
|
45
|
+
if (array === null) {
|
|
46
|
+
throw new StormError({ type: "general", code: 9 });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Fill the array with random values
|
|
50
|
+
for (let i = 0; i < array.length; i++) {
|
|
51
|
+
array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return array;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
59
|
+
*
|
|
60
|
+
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
61
|
+
* @returns A unique identifier following the nanoid format
|
|
62
|
+
*/
|
|
63
|
+
export function uniqueId(size?: number | undefined): string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
67
|
+
*
|
|
68
|
+
* @param prefix - The prefix to use for the unique identifier
|
|
69
|
+
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
70
|
+
* @returns A unique identifier following the nanoid format
|
|
71
|
+
*/
|
|
72
|
+
export function uniqueId(prefix?: string, size?: number | undefined): string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
76
|
+
*
|
|
77
|
+
* @param param - The parameter to use for the unique identifier, can be a string or number
|
|
78
|
+
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
79
|
+
* @returns A unique identifier following the nanoid format
|
|
80
|
+
*/
|
|
81
|
+
export function uniqueId(param?: string | number | undefined, size?: number | undefined): string {
|
|
82
|
+
if (typeof param === "number") {
|
|
83
|
+
size = param;
|
|
84
|
+
} else if (!param || !size) {
|
|
85
|
+
size = 21; // Default size if not provided
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Use our custom getRandom function to fill a Uint8Array with random values.
|
|
89
|
+
const randomBytes = getRandom(new Uint8Array(typeof param === "string" ? size - (param.length + 1) : size));
|
|
90
|
+
|
|
91
|
+
let result = "";
|
|
92
|
+
if (typeof param === "string") {
|
|
93
|
+
// If the parameter is a string, use it as a prefix.
|
|
94
|
+
result = param + "_";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return result + randomBytes.reduce((id, byte) => {
|
|
98
|
+
// It is incorrect to use bytes exceeding the alphabet size.
|
|
99
|
+
// The following mask reduces the random byte in the 0-255 value
|
|
100
|
+
// range to the 0-63 value range. Therefore, adding hacks, such
|
|
101
|
+
// as empty string fallback or magic numbers, is unnecessary because
|
|
102
|
+
// the bitmask trims bytes down to the alphabet size.
|
|
103
|
+
byte &= 63;
|
|
104
|
+
if (byte < 36) {
|
|
105
|
+
// \`0-9a-z\`
|
|
106
|
+
id += byte.toString(36);
|
|
107
|
+
} else if (byte < 62) {
|
|
108
|
+
// \`A-Z\`
|
|
109
|
+
id += (byte - 26).toString(36).toUpperCase();
|
|
110
|
+
} else if (byte > 62) {
|
|
111
|
+
id += "-";
|
|
112
|
+
} else {
|
|
113
|
+
id += "_";
|
|
114
|
+
}
|
|
115
|
+
return id;
|
|
116
|
+
}, "");
|
|
117
|
+
}
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
export { nanoidModule as t };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const require_index = require('./index.cjs');
|
|
2
|
+
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
3
|
+
|
|
4
|
+
//#region ../powerlines/src/lib/utilities/file-header.ts
|
|
5
|
+
function getBaseFileHeader(context) {
|
|
6
|
+
return `
|
|
7
|
+
// Generated with ${(0, __stryke_string_format_title_case.titleCase)(context.config.framework)}
|
|
8
|
+
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
11
|
+
function getFileHeader(context, options = {}) {
|
|
12
|
+
const { directive = null, prettierIgnore = false } = options;
|
|
13
|
+
return `/* eslint-disable */
|
|
14
|
+
// biome-ignore lint: disable
|
|
15
|
+
${prettierIgnore ? `// prettier-ignore` : ""}${directive ? `\n\n${directive}\n` : "\n"}
|
|
16
|
+
${getBaseFileHeader(context)}
|
|
17
|
+
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/components/nanoid.ts
|
|
23
|
+
/**
|
|
24
|
+
* Generates the nanoid module content.
|
|
25
|
+
*
|
|
26
|
+
* @param context - The build context containing runtime information.
|
|
27
|
+
* @returns A string representing the nanoid module code.
|
|
28
|
+
*/
|
|
29
|
+
function nanoidModule(context) {
|
|
30
|
+
return `
|
|
31
|
+
/**
|
|
32
|
+
* The ID module provides a set of utilities for generating unique identifiers.
|
|
33
|
+
*
|
|
34
|
+
* @module ${context.config.output.builtinPrefix}:id
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
${getFileHeader(context)}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generate a random string
|
|
41
|
+
*
|
|
42
|
+
* @param array - The array to fill with random values
|
|
43
|
+
* @returns The array filled with random values
|
|
44
|
+
*/
|
|
45
|
+
export function getRandom(array: Uint8Array) {
|
|
46
|
+
if (array === null) {
|
|
47
|
+
throw new StormError({ type: "general", code: 9 });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Fill the array with random values
|
|
51
|
+
for (let i = 0; i < array.length; i++) {
|
|
52
|
+
array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return array;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
60
|
+
*
|
|
61
|
+
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
62
|
+
* @returns A unique identifier following the nanoid format
|
|
63
|
+
*/
|
|
64
|
+
export function uniqueId(size?: number | undefined): string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
68
|
+
*
|
|
69
|
+
* @param prefix - The prefix to use for the unique identifier
|
|
70
|
+
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
71
|
+
* @returns A unique identifier following the nanoid format
|
|
72
|
+
*/
|
|
73
|
+
export function uniqueId(prefix?: string, size?: number | undefined): string;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
|
|
77
|
+
*
|
|
78
|
+
* @param param - The parameter to use for the unique identifier, can be a string or number
|
|
79
|
+
* @param size - The size of the string to generate. Defaults to 21 if not provided.
|
|
80
|
+
* @returns A unique identifier following the nanoid format
|
|
81
|
+
*/
|
|
82
|
+
export function uniqueId(param?: string | number | undefined, size?: number | undefined): string {
|
|
83
|
+
if (typeof param === "number") {
|
|
84
|
+
size = param;
|
|
85
|
+
} else if (!param || !size) {
|
|
86
|
+
size = 21; // Default size if not provided
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Use our custom getRandom function to fill a Uint8Array with random values.
|
|
90
|
+
const randomBytes = getRandom(new Uint8Array(typeof param === "string" ? size - (param.length + 1) : size));
|
|
91
|
+
|
|
92
|
+
let result = "";
|
|
93
|
+
if (typeof param === "string") {
|
|
94
|
+
// If the parameter is a string, use it as a prefix.
|
|
95
|
+
result = param + "_";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return result + randomBytes.reduce((id, byte) => {
|
|
99
|
+
// It is incorrect to use bytes exceeding the alphabet size.
|
|
100
|
+
// The following mask reduces the random byte in the 0-255 value
|
|
101
|
+
// range to the 0-63 value range. Therefore, adding hacks, such
|
|
102
|
+
// as empty string fallback or magic numbers, is unnecessary because
|
|
103
|
+
// the bitmask trims bytes down to the alphabet size.
|
|
104
|
+
byte &= 63;
|
|
105
|
+
if (byte < 36) {
|
|
106
|
+
// \`0-9a-z\`
|
|
107
|
+
id += byte.toString(36);
|
|
108
|
+
} else if (byte < 62) {
|
|
109
|
+
// \`A-Z\`
|
|
110
|
+
id += (byte - 26).toString(36).toUpperCase();
|
|
111
|
+
} else if (byte > 62) {
|
|
112
|
+
id += "-";
|
|
113
|
+
} else {
|
|
114
|
+
id += "_";
|
|
115
|
+
}
|
|
116
|
+
return id;
|
|
117
|
+
}, "");
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
Object.defineProperty(exports, 'nanoidModule', {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function () {
|
|
126
|
+
return nanoidModule;
|
|
127
|
+
}
|
|
128
|
+
});
|