@stacksjs/utils 0.72.102 → 0.73.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.
- package/dist/equal.d.ts +17 -1
- package/dist/equal.js +1 -1
- package/dist/helpers.d.ts +5 -5
- package/dist/helpers.js +2 -2
- package/dist/macroable.js +1 -1
- package/dist/observer.d.ts +11 -2
- package/package.json +11 -11
package/dist/equal.d.ts
CHANGED
|
@@ -9,5 +9,21 @@
|
|
|
9
9
|
* (`a.self = a; isDeepEqual(a, a)` blew the stack). A WeakSet of
|
|
10
10
|
* already-visited objects breaks the cycle and treats two structurally
|
|
11
11
|
* identical cycles as equal.
|
|
12
|
+
* - Dates, regular expressions, Maps and Sets are compared by what they
|
|
13
|
+
* HOLD. Only arrays and plain objects had branches, so everything else
|
|
14
|
+
* fell through to the `Object.is` tail — which for an object means
|
|
15
|
+
* reference identity. `isDeepEqual(new Date(0), new Date(0))` was
|
|
16
|
+
* therefore false, as were two equal `/a/g`s, two Maps with the same
|
|
17
|
+
* entries and two Sets with the same members. A Date nested anywhere
|
|
18
|
+
* inside a structure took the whole comparison down with it, which is
|
|
19
|
+
* how this stayed unnoticed: the common shapes are objects and arrays,
|
|
20
|
+
* and those worked. Typed arrays and ArrayBuffers compare by their bytes
|
|
21
|
+
* for the same reason.
|
|
22
|
+
* - Errors and host objects (URL, Headers, Blob, …) are deliberately NOT
|
|
23
|
+
* handled and still compare by identity. Unlike the types above they have
|
|
24
|
+
* no single obvious structural identity - whether two Errors with the same
|
|
25
|
+
* message but different stacks are "equal" is a policy question, not a
|
|
26
|
+
* fact - and there is no end to the list. Guessing an answer silently is
|
|
27
|
+
* what made the cases above wrong.
|
|
12
28
|
*/
|
|
13
|
-
export declare function isDeepEqual(value1:
|
|
29
|
+
export declare function isDeepEqual(value1: unknown, value2: unknown, seen?: WeakMap<object, object>): boolean;
|
package/dist/equal.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getTypeName}from"@stacksjs/types";export function isDeepEqual(value1,value2,seen=new WeakMap){if(value1===value2)return!0;if(typeof value1==="number"&&typeof value2==="number"&&Number.isNaN(value1)&&Number.isNaN(value2))return!0;const type1=getTypeName(value1),type2=getTypeName(value2);if(type1!==type2)return!1;if(value1&&typeof value1==="object"){if(seen.get(value1)===value2)return!0;seen.set(value1,value2)}if(type1==="
|
|
1
|
+
import{getTypeName}from"@stacksjs/types";function unorderedMatch(a,b,matches){if(a.length!==b.length)return!1;const consumed=Array.from({length:b.length},()=>!1);for(const item of a){let found=!1;for(let i=0;i<b.length;i++){if(consumed[i])continue;if(matches(item,b[i])){consumed[i]=!0;found=!0;break}}if(!found)return!1}return!0}function mapsEqual(a,b,seen){if(a.size!==b.size)return!1;let sameKeys=!0;for(const key of a.keys())if(!b.has(key)){sameKeys=!1;break}if(sameKeys){for(const[key,value]of a)if(!isDeepEqual(value,b.get(key),seen))return!1;return!0}return unorderedMatch([...a.entries()],[...b.entries()],(x,y)=>isDeepEqual(x[0],y[0],seen)&&isDeepEqual(x[1],y[1],seen))}export function isDeepEqual(value1,value2,seen=new WeakMap){if(value1===value2)return!0;if(typeof value1==="number"&&typeof value2==="number"&&Number.isNaN(value1)&&Number.isNaN(value2))return!0;const type1=getTypeName(value1),type2=getTypeName(value2);if(type1!==type2)return!1;if(value1&&typeof value1==="object"){if(seen.get(value1)===value2)return!0;seen.set(value1,value2)}if(type1==="date")return Object.is(value1.getTime(),value2.getTime());if(type1==="regexp")return value1.source===value2.source&&value1.flags===value2.flags;if(type1==="map")return mapsEqual(value1,value2,seen);if(type1==="set")return unorderedMatch([...value1],[...value2],(x,y)=>isDeepEqual(x,y,seen));if(ArrayBuffer.isView(value1)&&ArrayBuffer.isView(value2)){const bytes1=new Uint8Array(value1.buffer,value1.byteOffset,value1.byteLength),bytes2=new Uint8Array(value2.buffer,value2.byteOffset,value2.byteLength);if(bytes1.length!==bytes2.length)return!1;return bytes1.every((byte,i)=>byte===bytes2[i])}if(type1==="arraybuffer"){const bytes1=new Uint8Array(value1),bytes2=new Uint8Array(value2);if(bytes1.length!==bytes2.length)return!1;return bytes1.every((byte,i)=>byte===bytes2[i])}if(Array.isArray(value1)&&Array.isArray(value2)){if(value1.length!==value2.length)return!1;return value1.every((item,i)=>isDeepEqual(item,value2[i],seen))}if(type1==="object"){const object1=value1,object2=value2,keyArr=Object.keys(object1);if(keyArr.length!==Object.keys(object2).length)return!1;return keyArr.every((key)=>isDeepEqual(object1[key],object2[key],seen))}return Object.is(value1,value2)}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -28,11 +28,11 @@ export declare function determineResetPreset(preset?: string | null): string[];
|
|
|
28
28
|
/**
|
|
29
29
|
* Determines whether the specified value is a package manifest.
|
|
30
30
|
*/
|
|
31
|
-
export declare function isManifest(obj:
|
|
31
|
+
export declare function isManifest(obj: unknown): obj is Manifest;
|
|
32
32
|
/**
|
|
33
33
|
* Determines whether the specified value is a string, null, or undefined.
|
|
34
34
|
*/
|
|
35
|
-
export declare function isOptionalString(value:
|
|
35
|
+
export declare function isOptionalString(value: unknown): value is string | null | undefined;
|
|
36
36
|
export declare function setEnvValue(key: string, value: string): Promise<void>;
|
|
37
37
|
/**
|
|
38
38
|
* Runs the specified NPM script in the package.json file.
|
|
@@ -42,7 +42,7 @@ export declare function runNpmScript(script: NpmScript, options?: CliOptions): P
|
|
|
42
42
|
* Determines whether the specified NPM script exists in the given manifest.
|
|
43
43
|
*/
|
|
44
44
|
export declare function hasScript(manifest: Manifest, script: NpmScript): boolean;
|
|
45
|
-
export declare function parseYaml(content:
|
|
45
|
+
export declare function parseYaml(content: string): unknown;
|
|
46
46
|
/**
|
|
47
47
|
* Determines the level of debugging.
|
|
48
48
|
*
|
|
@@ -57,5 +57,5 @@ export declare function parseYaml(content: any): any;
|
|
|
57
57
|
*/
|
|
58
58
|
export declare function determineDebugLevel(options?: CliOptions): boolean;
|
|
59
59
|
export declare function isIpv6(address: AddressInfo): boolean;
|
|
60
|
-
export declare function dumpYaml(content:
|
|
61
|
-
export declare function loadYaml(content: string):
|
|
60
|
+
export declare function dumpYaml(content: unknown): string;
|
|
61
|
+
export declare function loadYaml(content: string): unknown;
|
package/dist/helpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import process from"node:process";import{runAction}from"@stacksjs/actions";import{log,runCommand}from"@stacksjs/cli";import{app,ui}from"@stacksjs/config";import{Action}from"@stacksjs/enums";import{err,handleError,ok}from"@stacksjs/error-handling";import{frameworkPath,projectPath}from"@stacksjs/path";import{fs,readJsonFile,readPackageJson,readTextFile,writeTextFile}from"@stacksjs/storage";export async function packageManager(){const{packageManager}=await readPackageJson(frameworkPath("package.json"));return packageManager}export async function initProject(){if(app.env!=="production")log.info("Project not yet initialized, generating application key...");else handleError("Please run `buddy key:generate` to generate an application key");const result=await runAction(Action.KeyGenerate,{cwd:projectPath()});if(result.isErr)return err(handleError(result.error));log.info("Application key generated.");return ok(result.value)}export async function ensureProjectIsInitialized(){if(!isStacksProject()){console.error("This command must be run inside a Stacks project; create one with: panx @stacksjs/buddy new my-app");process.exit(1)}if(await isAppKeySet())return!0;if(fs.existsSync(projectPath(".env")))return!1;if(fs.existsSync(projectPath(".env.example")))fs.copyFileSync(projectPath(".env.example"),projectPath(".env"));else console.error("no .env.example file found");return await isAppKeySet()}export function isStacksProject(){if(!fs.existsSync(projectPath("package.json")))return!1;return fs.existsSync(projectPath("config"))||fs.existsSync(projectPath("storage/framework/core"))}export async function installIfVersionMismatch(){}export async function frameworkVersion(){return(await readPackageJson(frameworkPath("package.json"))).version}export async function isAppKeySet(){if(String(process.env.APP_KEY??"").trim().length>16)return!0;try{const appKey=(await readTextFile(".env",projectPath())).data.split(`
|
|
2
|
-
`).find((line)=>line.startsWith("APP_KEY="));return!!(appKey&&appKey.length>16)}catch{return!1}}export function determineResetPreset(preset){if(preset===void 0&&ui.reset)preset=ui.reset;if(preset===null)return[];const resetImport={tailwind:'import { tailwindPreflight as reset } from "@cwcss/crosswind"',preflight:'import { tailwindPreflight as reset } from "@cwcss/crosswind"',forms:'import { tailwindFormsPreflight as reset } from "@cwcss/crosswind"'}[preset??"tailwind"];return resetImport?[resetImport]:[]}export function isManifest(obj){
|
|
1
|
+
import process from"node:process";import{runAction}from"@stacksjs/actions";import{log,runCommand}from"@stacksjs/cli";import{app,ui}from"@stacksjs/config";import{Action}from"@stacksjs/enums";import{err,handleError,ok}from"@stacksjs/error-handling";import{frameworkPath,projectPath}from"@stacksjs/path";import{fs,readJsonFile,readPackageJson,readTextFile,writeTextFile}from"@stacksjs/storage";export async function packageManager(){const{packageManager}=await readPackageJson(frameworkPath("package.json"));return packageManager??""}export async function initProject(){if(app.env!=="production")log.info("Project not yet initialized, generating application key...");else handleError("Please run `buddy key:generate` to generate an application key");const result=await runAction(Action.KeyGenerate,{cwd:projectPath()});if(result.isErr)return err(handleError(result.error));log.info("Application key generated.");return ok(result.value)}export async function ensureProjectIsInitialized(){if(!isStacksProject()){console.error("This command must be run inside a Stacks project; create one with: panx @stacksjs/buddy new my-app");process.exit(1)}if(await isAppKeySet())return!0;if(fs.existsSync(projectPath(".env")))return!1;if(fs.existsSync(projectPath(".env.example")))fs.copyFileSync(projectPath(".env.example"),projectPath(".env"));else console.error("no .env.example file found");return await isAppKeySet()}export function isStacksProject(){if(!fs.existsSync(projectPath("package.json")))return!1;return fs.existsSync(projectPath("config"))||fs.existsSync(projectPath("storage/framework/core"))}export async function installIfVersionMismatch(){}export async function frameworkVersion(){return(await readPackageJson(frameworkPath("package.json"))).version??""}export async function isAppKeySet(){if(String(process.env.APP_KEY??"").trim().length>16)return!0;try{const appKey=(await readTextFile(".env",projectPath())).data.split(`
|
|
2
|
+
`).find((line)=>line.startsWith("APP_KEY="));return!!(appKey&&appKey.length>16)}catch{return!1}}export function determineResetPreset(preset){if(preset===void 0&&ui.reset)preset=ui.reset;if(preset===null)return[];const resetImport={tailwind:'import { tailwindPreflight as reset } from "@cwcss/crosswind"',preflight:'import { tailwindPreflight as reset } from "@cwcss/crosswind"',forms:'import { tailwindFormsPreflight as reset } from "@cwcss/crosswind"'}[preset??"tailwind"];return resetImport?[resetImport]:[]}export function isManifest(obj){if(!obj||typeof obj!=="object")return!1;const candidate=obj;return isOptionalString(candidate.name)&&isOptionalString(candidate.version)&&isOptionalString(candidate.description)}export function isOptionalString(value){const type=typeof value;return value===null||type==="undefined"||type==="string"}export async function setEnvValue(key,value){const file=await readTextFile(projectPath(".env")),escapedKey=key.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),keyPattern=new RegExp(`^${escapedKey}=.*$`,"m"),nextValue=`${key}=${value}`,data=keyPattern.test(file.data)?file.data.replace(keyPattern,nextValue):`${file.data}${file.data.endsWith(`
|
|
3
3
|
`)?"":`
|
|
4
4
|
`}${nextValue}
|
|
5
5
|
`;await writeTextFile({path:projectPath(".env"),data})}export async function runNpmScript(script,options){const{data:manifest}=await readJsonFile("package.json",frameworkPath());if(isManifest(manifest)&&hasScript(manifest,script))return await runCommand(`bun run ${script}`,options);return err(handleError(`The ${script} script does not exist in the package.json file.`))}export function hasScript(manifest,script){const scripts=manifest.scripts;if(scripts&&typeof scripts==="object")return Boolean(scripts[script]);return!1}export function parseYaml(content){return Bun.YAML.parse(content)}export function determineDebugLevel(options){if(options?.verbose===!0)return!0;return app.debug===!0}export function isIpv6(address){return address.family==="IPv6"||address.family===6}export function dumpYaml(content){const yaml=Bun.YAML;if(typeof yaml.stringify==="function")return yaml.stringify(content);return JSON.stringify(content,null,2)}export function loadYaml(content){return Bun.YAML.parse(content)}
|
package/dist/macroable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class Macroable{static macros=new Map;static macro(name,fn,replace=!1){if(this.macros.has(name)&&!replace)throw Error(`Macro "${name}" is already registered`);this.macros.set(name,fn);Object.defineProperty(this.prototype,name,{value:fn,writable:!0,configurable:!0,enumerable:!1})}static mixin(obj,replace=!0){const methods=Object.getOwnPropertyNames(obj);for(const method of methods){if(method==="constructor")continue;if(this.macros.has(method)&&!replace)continue;const descriptor=Object.getOwnPropertyDescriptor(obj,method);if(descriptor&&typeof descriptor.value==="function")this.macro(method,descriptor.value,replace)}}static hasMacro(name){return this.macros.has(name)}static flushMacros(){for(const name of this.macros.keys())delete this.prototype[name];this.macros.clear()}static getMacros(){return Array.from(this.macros.keys())}callMacro(name,...args){const macro=this.constructor.macros.get(name);if(!macro)throw Error(`Macro "${name}" is not registered`);return macro.apply(this,args)}}export function createMacroable(BaseClass=class{}){return class extends BaseClass{static macros=new Map;static macro(name,fn,replace=!1){if(this.macros.has(name)&&!replace)throw Error(`Macro "${name}" is already registered`);this.macros.set(name,fn);Object.defineProperty(this.prototype,name,{value:fn,writable:!0,configurable:!0,enumerable:!1})}static mixin(obj,replace=!0){const methods=Object.getOwnPropertyNames(obj);for(const method of methods){if(method==="constructor")continue;if(this.macros.has(method)&&!replace)continue;const descriptor=Object.getOwnPropertyDescriptor(obj,method);if(descriptor&&typeof descriptor.value==="function")this.macro(method,descriptor.value,replace)}}static hasMacro(name){return this.macros.has(name)}static flushMacros(){for(const name of this.macros.keys())delete this.prototype[name];this.macros.clear()}static getMacros(){return Array.from(this.macros.keys())}}}export function macroable(target){const macros=new Map;
|
|
1
|
+
export class Macroable{static macros=new Map;static macro(name,fn,replace=!1){if(this.macros.has(name)&&!replace)throw Error(`Macro "${name}" is already registered`);this.macros.set(name,fn);Object.defineProperty(this.prototype,name,{value:fn,writable:!0,configurable:!0,enumerable:!1})}static mixin(obj,replace=!0){const methods=Object.getOwnPropertyNames(obj);for(const method of methods){if(method==="constructor")continue;if(this.macros.has(method)&&!replace)continue;const descriptor=Object.getOwnPropertyDescriptor(obj,method);if(descriptor&&typeof descriptor.value==="function")this.macro(method,descriptor.value,replace)}}static hasMacro(name){return this.macros.has(name)}static flushMacros(){for(const name of this.macros.keys())delete this.prototype[name];this.macros.clear()}static getMacros(){return Array.from(this.macros.keys())}callMacro(name,...args){const macro=this.constructor.macros.get(name);if(!macro)throw Error(`Macro "${name}" is not registered`);return macro.apply(this,args)}}export function createMacroable(BaseClass=class{}){return class extends BaseClass{static macros=new Map;static macro(name,fn,replace=!1){if(this.macros.has(name)&&!replace)throw Error(`Macro "${name}" is already registered`);this.macros.set(name,fn);Object.defineProperty(this.prototype,name,{value:fn,writable:!0,configurable:!0,enumerable:!1})}static mixin(obj,replace=!0){const methods=Object.getOwnPropertyNames(obj);for(const method of methods){if(method==="constructor")continue;if(this.macros.has(method)&&!replace)continue;const descriptor=Object.getOwnPropertyDescriptor(obj,method);if(descriptor&&typeof descriptor.value==="function")this.macro(method,descriptor.value,replace)}}static hasMacro(name){return this.macros.has(name)}static flushMacros(){for(const name of this.macros.keys())delete this.prototype[name];this.macros.clear()}static getMacros(){return Array.from(this.macros.keys())}}}export function macroable(target){const macros=new Map,decorated=target;decorated.macro=function(name,fn,replace=!1){if(macros.has(name)&&!replace)throw Error(`Macro "${name}" is already registered`);macros.set(name,fn);Object.defineProperty(target.prototype,name,{value:fn,writable:!0,configurable:!0,enumerable:!1})};decorated.mixin=function(obj,replace=!0){const methods=Object.getOwnPropertyNames(obj);for(const method of methods){if(method==="constructor")continue;if(macros.has(method)&&!replace)continue;const descriptor=Object.getOwnPropertyDescriptor(obj,method);if(descriptor&&typeof descriptor.value==="function")decorated.macro(method,descriptor.value,replace)}};decorated.hasMacro=function(name){return macros.has(name)};decorated.flushMacros=function(){for(const name of macros.keys())delete target.prototype[name];macros.clear()};decorated.getMacros=function(){return Array.from(macros.keys())};return target}
|
package/dist/observer.d.ts
CHANGED
|
@@ -7,7 +7,16 @@ export declare function isResizeObserverSupported(): boolean;
|
|
|
7
7
|
*
|
|
8
8
|
* Modern browsers all support ResizeObserver, but this provides a fallback
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The native `ResizeObserver`, or a polyfill constructor with the same shape.
|
|
12
|
+
*
|
|
13
|
+
* Typed as the constructor rather than `any`: the polyfill below already
|
|
14
|
+
* declares `implements ResizeObserver`, so both branches genuinely satisfy it
|
|
15
|
+
* and nothing had to be given up to say so. `any` here spread to the
|
|
16
|
+
* `ResizeObserver` export beneath, so every consumer of the polyfill lost
|
|
17
|
+
* `observe` / `unobserve` / `disconnect` checking.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getResizeObserver(): new (_callback: ResizeObserverCallback) => ResizeObserver;
|
|
11
20
|
/**
|
|
12
21
|
* Create a resize observer with automatic cleanup
|
|
13
22
|
*
|
|
@@ -39,7 +48,7 @@ export declare function createResizeObserver(callback: ResizeObserverCallback, t
|
|
|
39
48
|
*/
|
|
40
49
|
export declare function observeElementSize(element: Element, callback: (entry: ResizeObserverEntry) => void): () => void;
|
|
41
50
|
// Export the native ResizeObserver if available, or the polyfill
|
|
42
|
-
export declare const ResizeObserver:
|
|
51
|
+
export declare const ResizeObserver: new (_callback: ResizeObserverCallback) => ResizeObserver;
|
|
43
52
|
/**
|
|
44
53
|
* ResizeObserver polyfill (resize-observer-polyfill replacement)
|
|
45
54
|
*
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/utils",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.73.0",
|
|
6
6
|
"description": "The Stacks helper functions.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -62,20 +62,20 @@
|
|
|
62
62
|
"size": "bun scripts/export-size.ts"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@stacksjs/browser": "0.
|
|
65
|
+
"@stacksjs/browser": "0.73.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@stacksjs/actions": "0.
|
|
69
|
-
"@stacksjs/arrays": "0.
|
|
70
|
-
"@stacksjs/cli": "0.
|
|
71
|
-
"@stacksjs/config": "0.
|
|
68
|
+
"@stacksjs/actions": "0.73.0",
|
|
69
|
+
"@stacksjs/arrays": "0.73.0",
|
|
70
|
+
"@stacksjs/cli": "0.73.0",
|
|
71
|
+
"@stacksjs/config": "0.73.0",
|
|
72
72
|
"better-dx": "^0.2.24",
|
|
73
73
|
"filesize": "^11.0.22",
|
|
74
74
|
"markdown-table": "^3.0.4",
|
|
75
|
-
"@stacksjs/lint": "0.
|
|
76
|
-
"@stacksjs/path": "0.
|
|
77
|
-
"@stacksjs/storage": "0.
|
|
78
|
-
"@stacksjs/strings": "0.
|
|
79
|
-
"@stacksjs/types": "0.
|
|
75
|
+
"@stacksjs/lint": "0.73.0",
|
|
76
|
+
"@stacksjs/path": "0.73.0",
|
|
77
|
+
"@stacksjs/storage": "0.73.0",
|
|
78
|
+
"@stacksjs/strings": "0.73.0",
|
|
79
|
+
"@stacksjs/types": "0.73.0"
|
|
80
80
|
}
|
|
81
81
|
}
|