@powerlines/plugin-id 0.9.7 → 0.9.8

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.
@@ -0,0 +1,7 @@
1
+ 'use strict';/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ var c=Object.defineProperty;var d=(a,b)=>c(a,"name",{value:b,configurable:true});exports.a=d;
@@ -0,0 +1,7 @@
1
+ /*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ var c=Object.defineProperty;var d=(a,b)=>c(a,"name",{value:b,configurable:true});export{d as a};
@@ -0,0 +1 @@
1
+ 'use strict';var nanoid=require('./nanoid');Object.keys(nanoid).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return nanoid[k]}})});
@@ -0,0 +1,22 @@
1
+ export { nanoidModule } from './nanoid.cjs';
2
+ import '../index-CZ8NfQGb.cjs';
3
+ import '@storm-software/build-tools/types';
4
+ import '@storm-software/config-tools/types';
5
+ import '@storm-software/config/types';
6
+ import '@stryke/types/base';
7
+ import '@stryke/types/configuration';
8
+ import '@stryke/types/file';
9
+ import 'vite';
10
+ import '@stryke/env/get-env-paths';
11
+ import '@stryke/types/package-json';
12
+ import 'jiti';
13
+ import 'oxc-parser';
14
+ import 'semver';
15
+ import 'unplugin';
16
+ import '@stryke/types/tsconfig';
17
+ import 'typescript';
18
+ import '@stryke/json/types';
19
+ import 'memfs';
20
+ import 'node:fs';
21
+ import 'unionfs';
22
+ import '@stryke/types/array';
@@ -0,0 +1,22 @@
1
+ export { nanoidModule } from './nanoid.js';
2
+ import '../index-CZ8NfQGb.js';
3
+ import '@storm-software/build-tools/types';
4
+ import '@storm-software/config-tools/types';
5
+ import '@storm-software/config/types';
6
+ import '@stryke/types/base';
7
+ import '@stryke/types/configuration';
8
+ import '@stryke/types/file';
9
+ import 'vite';
10
+ import '@stryke/env/get-env-paths';
11
+ import '@stryke/types/package-json';
12
+ import 'jiti';
13
+ import 'oxc-parser';
14
+ import 'semver';
15
+ import 'unplugin';
16
+ import '@stryke/types/tsconfig';
17
+ import 'typescript';
18
+ import '@stryke/json/types';
19
+ import 'memfs';
20
+ import 'node:fs';
21
+ import 'unionfs';
22
+ import '@stryke/types/array';
@@ -0,0 +1 @@
1
+ export*from'./nanoid';
@@ -0,0 +1,96 @@
1
+ 'use strict';var chunkFBBMZ4NC_cjs=require('../chunk-FBBMZ4NC.cjs'),fileHeader=require('powerlines/lib/utilities/file-header');/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ function s(e){return `
8
+ /**
9
+ * The ID module provides a set of utilities for generating unique identifiers.
10
+ *
11
+ * @module ${e.config.output.builtinPrefix}:id
12
+ */
13
+
14
+ ${fileHeader.getFileHeader(e)}
15
+
16
+ /**
17
+ * Generate a random string
18
+ *
19
+ * @param array - The array to fill with random values
20
+ * @returns The array filled with random values
21
+ */
22
+ export function getRandom(array: Uint8Array) {
23
+ if (array === null) {
24
+ throw new StormError({ type: "general", code: 9 });
25
+ }
26
+
27
+ // Fill the array with random values
28
+ for (let i = 0; i < array.length; i++) {
29
+ array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)
30
+ }
31
+
32
+ return array;
33
+ }
34
+
35
+ /**
36
+ * A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
37
+ *
38
+ * @param size - The size of the string to generate. Defaults to 21 if not provided.
39
+ * @returns A unique identifier following the nanoid format
40
+ */
41
+ export function uniqueId(size?: number | undefined): string;
42
+
43
+ /**
44
+ * A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
45
+ *
46
+ * @param prefix - The prefix to use for the unique identifier
47
+ * @param size - The size of the string to generate. Defaults to 21 if not provided.
48
+ * @returns A unique identifier following the nanoid format
49
+ */
50
+ export function uniqueId(prefix?: string, size?: number | undefined): string;
51
+
52
+ /**
53
+ * A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
54
+ *
55
+ * @param param - The parameter to use for the unique identifier, can be a string or number
56
+ * @param size - The size of the string to generate. Defaults to 21 if not provided.
57
+ * @returns A unique identifier following the nanoid format
58
+ */
59
+ export function uniqueId(param?: string | number | undefined, size?: number | undefined): string {
60
+ if (typeof param === "number") {
61
+ size = param;
62
+ } else if (!param || !size) {
63
+ size = 21; // Default size if not provided
64
+ }
65
+
66
+ // Use our custom getRandom function to fill a Uint8Array with random values.
67
+ const randomBytes = getRandom(new Uint8Array(typeof param === "string" ? size - (param.length + 1) : size));
68
+
69
+ let result = "";
70
+ if (typeof param === "string") {
71
+ // If the parameter is a string, use it as a prefix.
72
+ result = param + "_";
73
+ }
74
+
75
+ return result + randomBytes.reduce((id, byte) => {
76
+ // It is incorrect to use bytes exceeding the alphabet size.
77
+ // The following mask reduces the random byte in the 0-255 value
78
+ // range to the 0-63 value range. Therefore, adding hacks, such
79
+ // as empty string fallback or magic numbers, is unnecessary because
80
+ // the bitmask trims bytes down to the alphabet size.
81
+ byte &= 63;
82
+ if (byte < 36) {
83
+ // \`0-9a-z\`
84
+ id += byte.toString(36);
85
+ } else if (byte < 62) {
86
+ // \`A-Z\`
87
+ id += (byte - 26).toString(36).toUpperCase();
88
+ } else if (byte > 62) {
89
+ id += "-";
90
+ } else {
91
+ id += "_";
92
+ }
93
+ return id;
94
+ }, "");
95
+ }
96
+ `}chunkFBBMZ4NC_cjs.a(s,"nanoidModule");exports.nanoidModule=s;
@@ -0,0 +1,31 @@
1
+ import { a as IdPluginContext } from '../index-CZ8NfQGb.cjs';
2
+ import '@storm-software/build-tools/types';
3
+ import '@storm-software/config-tools/types';
4
+ import '@storm-software/config/types';
5
+ import '@stryke/types/base';
6
+ import '@stryke/types/configuration';
7
+ import '@stryke/types/file';
8
+ import 'vite';
9
+ import '@stryke/env/get-env-paths';
10
+ import '@stryke/types/package-json';
11
+ import 'jiti';
12
+ import 'oxc-parser';
13
+ import 'semver';
14
+ import 'unplugin';
15
+ import '@stryke/types/tsconfig';
16
+ import 'typescript';
17
+ import '@stryke/json/types';
18
+ import 'memfs';
19
+ import 'node:fs';
20
+ import 'unionfs';
21
+ import '@stryke/types/array';
22
+
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
+ declare function nanoidModule(context: IdPluginContext): string;
30
+
31
+ export { nanoidModule };
@@ -0,0 +1,31 @@
1
+ import { a as IdPluginContext } from '../index-CZ8NfQGb.js';
2
+ import '@storm-software/build-tools/types';
3
+ import '@storm-software/config-tools/types';
4
+ import '@storm-software/config/types';
5
+ import '@stryke/types/base';
6
+ import '@stryke/types/configuration';
7
+ import '@stryke/types/file';
8
+ import 'vite';
9
+ import '@stryke/env/get-env-paths';
10
+ import '@stryke/types/package-json';
11
+ import 'jiti';
12
+ import 'oxc-parser';
13
+ import 'semver';
14
+ import 'unplugin';
15
+ import '@stryke/types/tsconfig';
16
+ import 'typescript';
17
+ import '@stryke/json/types';
18
+ import 'memfs';
19
+ import 'node:fs';
20
+ import 'unionfs';
21
+ import '@stryke/types/array';
22
+
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
+ declare function nanoidModule(context: IdPluginContext): string;
30
+
31
+ export { nanoidModule };
@@ -0,0 +1,96 @@
1
+ import {a}from'../chunk-UCUR73HG.js';import {getFileHeader}from'powerlines/lib/utilities/file-header';/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ function u(e){return `
8
+ /**
9
+ * The ID module provides a set of utilities for generating unique identifiers.
10
+ *
11
+ * @module ${e.config.output.builtinPrefix}:id
12
+ */
13
+
14
+ ${getFileHeader(e)}
15
+
16
+ /**
17
+ * Generate a random string
18
+ *
19
+ * @param array - The array to fill with random values
20
+ * @returns The array filled with random values
21
+ */
22
+ export function getRandom(array: Uint8Array) {
23
+ if (array === null) {
24
+ throw new StormError({ type: "general", code: 9 });
25
+ }
26
+
27
+ // Fill the array with random values
28
+ for (let i = 0; i < array.length; i++) {
29
+ array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)
30
+ }
31
+
32
+ return array;
33
+ }
34
+
35
+ /**
36
+ * A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
37
+ *
38
+ * @param size - The size of the string to generate. Defaults to 21 if not provided.
39
+ * @returns A unique identifier following the nanoid format
40
+ */
41
+ export function uniqueId(size?: number | undefined): string;
42
+
43
+ /**
44
+ * A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
45
+ *
46
+ * @param prefix - The prefix to use for the unique identifier
47
+ * @param size - The size of the string to generate. Defaults to 21 if not provided.
48
+ * @returns A unique identifier following the nanoid format
49
+ */
50
+ export function uniqueId(prefix?: string, size?: number | undefined): string;
51
+
52
+ /**
53
+ * A platform agnostic version of the [nanoid](https://github.com/ai/nanoid) package with some modifications.
54
+ *
55
+ * @param param - The parameter to use for the unique identifier, can be a string or number
56
+ * @param size - The size of the string to generate. Defaults to 21 if not provided.
57
+ * @returns A unique identifier following the nanoid format
58
+ */
59
+ export function uniqueId(param?: string | number | undefined, size?: number | undefined): string {
60
+ if (typeof param === "number") {
61
+ size = param;
62
+ } else if (!param || !size) {
63
+ size = 21; // Default size if not provided
64
+ }
65
+
66
+ // Use our custom getRandom function to fill a Uint8Array with random values.
67
+ const randomBytes = getRandom(new Uint8Array(typeof param === "string" ? size - (param.length + 1) : size));
68
+
69
+ let result = "";
70
+ if (typeof param === "string") {
71
+ // If the parameter is a string, use it as a prefix.
72
+ result = param + "_";
73
+ }
74
+
75
+ return result + randomBytes.reduce((id, byte) => {
76
+ // It is incorrect to use bytes exceeding the alphabet size.
77
+ // The following mask reduces the random byte in the 0-255 value
78
+ // range to the 0-63 value range. Therefore, adding hacks, such
79
+ // as empty string fallback or magic numbers, is unnecessary because
80
+ // the bitmask trims bytes down to the alphabet size.
81
+ byte &= 63;
82
+ if (byte < 36) {
83
+ // \`0-9a-z\`
84
+ id += byte.toString(36);
85
+ } else if (byte < 62) {
86
+ // \`A-Z\`
87
+ id += (byte - 26).toString(36).toUpperCase();
88
+ } else if (byte > 62) {
89
+ id += "-";
90
+ } else {
91
+ id += "_";
92
+ }
93
+ return id;
94
+ }, "");
95
+ }
96
+ `}a(u,"nanoidModule");export{u as nanoidModule};