@stacksjs/utils 0.49.1 → 0.49.2
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/base.d.ts +3 -0
- package/dist/base.mjs +12 -0
- package/dist/equal.d.ts +1 -0
- package/dist/equal.mjs +23 -0
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.mjs +2 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +4 -3
- package/dist/is.d.ts +10 -0
- package/dist/is.mjs +11 -0
- package/dist/p.d.ts +1 -1
- package/dist/p.mjs +1 -2
- package/dist/promise.d.ts +24 -10
- package/dist/promise.mjs +22 -7
- package/package.json +10 -10
package/dist/base.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
export declare const assert: (condition: boolean, message: string) => asserts condition;
|
|
1
2
|
export declare const toString: (v: any) => any;
|
|
3
|
+
export declare const noop: () => void;
|
|
2
4
|
export declare const loop: (times: number, callback: any) => void;
|
|
5
|
+
export declare const getTypeName: (v: any) => any;
|
package/dist/base.mjs
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
export const assert = (condition, message) => {
|
|
2
|
+
if (!condition)
|
|
3
|
+
throw new Error(message);
|
|
4
|
+
};
|
|
1
5
|
export const toString = (v) => Object.prototype.toString.call(v);
|
|
6
|
+
export const noop = () => {
|
|
7
|
+
};
|
|
2
8
|
export const loop = (times, callback) => {
|
|
3
9
|
[...Array(times)].forEach((item, i) => callback(i));
|
|
4
10
|
};
|
|
11
|
+
export const getTypeName = (v) => {
|
|
12
|
+
if (v === null)
|
|
13
|
+
return "null";
|
|
14
|
+
const type = toString(v).slice(8, -1).toLowerCase();
|
|
15
|
+
return typeof v === "object" || typeof v === "function" ? type : typeof v;
|
|
16
|
+
};
|
package/dist/equal.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isDeepEqual(value1: any, value2: any): boolean;
|
package/dist/equal.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getTypeName } from "./base.mjs";
|
|
2
|
+
export function isDeepEqual(value1, value2) {
|
|
3
|
+
const type1 = getTypeName(value1);
|
|
4
|
+
const type2 = getTypeName(value2);
|
|
5
|
+
if (type1 !== type2)
|
|
6
|
+
return false;
|
|
7
|
+
if (type1 === "array") {
|
|
8
|
+
if (value1.length !== value2.length)
|
|
9
|
+
return false;
|
|
10
|
+
return value1.every((item, i) => {
|
|
11
|
+
return isDeepEqual(item, value2[i]);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (type1 === "object") {
|
|
15
|
+
const keyArr = Object.keys(value1);
|
|
16
|
+
if (keyArr.length !== Object.keys(value2).length)
|
|
17
|
+
return false;
|
|
18
|
+
return keyArr.every((key) => {
|
|
19
|
+
return isDeepEqual(value1[key], value2[key]);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return Object.is(value1, value2);
|
|
23
|
+
}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CliOptions, Manifest, NpmScript } from '@stacksjs/types';
|
|
2
|
+
import detectIndent from 'detect-indent';
|
|
2
3
|
export declare function isProjectCreated(): Promise<boolean>;
|
|
3
4
|
export declare function frameworkVersion(): Promise<string>;
|
|
4
5
|
export declare function isAppKeySet(): Promise<boolean>;
|
|
@@ -30,5 +31,5 @@ export declare function runNpmScript(script: NpmScript, options?: CliOptions): P
|
|
|
30
31
|
export declare function hasScript(manifest: Manifest, script: NpmScript): boolean;
|
|
31
32
|
export * from '@dinero.js/currencies';
|
|
32
33
|
export * from 'dinero.js';
|
|
33
|
-
export
|
|
34
|
+
export { detectIndent };
|
|
34
35
|
export { detectNewline } from 'detect-newline';
|
package/dist/helpers.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { log, runCommand, spawn } from "@stacksjs/cli";
|
|
|
2
2
|
import { frameworkPath, projectPath } from "@stacksjs/path";
|
|
3
3
|
import storage from "@stacksjs/storage";
|
|
4
4
|
import { ui } from "@stacksjs/config";
|
|
5
|
+
import detectIndent from "detect-indent";
|
|
5
6
|
export async function isProjectCreated() {
|
|
6
7
|
if (storage.isFile(".env"))
|
|
7
8
|
return await isAppKeySet();
|
|
@@ -72,5 +73,5 @@ export function hasScript(manifest, script) {
|
|
|
72
73
|
}
|
|
73
74
|
export * from "@dinero.js/currencies";
|
|
74
75
|
export * from "dinero.js";
|
|
75
|
-
export
|
|
76
|
+
export { detectIndent };
|
|
76
77
|
export { detectNewline } from "detect-newline";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { assert, toString, noop, loop, getTypeName } from './base';
|
|
2
|
+
export * from './equal';
|
|
2
3
|
export * from './helpers';
|
|
3
|
-
export
|
|
4
|
+
export type { SingletonPromiseReturn, ControlledPromise } from './promise';
|
|
5
|
+
export { createSingletonPromise, createPromiseLock, createControlledPromise, sleep } from './promise';
|
|
4
6
|
export * from './function';
|
|
5
7
|
export * from './guards';
|
|
6
|
-
export
|
|
8
|
+
export { isDef, isBoolean, isFunction, isNumber, isString, isObject, isWindow, isBrowser, isServer, isMap, isSet, isPromise } from './is';
|
|
7
9
|
export * from './p';
|
|
8
10
|
export * from './vendor';
|
|
9
11
|
export * from '@vueuse/core';
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { assert, toString, noop, loop, getTypeName } from "./base.mjs";
|
|
2
|
+
export * from "./equal.mjs";
|
|
2
3
|
export * from "./helpers.mjs";
|
|
3
|
-
export
|
|
4
|
+
export { createSingletonPromise, createPromiseLock, createControlledPromise, sleep } from "./promise.mjs";
|
|
4
5
|
export * from "./function.mjs";
|
|
5
6
|
export * from "./guards.mjs";
|
|
6
|
-
export
|
|
7
|
+
export { isDef, isBoolean, isFunction, isNumber, isString, isObject, isWindow, isBrowser, isServer, isMap, isSet, isPromise } from "./is.mjs";
|
|
7
8
|
export * from "./p.mjs";
|
|
8
9
|
export * from "./vendor.mjs";
|
|
9
10
|
export * from "@vueuse/core";
|
package/dist/is.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
+
export declare const isDef: <T = any>(val?: T | undefined) => val is T;
|
|
2
|
+
export declare const isBoolean: (val: any) => val is boolean;
|
|
3
|
+
export declare const isFunction: <T extends Function>(val: any) => val is T;
|
|
4
|
+
export declare const isNumber: (val: any) => val is number;
|
|
5
|
+
export declare const isString: (val: unknown) => val is string;
|
|
6
|
+
export declare const isObject: (val: any) => val is object;
|
|
7
|
+
export declare const isWindow: (val: any) => boolean;
|
|
1
8
|
export declare const isBrowser: boolean;
|
|
2
9
|
export declare const isServer: boolean;
|
|
10
|
+
export declare const isMap: (val: any) => val is Map<any, any>;
|
|
11
|
+
export declare const isSet: (val: any) => val is Set<any>;
|
|
12
|
+
export declare const isPromise: <T = any>(val: any) => val is Promise<T>;
|
package/dist/is.mjs
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
import { toString } from "./base.mjs";
|
|
2
|
+
export const isDef = (val) => typeof val !== "undefined";
|
|
3
|
+
export const isBoolean = (val) => typeof val === "boolean";
|
|
4
|
+
export const isFunction = (val) => typeof val === "function";
|
|
5
|
+
export const isNumber = (val) => typeof val === "number";
|
|
6
|
+
export const isString = (val) => typeof val === "string";
|
|
7
|
+
export const isObject = (val) => toString(val) === "[object Object]";
|
|
8
|
+
export const isWindow = (val) => typeof window !== "undefined" && toString(val) === "[object Window]";
|
|
1
9
|
export const isBrowser = typeof window !== "undefined";
|
|
2
10
|
export const isServer = typeof document === "undefined";
|
|
11
|
+
export const isMap = (val) => toString(val) === "[object Map]";
|
|
12
|
+
export const isSet = (val) => toString(val) === "[object Set]";
|
|
13
|
+
export const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
package/dist/p.d.ts
CHANGED
package/dist/p.mjs
CHANGED
package/dist/promise.d.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import type { Fn } from '@stacksjs/types';
|
|
2
|
+
export interface SingletonPromiseReturn<T> {
|
|
3
|
+
(): Promise<T>;
|
|
4
|
+
/**
|
|
5
|
+
* Reset current staled promise.
|
|
6
|
+
* Await it to have proper shutdown.
|
|
7
|
+
*/
|
|
8
|
+
reset: () => Promise<void>;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
|
-
*
|
|
11
|
+
* Promise with `resolve` and `reject` methods of itself
|
|
12
|
+
*/
|
|
13
|
+
export interface ControlledPromise<T = void> extends Promise<T> {
|
|
14
|
+
resolve(value: T | PromiseLike<T>): void;
|
|
15
|
+
reject(reason?: any): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create singleton promise function.
|
|
4
19
|
*
|
|
5
20
|
* @category Promise
|
|
6
21
|
*/
|
|
7
|
-
export declare function
|
|
22
|
+
export declare function createSingletonPromise<T>(fn: () => Promise<T>): SingletonPromiseReturn<T>;
|
|
8
23
|
/**
|
|
9
|
-
* Create a promise lock
|
|
24
|
+
* Create a promise lock.
|
|
10
25
|
*
|
|
11
26
|
* @category Promise
|
|
12
27
|
* @example
|
|
@@ -27,13 +42,6 @@ export declare function createPromiseLock(): {
|
|
|
27
42
|
isWaiting(): boolean;
|
|
28
43
|
clear(): void;
|
|
29
44
|
};
|
|
30
|
-
/**
|
|
31
|
-
* Promise with `resolve` and `reject` methods of itself
|
|
32
|
-
*/
|
|
33
|
-
export interface ControlledPromise<T = void> extends Promise<T> {
|
|
34
|
-
resolve(value: T | PromiseLike<T>): void;
|
|
35
|
-
reject(reason?: any): void;
|
|
36
|
-
}
|
|
37
45
|
/**
|
|
38
46
|
* Return a Promise with `resolve` and `reject` methods
|
|
39
47
|
*
|
|
@@ -49,3 +57,9 @@ export interface ControlledPromise<T = void> extends Promise<T> {
|
|
|
49
57
|
* ```
|
|
50
58
|
*/
|
|
51
59
|
export declare function createControlledPromise<T>(): ControlledPromise<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Promised `setTimeout`.
|
|
62
|
+
*
|
|
63
|
+
* @category Promise
|
|
64
|
+
*/
|
|
65
|
+
export declare function sleep(ms: number, callback?: Fn<any>): Promise<void>;
|
package/dist/promise.mjs
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { remove } from "@stacksjs/arrays";
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export function createSingletonPromise(fn) {
|
|
3
|
+
let _promise;
|
|
4
|
+
function wrapper() {
|
|
5
|
+
if (!_promise)
|
|
6
|
+
_promise = fn();
|
|
7
|
+
return _promise;
|
|
8
|
+
}
|
|
9
|
+
wrapper.reset = async () => {
|
|
10
|
+
const _prev = _promise;
|
|
11
|
+
_promise = void 0;
|
|
12
|
+
if (_prev)
|
|
13
|
+
await _prev;
|
|
14
|
+
};
|
|
15
|
+
return wrapper;
|
|
9
16
|
}
|
|
10
17
|
export function createPromiseLock() {
|
|
11
18
|
const locks = [];
|
|
@@ -40,3 +47,11 @@ export function createControlledPromise() {
|
|
|
40
47
|
promise.reject = reject;
|
|
41
48
|
return promise;
|
|
42
49
|
}
|
|
50
|
+
export function sleep(ms, callback) {
|
|
51
|
+
return new Promise(
|
|
52
|
+
(resolve) => setTimeout(async () => {
|
|
53
|
+
await callback?.();
|
|
54
|
+
resolve();
|
|
55
|
+
}, ms)
|
|
56
|
+
);
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.49.
|
|
4
|
+
"version": "0.49.2",
|
|
5
5
|
"packageManager": "pnpm@7.25.0",
|
|
6
6
|
"description": "The Stacks helper functions.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
@@ -53,21 +53,21 @@
|
|
|
53
53
|
"fast-glob": "^3.2.12",
|
|
54
54
|
"kolorist": "1.6.0",
|
|
55
55
|
"p-limit": "^4.0.0",
|
|
56
|
-
"rimraf": "^4.0.
|
|
56
|
+
"rimraf": "^4.0.7",
|
|
57
57
|
"throttle-debounce": "^5.0.0",
|
|
58
|
-
"@stacksjs/
|
|
59
|
-
"@stacksjs/
|
|
60
|
-
"@stacksjs/
|
|
61
|
-
"@stacksjs/lint": "0.49.
|
|
62
|
-
"@stacksjs/path": "0.49.
|
|
63
|
-
"@stacksjs/
|
|
64
|
-
"@stacksjs/
|
|
58
|
+
"@stacksjs/cli": "0.49.2",
|
|
59
|
+
"@stacksjs/config": "0.49.2",
|
|
60
|
+
"@stacksjs/arrays": "0.49.2",
|
|
61
|
+
"@stacksjs/lint": "0.49.2",
|
|
62
|
+
"@stacksjs/path": "0.49.2",
|
|
63
|
+
"@stacksjs/types": "0.49.2",
|
|
64
|
+
"@stacksjs/storage": "0.49.2"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/throttle-debounce": "^5.0.0",
|
|
68
68
|
"mkdist": "^1.1.0",
|
|
69
69
|
"typescript": "^4.9.4",
|
|
70
|
-
"@stacksjs/testing": "0.49.
|
|
70
|
+
"@stacksjs/testing": "0.49.2"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "mkdist -d",
|