@jsnw/srv-utils 1.1.4 → 1.2.0
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,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRandomString = createRandomString;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
/**
|
|
6
|
+
* @param {number} length The length of the string
|
|
7
|
+
* @return {Promise<string>}
|
|
8
|
+
*/
|
|
9
|
+
function createRandomString(length) {
|
|
10
|
+
if (length <= 0)
|
|
11
|
+
return Promise.resolve('');
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const bytesLength = Math.ceil(length / 2);
|
|
14
|
+
(0, node_crypto_1.randomBytes)(bytesLength, (err, buff) => {
|
|
15
|
+
if (err)
|
|
16
|
+
return reject(err);
|
|
17
|
+
const hexString = buff.toString('hex').slice(0, length);
|
|
18
|
+
return resolve(hexString);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withNest = exports.configSchemas = exports.ConfigLoader = exports.getRootPackageDirnameSync = exports.useTsconfigPaths = exports.fileExistsSync = exports.fileExists = void 0;
|
|
3
|
+
exports.createRandomString = exports.withNest = exports.configSchemas = exports.ConfigLoader = exports.getRootPackageDirnameSync = exports.useTsconfigPaths = exports.fileExistsSync = exports.fileExists = void 0;
|
|
4
4
|
var file_exists_1 = require("./file-exists");
|
|
5
5
|
Object.defineProperty(exports, "fileExists", { enumerable: true, get: function () { return file_exists_1.fileExists; } });
|
|
6
6
|
Object.defineProperty(exports, "fileExistsSync", { enumerable: true, get: function () { return file_exists_1.fileExistsSync; } });
|
|
@@ -13,3 +13,5 @@ Object.defineProperty(exports, "ConfigLoader", { enumerable: true, get: function
|
|
|
13
13
|
Object.defineProperty(exports, "configSchemas", { enumerable: true, get: function () { return config_1.configSchemas; } });
|
|
14
14
|
var withNest_1 = require("./withNest");
|
|
15
15
|
Object.defineProperty(exports, "withNest", { enumerable: true, get: function () { return withNest_1.withNest; } });
|
|
16
|
+
var create_random_string_1 = require("./create-random-string");
|
|
17
|
+
Object.defineProperty(exports, "createRandomString", { enumerable: true, get: function () { return create_random_string_1.createRandomString; } });
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { useTsconfigPaths } from './useTsconfigPaths';
|
|
|
3
3
|
export { getRootPackageDirnameSync } from './getRootPackageDirname';
|
|
4
4
|
export { ConfigLoader, configSchemas, type ResolvedConfig } from './config';
|
|
5
5
|
export { withNest } from './withNest';
|
|
6
|
+
export { createRandomString } from './create-random-string';
|
package/dist/useTsconfigPaths.js
CHANGED
|
@@ -17,9 +17,13 @@ function useTsconfigPaths({ basePath, tsconfigPath }) {
|
|
|
17
17
|
const tsconfig = require((0, node_path_1.resolve)(tsconfigPath)), tsconfigDirPathname = (0, node_path_1.dirname)(tsconfigPath), paths = {};
|
|
18
18
|
if (!basePath && !tsconfig?.compilerOptions?.baseUrl)
|
|
19
19
|
throw new TypeError('Either basePath option should be provided or tsconfig.json should contain compilerOptions.baseUrl property');
|
|
20
|
-
const baseUrl =
|
|
21
|
-
? (0, node_path_1.resolve)(
|
|
22
|
-
:
|
|
20
|
+
const baseUrl = basePath
|
|
21
|
+
? (0, node_path_1.resolve)(basePath)
|
|
22
|
+
: tsconfig?.compilerOptions?.baseUrl
|
|
23
|
+
? (0, node_path_1.resolve)(tsconfig.compilerOptions.baseUrl)
|
|
24
|
+
: undefined;
|
|
25
|
+
if (baseUrl === undefined)
|
|
26
|
+
throw new Error('Unable to resolve base path for tsconfig paths');
|
|
23
27
|
Object.entries((tsconfig?.compilerOptions?.paths ?? {}))
|
|
24
28
|
.forEach(([moduleName, pathArray]) => {
|
|
25
29
|
if (pathArray.length === 0)
|
package/package.json
CHANGED