@percuss.io/utils 0.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Eric L Carraway
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 ADDED
@@ -0,0 +1 @@
1
+ # https://www.npmjs.com/package/@percuss.io/utils
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ // src/isNonEmptyObj/isNonEmptyObj.ts
4
+ function isNonEmptyObj(value) {
5
+ return value !== null && typeof value === `object` && !Array.isArray(value) && Object.keys(value).length > 0;
6
+ }
7
+
8
+ exports.isNonEmptyObj = isNonEmptyObj;
@@ -0,0 +1,11 @@
1
+ // src/shuffleArray/shuffleArray.ts
2
+ function shuffleArray(array) {
3
+ const clonedArr = [...array];
4
+ for (let i = clonedArr.length - 1; i > 0; i -= 1) {
5
+ const j = Math.floor(Math.random() * (i + 1));
6
+ [clonedArr[i], clonedArr[j]] = [clonedArr[j], clonedArr[i]];
7
+ }
8
+ return clonedArr;
9
+ }
10
+
11
+ export { shuffleArray };
@@ -0,0 +1,6 @@
1
+ // src/isNonEmptyObj/isNonEmptyObj.ts
2
+ function isNonEmptyObj(value) {
3
+ return value !== null && typeof value === `object` && !Array.isArray(value) && Object.keys(value).length > 0;
4
+ }
5
+
6
+ export { isNonEmptyObj };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ // src/shuffleArray/shuffleArray.ts
4
+ function shuffleArray(array) {
5
+ const clonedArr = [...array];
6
+ for (let i = clonedArr.length - 1; i > 0; i -= 1) {
7
+ const j = Math.floor(Math.random() * (i + 1));
8
+ [clonedArr[i], clonedArr[j]] = [clonedArr[j], clonedArr[i]];
9
+ }
10
+ return clonedArr;
11
+ }
12
+
13
+ exports.shuffleArray = shuffleArray;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ // src/sleep/sleep.ts
4
+ function sleep(millis) {
5
+ if (typeof millis !== `number` || !Number.isFinite(millis) || millis < 0) {
6
+ throw new TypeError(
7
+ `sleep(millis): expected a non-negative finite number, got ${millis}`
8
+ );
9
+ }
10
+ return new Promise((resolve) => {
11
+ globalThis.setTimeout(resolve, millis);
12
+ });
13
+ }
14
+
15
+ exports.sleep = sleep;
@@ -0,0 +1,13 @@
1
+ // src/sleep/sleep.ts
2
+ function sleep(millis) {
3
+ if (typeof millis !== `number` || !Number.isFinite(millis) || millis < 0) {
4
+ throw new TypeError(
5
+ `sleep(millis): expected a non-negative finite number, got ${millis}`
6
+ );
7
+ }
8
+ return new Promise((resolve) => {
9
+ globalThis.setTimeout(resolve, millis);
10
+ });
11
+ }
12
+
13
+ export { sleep };
@@ -0,0 +1,3 @@
1
+ export { isNonEmptyObj } from './isNonEmptyObj/isNonEmptyObj.mjs';
2
+ export { shuffleArray } from './shuffleArray/shuffleArray.mjs';
3
+ export { sleep } from './sleep/sleep.mjs';
@@ -0,0 +1,3 @@
1
+ export { isNonEmptyObj } from './isNonEmptyObj/isNonEmptyObj.js';
2
+ export { shuffleArray } from './shuffleArray/shuffleArray.js';
3
+ export { sleep } from './sleep/sleep.js';
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var chunk2J4AIXWB_js = require('./chunk-2J4AIXWB.js');
4
+ var chunkS6VKMDVX_js = require('./chunk-S6VKMDVX.js');
5
+ var chunkTZ3Z56CI_js = require('./chunk-TZ3Z56CI.js');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "isNonEmptyObj", {
10
+ enumerable: true,
11
+ get: function () { return chunk2J4AIXWB_js.isNonEmptyObj; }
12
+ });
13
+ Object.defineProperty(exports, "shuffleArray", {
14
+ enumerable: true,
15
+ get: function () { return chunkS6VKMDVX_js.shuffleArray; }
16
+ });
17
+ Object.defineProperty(exports, "sleep", {
18
+ enumerable: true,
19
+ get: function () { return chunkTZ3Z56CI_js.sleep; }
20
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export { isNonEmptyObj } from './chunk-5XK774RW.mjs';
2
+ export { shuffleArray } from './chunk-55RT75P2.mjs';
3
+ export { sleep } from './chunk-WEF2NP5F.mjs';
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Validates if a value is a non-empty object (not null, not an array, has at least one property).
3
+ *
4
+ * @param value - The value to check
5
+ * @returns True if the value is a non-null object with at least one property
6
+ *
7
+ * @example
8
+ * // Returns true
9
+ * isNonEmptyObj({ foo: 'bar' });
10
+ *
11
+ * @example
12
+ * // Returns false
13
+ * isNonEmptyObj({});
14
+ * isNonEmptyObj(null);
15
+ * isNonEmptyObj(undefined);
16
+ * isNonEmptyObj([]);
17
+ * isNonEmptyObj('string');
18
+ * isNonEmptyObj(123);
19
+ */
20
+ declare function isNonEmptyObj(value: unknown): value is Record<string, unknown>;
21
+
22
+ export { isNonEmptyObj };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Validates if a value is a non-empty object (not null, not an array, has at least one property).
3
+ *
4
+ * @param value - The value to check
5
+ * @returns True if the value is a non-null object with at least one property
6
+ *
7
+ * @example
8
+ * // Returns true
9
+ * isNonEmptyObj({ foo: 'bar' });
10
+ *
11
+ * @example
12
+ * // Returns false
13
+ * isNonEmptyObj({});
14
+ * isNonEmptyObj(null);
15
+ * isNonEmptyObj(undefined);
16
+ * isNonEmptyObj([]);
17
+ * isNonEmptyObj('string');
18
+ * isNonEmptyObj(123);
19
+ */
20
+ declare function isNonEmptyObj(value: unknown): value is Record<string, unknown>;
21
+
22
+ export { isNonEmptyObj };
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var chunk2J4AIXWB_js = require('../chunk-2J4AIXWB.js');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "isNonEmptyObj", {
8
+ enumerable: true,
9
+ get: function () { return chunk2J4AIXWB_js.isNonEmptyObj; }
10
+ });
@@ -0,0 +1 @@
1
+ export { isNonEmptyObj } from '../chunk-5XK774RW.mjs';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The Fisher-Yates (also known as Knuth) shuffle algorithm.
3
+ * Returns a shuffled copy of the input array.
4
+ * @param array The array to shuffle
5
+ * @returns A new shuffled array
6
+ */
7
+ declare function shuffleArray<T>(array: readonly T[]): T[];
8
+
9
+ export { shuffleArray };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The Fisher-Yates (also known as Knuth) shuffle algorithm.
3
+ * Returns a shuffled copy of the input array.
4
+ * @param array The array to shuffle
5
+ * @returns A new shuffled array
6
+ */
7
+ declare function shuffleArray<T>(array: readonly T[]): T[];
8
+
9
+ export { shuffleArray };
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var chunkS6VKMDVX_js = require('../chunk-S6VKMDVX.js');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "shuffleArray", {
8
+ enumerable: true,
9
+ get: function () { return chunkS6VKMDVX_js.shuffleArray; }
10
+ });
@@ -0,0 +1 @@
1
+ export { shuffleArray } from '../chunk-55RT75P2.mjs';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Sleep for the specified number of milliseconds.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * await sleep(1000); // waits for 1 second
7
+ * ```
8
+ */
9
+ declare function sleep(millis: number): Promise<void>;
10
+
11
+ export { sleep };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Sleep for the specified number of milliseconds.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * await sleep(1000); // waits for 1 second
7
+ * ```
8
+ */
9
+ declare function sleep(millis: number): Promise<void>;
10
+
11
+ export { sleep };
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var chunkTZ3Z56CI_js = require('../chunk-TZ3Z56CI.js');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "sleep", {
8
+ enumerable: true,
9
+ get: function () { return chunkTZ3Z56CI_js.sleep; }
10
+ });
@@ -0,0 +1 @@
1
+ export { sleep } from '../chunk-WEF2NP5F.mjs';
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@percuss.io/utils",
3
+ "version": "0.0.1",
4
+ "description": "utils",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./isNonEmptyObj": {
15
+ "types": "./dist/isNonEmptyObj/isNonEmptyObj.d.ts",
16
+ "import": "./dist/isNonEmptyObj/isNonEmptyObj.js",
17
+ "require": "./dist/isNonEmptyObj/isNonEmptyObj.cjs"
18
+ },
19
+ "./shuffleArray": {
20
+ "types": "./dist/shuffleArray/shuffleArray.d.ts",
21
+ "import": "./dist/shuffleArray/shuffleArray.js",
22
+ "require": "./dist/shuffleArray/shuffleArray.cjs"
23
+ },
24
+ "./sleep": {
25
+ "types": "./dist/sleep/sleep.d.ts",
26
+ "import": "./dist/sleep/sleep.js",
27
+ "require": "./dist/sleep/sleep.cjs"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "lint": "eslint src",
36
+ "prerelease": "./scripts/prerelease.sh",
37
+ "shipit": "./scripts/publish.sh",
38
+ "test": "vitest run",
39
+ "test:watch": "vitest",
40
+ "typecheck": "tsc --noEmit"
41
+ },
42
+ "sideEffects": false,
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/percuss-io/utils.git"
46
+ },
47
+ "keywords": [],
48
+ "author": "",
49
+ "license": "MIT",
50
+ "type": "commonjs",
51
+ "bugs": {
52
+ "url": "https://github.com/percuss-io/utils/issues"
53
+ },
54
+ "homepage": "https://github.com/percuss-io/utils#readme",
55
+ "devDependencies": {
56
+ "@eslint/js": "^9.25.0",
57
+ "@percuss.io/eslint-config-ericcarraway": "5.0.1-beta.14",
58
+ "@stylistic/eslint-plugin": "^4.2.0",
59
+ "@types/node": "^22.14.1",
60
+ "eslint-plugin-import": "^2.31.0",
61
+ "eslint-plugin-simple-import-sort": "^12.1.1",
62
+ "eslint-plugin-sort-destructure-keys": "^2.0.0",
63
+ "tsup": "^8.4.0",
64
+ "typescript": "^5.8.3",
65
+ "typescript-eslint": "^8.30.1",
66
+ "vitest": "^3.1.1"
67
+ }
68
+ }