@stacksjs/utils 0.70.257 → 0.70.259
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/bytes.js +1 -55
- package/dist/clean.js +1 -13
- package/dist/colors.js +1 -100
- package/dist/config.js +1 -23
- package/dist/debounce.js +1 -77
- package/dist/detect.js +8 -65
- package/dist/equal.js +1 -27
- package/dist/errors.js +1 -44
- package/dist/export-size.js +1 -1
- package/dist/find.js +1 -64
- package/dist/git.js +1 -11
- package/dist/glob.js +1 -1
- package/dist/hash.js +1 -36
- package/dist/helpers.js +4 -114
- package/dist/index.js +1 -23
- package/dist/macroable.js +1 -121
- package/dist/markdown.js +2 -92
- package/dist/merge.js +1 -51
- package/dist/observer.js +1 -78
- package/dist/pipeline.js +1 -37
- package/dist/safe-json.js +1 -33
- package/dist/size.js +3 -66
- package/dist/utils.js +1 -6
- package/dist/versions.js +1 -23
- package/package.json +21 -14
package/dist/helpers.js
CHANGED
|
@@ -1,115 +1,5 @@
|
|
|
1
|
-
import process from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { app, ui } from "@stacksjs/config";
|
|
5
|
-
import { Action } from "@stacksjs/enums";
|
|
6
|
-
import { err, handleError, ok } from "@stacksjs/error-handling";
|
|
7
|
-
import { frameworkPath, projectPath } from "@stacksjs/path";
|
|
8
|
-
import { fs, readJsonFile, readPackageJson, readTextFile, writeTextFile } from "@stacksjs/storage";
|
|
9
|
-
export async function packageManager() {
|
|
10
|
-
const { packageManager } = await readPackageJson(frameworkPath("package.json"));
|
|
11
|
-
return packageManager;
|
|
12
|
-
}
|
|
13
|
-
export async function initProject() {
|
|
14
|
-
if (app.env !== "production")
|
|
15
|
-
log.info("Project not yet initialized, generating application key...");
|
|
16
|
-
else
|
|
17
|
-
handleError("Please run `buddy key:generate` to generate an application key");
|
|
18
|
-
const result = await runAction(Action.KeyGenerate, { cwd: projectPath() });
|
|
19
|
-
if (result.isErr)
|
|
20
|
-
return err(handleError(result.error));
|
|
21
|
-
log.info("Application key generated.");
|
|
22
|
-
return ok(result.value);
|
|
23
|
-
}
|
|
24
|
-
export async function ensureProjectIsInitialized() {
|
|
25
|
-
if (!isStacksProject()) {
|
|
26
|
-
console.error("This command must be run inside a Stacks project; create one with: panx @stacksjs/buddy new my-app");
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
if (fs.existsSync(projectPath(".env")))
|
|
30
|
-
return await isAppKeySet();
|
|
31
|
-
if (fs.existsSync(projectPath(".env.example")))
|
|
32
|
-
fs.copyFileSync(projectPath(".env.example"), projectPath(".env"));
|
|
33
|
-
else
|
|
34
|
-
console.error("no .env.example file found");
|
|
35
|
-
return await isAppKeySet();
|
|
36
|
-
}
|
|
37
|
-
export function isStacksProject() {
|
|
38
|
-
if (!fs.existsSync(projectPath("package.json")))
|
|
39
|
-
return !1;
|
|
40
|
-
return fs.existsSync(projectPath("config")) || fs.existsSync(projectPath("storage/framework/core"));
|
|
41
|
-
}
|
|
42
|
-
export async function installIfVersionMismatch() {}
|
|
43
|
-
export async function frameworkVersion() {
|
|
44
|
-
return (await readPackageJson(frameworkPath("package.json"))).version;
|
|
45
|
-
}
|
|
46
|
-
export async function isAppKeySet() {
|
|
47
|
-
try {
|
|
48
|
-
const appKey = (await readTextFile(".env", projectPath())).data.split(`
|
|
49
|
-
`).find((line) => line.startsWith("APP_KEY="));
|
|
50
|
-
return !!(appKey && appKey.length > 16);
|
|
51
|
-
} catch {
|
|
52
|
-
return !1;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export function determineResetPreset(preset) {
|
|
56
|
-
if (preset === void 0 && ui.reset)
|
|
57
|
-
preset = ui.reset;
|
|
58
|
-
if (preset === null)
|
|
59
|
-
return [];
|
|
60
|
-
const resetImport = {
|
|
61
|
-
tailwind: 'import { tailwindPreflight as reset } from "@cwcss/crosswind"',
|
|
62
|
-
preflight: 'import { tailwindPreflight as reset } from "@cwcss/crosswind"',
|
|
63
|
-
forms: 'import { tailwindFormsPreflight as reset } from "@cwcss/crosswind"'
|
|
64
|
-
}[preset ?? "tailwind"];
|
|
65
|
-
return resetImport ? [resetImport] : [];
|
|
66
|
-
}
|
|
67
|
-
export function isManifest(obj) {
|
|
68
|
-
return obj && typeof obj === "object" && isOptionalString(obj.name) && isOptionalString(obj.version) && isOptionalString(obj.description);
|
|
69
|
-
}
|
|
70
|
-
export function isOptionalString(value) {
|
|
71
|
-
const type = typeof value;
|
|
72
|
-
return value === null || type === "undefined" || type === "string";
|
|
73
|
-
}
|
|
74
|
-
export async function setEnvValue(key, value) {
|
|
75
|
-
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(`
|
|
76
|
-
`) ? "" : `
|
|
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(fs.existsSync(projectPath(".env")))return await isAppKeySet();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(){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){return obj&&typeof obj==="object"&&isOptionalString(obj.name)&&isOptionalString(obj.version)&&isOptionalString(obj.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
|
+
`)?"":`
|
|
77
4
|
`}${nextValue}
|
|
78
|
-
`;
|
|
79
|
-
await writeTextFile({
|
|
80
|
-
path: projectPath(".env"),
|
|
81
|
-
data
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
export async function runNpmScript(script, options) {
|
|
85
|
-
const { data: manifest } = await readJsonFile("package.json", frameworkPath());
|
|
86
|
-
if (isManifest(manifest) && hasScript(manifest, script))
|
|
87
|
-
return await runCommand(`bun run ${script}`, options);
|
|
88
|
-
return err(handleError(`The ${script} script does not exist in the package.json file.`));
|
|
89
|
-
}
|
|
90
|
-
export function hasScript(manifest, script) {
|
|
91
|
-
const scripts = manifest.scripts;
|
|
92
|
-
if (scripts && typeof scripts === "object")
|
|
93
|
-
return Boolean(scripts[script]);
|
|
94
|
-
return !1;
|
|
95
|
-
}
|
|
96
|
-
export function parseYaml(content) {
|
|
97
|
-
return Bun.YAML.parse(content);
|
|
98
|
-
}
|
|
99
|
-
export function determineDebugLevel(options) {
|
|
100
|
-
if (options?.verbose === !0)
|
|
101
|
-
return !0;
|
|
102
|
-
return app.debug === !0;
|
|
103
|
-
}
|
|
104
|
-
export function isIpv6(address) {
|
|
105
|
-
return address.family === "IPv6" || address.family === 6;
|
|
106
|
-
}
|
|
107
|
-
export function dumpYaml(content) {
|
|
108
|
-
const yaml = Bun.YAML;
|
|
109
|
-
if (typeof yaml.stringify === "function")
|
|
110
|
-
return yaml.stringify(content);
|
|
111
|
-
return JSON.stringify(content, null, 2);
|
|
112
|
-
}
|
|
113
|
-
export function loadYaml(content) {
|
|
114
|
-
return Bun.YAML.parse(content);
|
|
115
|
-
}
|
|
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/index.js
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./config";
|
|
3
|
-
export * from "./equal";
|
|
4
|
-
export * from "./errors";
|
|
5
|
-
export * from "./export-size";
|
|
6
|
-
export * from "./find";
|
|
7
|
-
export * from "./git";
|
|
8
|
-
export * from "./hash";
|
|
9
|
-
export * from "./helpers";
|
|
10
|
-
export * from "./macroable";
|
|
11
|
-
export * from "./safe-json";
|
|
12
|
-
export * from "./versions";
|
|
13
|
-
export * as browserUtils from "@stacksjs/browser";
|
|
14
|
-
export { clamp, notNullish, retry, useOnline } from "@stacksjs/browser";
|
|
15
|
-
export * from "./merge";
|
|
16
|
-
export * from "./detect";
|
|
17
|
-
export * from "./debounce";
|
|
18
|
-
export * from "./bytes";
|
|
19
|
-
export * from "./colors";
|
|
20
|
-
export * from "./markdown";
|
|
21
|
-
export * from "./size";
|
|
22
|
-
export * from "./observer";
|
|
23
|
-
export * from "./pipeline";
|
|
1
|
+
export*from"./clean";export*from"./config";export*from"./equal";export*from"./errors";export*from"./export-size";export*from"./find";export*from"./git";export*from"./hash";export*from"./helpers";export*from"./macroable";export*from"./safe-json";export*from"./versions";export* as browserUtils from"@stacksjs/browser";export{clamp,notNullish,retry,useOnline}from"@stacksjs/browser";export*from"./merge";export*from"./detect";export*from"./debounce";export*from"./bytes";export*from"./colors";export*from"./markdown";export*from"./size";export*from"./observer";export*from"./pipeline";
|
package/dist/macroable.js
CHANGED
|
@@ -1,121 +1 @@
|
|
|
1
|
-
export class Macroable {
|
|
2
|
-
static macros = new Map;
|
|
3
|
-
static macro(name, fn, replace = !1) {
|
|
4
|
-
if (this.macros.has(name) && !replace)
|
|
5
|
-
throw Error(`Macro "${name}" is already registered`);
|
|
6
|
-
this.macros.set(name, fn);
|
|
7
|
-
Object.defineProperty(this.prototype, name, {
|
|
8
|
-
value: fn,
|
|
9
|
-
writable: !0,
|
|
10
|
-
configurable: !0,
|
|
11
|
-
enumerable: !1
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
static mixin(obj, replace = !0) {
|
|
15
|
-
const methods = Object.getOwnPropertyNames(obj);
|
|
16
|
-
for (const method of methods) {
|
|
17
|
-
if (method === "constructor")
|
|
18
|
-
continue;
|
|
19
|
-
if (this.macros.has(method) && !replace)
|
|
20
|
-
continue;
|
|
21
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, method);
|
|
22
|
-
if (descriptor && typeof descriptor.value === "function")
|
|
23
|
-
this.macro(method, descriptor.value, replace);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
static hasMacro(name) {
|
|
27
|
-
return this.macros.has(name);
|
|
28
|
-
}
|
|
29
|
-
static flushMacros() {
|
|
30
|
-
for (const name of this.macros.keys())
|
|
31
|
-
delete this.prototype[name];
|
|
32
|
-
this.macros.clear();
|
|
33
|
-
}
|
|
34
|
-
static getMacros() {
|
|
35
|
-
return Array.from(this.macros.keys());
|
|
36
|
-
}
|
|
37
|
-
callMacro(name, ...args) {
|
|
38
|
-
const macro = this.constructor.macros.get(name);
|
|
39
|
-
if (!macro)
|
|
40
|
-
throw Error(`Macro "${name}" is not registered`);
|
|
41
|
-
return macro.apply(this, args);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export function createMacroable(BaseClass = class {
|
|
45
|
-
}) {
|
|
46
|
-
return class extends BaseClass {
|
|
47
|
-
static macros = new Map;
|
|
48
|
-
static macro(name, fn, replace = !1) {
|
|
49
|
-
if (this.macros.has(name) && !replace)
|
|
50
|
-
throw Error(`Macro "${name}" is already registered`);
|
|
51
|
-
this.macros.set(name, fn);
|
|
52
|
-
Object.defineProperty(this.prototype, name, {
|
|
53
|
-
value: fn,
|
|
54
|
-
writable: !0,
|
|
55
|
-
configurable: !0,
|
|
56
|
-
enumerable: !1
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
static mixin(obj, replace = !0) {
|
|
60
|
-
const methods = Object.getOwnPropertyNames(obj);
|
|
61
|
-
for (const method of methods) {
|
|
62
|
-
if (method === "constructor")
|
|
63
|
-
continue;
|
|
64
|
-
if (this.macros.has(method) && !replace)
|
|
65
|
-
continue;
|
|
66
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, method);
|
|
67
|
-
if (descriptor && typeof descriptor.value === "function")
|
|
68
|
-
this.macro(method, descriptor.value, replace);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
static hasMacro(name) {
|
|
72
|
-
return this.macros.has(name);
|
|
73
|
-
}
|
|
74
|
-
static flushMacros() {
|
|
75
|
-
for (const name of this.macros.keys())
|
|
76
|
-
delete this.prototype[name];
|
|
77
|
-
this.macros.clear();
|
|
78
|
-
}
|
|
79
|
-
static getMacros() {
|
|
80
|
-
return Array.from(this.macros.keys());
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
export function macroable(target) {
|
|
85
|
-
const macros = new Map;
|
|
86
|
-
target.macro = function(name, fn, replace = !1) {
|
|
87
|
-
if (macros.has(name) && !replace)
|
|
88
|
-
throw Error(`Macro "${name}" is already registered`);
|
|
89
|
-
macros.set(name, fn);
|
|
90
|
-
Object.defineProperty(target.prototype, name, {
|
|
91
|
-
value: fn,
|
|
92
|
-
writable: !0,
|
|
93
|
-
configurable: !0,
|
|
94
|
-
enumerable: !1
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
target.mixin = function(obj, replace = !0) {
|
|
98
|
-
const methods = Object.getOwnPropertyNames(obj);
|
|
99
|
-
for (const method of methods) {
|
|
100
|
-
if (method === "constructor")
|
|
101
|
-
continue;
|
|
102
|
-
if (macros.has(method) && !replace)
|
|
103
|
-
continue;
|
|
104
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, method);
|
|
105
|
-
if (descriptor && typeof descriptor.value === "function")
|
|
106
|
-
target.macro(method, descriptor.value, replace);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
target.hasMacro = function(name) {
|
|
110
|
-
return macros.has(name);
|
|
111
|
-
};
|
|
112
|
-
target.flushMacros = function() {
|
|
113
|
-
for (const name of macros.keys())
|
|
114
|
-
delete target.prototype[name];
|
|
115
|
-
macros.clear();
|
|
116
|
-
};
|
|
117
|
-
target.getMacros = function() {
|
|
118
|
-
return Array.from(macros.keys());
|
|
119
|
-
};
|
|
120
|
-
return target;
|
|
121
|
-
}
|
|
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;target.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})};target.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")target.macro(method,descriptor.value,replace)}};target.hasMacro=function(name){return macros.has(name)};target.flushMacros=function(){for(const name of macros.keys())delete target.prototype[name];macros.clear()};target.getMacros=function(){return Array.from(macros.keys())};return target}
|
package/dist/markdown.js
CHANGED
|
@@ -1,92 +1,2 @@
|
|
|
1
|
-
export function markdownTable(table,
|
|
2
|
-
|
|
3
|
-
align = [],
|
|
4
|
-
padding = !0,
|
|
5
|
-
delimiter = "|",
|
|
6
|
-
delimiterStart = !0,
|
|
7
|
-
delimiterEnd = !0,
|
|
8
|
-
alignDelimiter = "-"
|
|
9
|
-
} = options;
|
|
10
|
-
if (!table || table.length === 0)
|
|
11
|
-
return "";
|
|
12
|
-
const normalized = table.map((row) => row.map((cell) => {
|
|
13
|
-
if (cell === null || cell === void 0)
|
|
14
|
-
return "";
|
|
15
|
-
return String(cell);
|
|
16
|
-
})), columnCount = Math.max(...normalized.map((row) => row.length)), columnWidths = Array.from({ length: columnCount }).fill(0);
|
|
17
|
-
for (const row of normalized)
|
|
18
|
-
for (let i = 0;i < row.length; i++) {
|
|
19
|
-
const cellLength = row[i]?.length ?? 0;
|
|
20
|
-
if (cellLength > (columnWidths[i] ?? 0))
|
|
21
|
-
columnWidths[i] = cellLength;
|
|
22
|
-
}
|
|
23
|
-
const rows = [];
|
|
24
|
-
if (normalized.length > 0) {
|
|
25
|
-
const header = normalized[0] ?? [];
|
|
26
|
-
rows.push(buildRow(header, columnWidths, padding, delimiter, delimiterStart, delimiterEnd));
|
|
27
|
-
const separatorCells = columnWidths.map((width, index) => {
|
|
28
|
-
const alignment = normalizeAlignment(align[index]);
|
|
29
|
-
return buildSeparator(width, alignment, alignDelimiter);
|
|
30
|
-
});
|
|
31
|
-
rows.push(buildRow(separatorCells, columnWidths, padding, delimiter, delimiterStart, delimiterEnd));
|
|
32
|
-
for (let i = 1;i < normalized.length; i++) {
|
|
33
|
-
const dataRow = normalized[i] ?? [];
|
|
34
|
-
rows.push(buildRow(dataRow, columnWidths, padding, delimiter, delimiterStart, delimiterEnd));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return rows.join(`
|
|
38
|
-
`);
|
|
39
|
-
}
|
|
40
|
-
function buildRow(cells, columnWidths, padding, delimiter, delimiterStart, delimiterEnd) {
|
|
41
|
-
const paddedCells = cells.map((cell, index) => {
|
|
42
|
-
const width = columnWidths[index] ?? 0;
|
|
43
|
-
return cell.padEnd(width, " ");
|
|
44
|
-
}), space = padding ? " " : "";
|
|
45
|
-
let row = paddedCells.map((cell) => `${space}${cell}${space}`).join(delimiter);
|
|
46
|
-
if (delimiterStart)
|
|
47
|
-
row = delimiter + row;
|
|
48
|
-
if (delimiterEnd)
|
|
49
|
-
row = row + delimiter;
|
|
50
|
-
return row;
|
|
51
|
-
}
|
|
52
|
-
function buildSeparator(width, alignment, char) {
|
|
53
|
-
const minWidth = alignment === "center" ? 3 : alignment ? 2 : 1;
|
|
54
|
-
if (width < minWidth)
|
|
55
|
-
width = minWidth;
|
|
56
|
-
let separator = char.repeat(width);
|
|
57
|
-
if (alignment === "left")
|
|
58
|
-
separator = `:${separator.slice(1)}`;
|
|
59
|
-
else if (alignment === "right")
|
|
60
|
-
separator = separator.slice(0, -1) + ":";
|
|
61
|
-
else if (alignment === "center")
|
|
62
|
-
separator = `:${separator.slice(2)}:`;
|
|
63
|
-
return separator;
|
|
64
|
-
}
|
|
65
|
-
function normalizeAlignment(align) {
|
|
66
|
-
if (!align)
|
|
67
|
-
return null;
|
|
68
|
-
switch (align) {
|
|
69
|
-
case "l":
|
|
70
|
-
case "left":
|
|
71
|
-
return "left";
|
|
72
|
-
case "c":
|
|
73
|
-
case "center":
|
|
74
|
-
return "center";
|
|
75
|
-
case "r":
|
|
76
|
-
case "right":
|
|
77
|
-
return "right";
|
|
78
|
-
default:
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export function markdownTableFromObjects(objects, options = {}) {
|
|
83
|
-
if (!objects || objects.length === 0)
|
|
84
|
-
return "";
|
|
85
|
-
const keys = Array.from(new Set(objects.flatMap((obj) => Object.keys(obj)))), table = [
|
|
86
|
-
keys,
|
|
87
|
-
...objects.map((obj) => keys.map((key) => obj[key]))
|
|
88
|
-
];
|
|
89
|
-
return markdownTable(table, options);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { markdownTable as default };
|
|
1
|
+
export function markdownTable(table,options={}){const{align=[],padding=!0,delimiter="|",delimiterStart=!0,delimiterEnd=!0,alignDelimiter="-"}=options;if(!table||table.length===0)return"";const normalized=table.map((row)=>row.map((cell)=>{if(cell===null||cell===void 0)return"";return String(cell)})),columnCount=Math.max(...normalized.map((row)=>row.length)),columnWidths=Array.from({length:columnCount}).fill(0);for(const row of normalized)for(let i=0;i<row.length;i++){const cellLength=row[i]?.length??0;if(cellLength>(columnWidths[i]??0))columnWidths[i]=cellLength}const rows=[];if(normalized.length>0){const header=normalized[0]??[];rows.push(buildRow(header,columnWidths,padding,delimiter,delimiterStart,delimiterEnd));const separatorCells=columnWidths.map((width,index)=>{const alignment=normalizeAlignment(align[index]);return buildSeparator(width,alignment,alignDelimiter)});rows.push(buildRow(separatorCells,columnWidths,padding,delimiter,delimiterStart,delimiterEnd));for(let i=1;i<normalized.length;i++){const dataRow=normalized[i]??[];rows.push(buildRow(dataRow,columnWidths,padding,delimiter,delimiterStart,delimiterEnd))}}return rows.join(`
|
|
2
|
+
`)}function buildRow(cells,columnWidths,padding,delimiter,delimiterStart,delimiterEnd){const paddedCells=cells.map((cell,index)=>{const width=columnWidths[index]??0;return cell.padEnd(width," ")}),space=padding?" ":"";let row=paddedCells.map((cell)=>`${space}${cell}${space}`).join(delimiter);if(delimiterStart)row=delimiter+row;if(delimiterEnd)row=row+delimiter;return row}function buildSeparator(width,alignment,char){const minWidth=alignment==="center"?3:alignment?2:1;if(width<minWidth)width=minWidth;let separator=char.repeat(width);if(alignment==="left")separator=`:${separator.slice(1)}`;else if(alignment==="right")separator=separator.slice(0,-1)+":";else if(alignment==="center")separator=`:${separator.slice(2)}:`;return separator}function normalizeAlignment(align){if(!align)return null;switch(align){case"l":case"left":return"left";case"c":case"center":return"center";case"r":case"right":return"right";default:return null}}export function markdownTableFromObjects(objects,options={}){if(!objects||objects.length===0)return"";const keys=Array.from(new Set(objects.flatMap((obj)=>Object.keys(obj)))),table=[keys,...objects.map((obj)=>keys.map((key)=>obj[key]))];return markdownTable(table,options)}export{markdownTable as default};
|
package/dist/merge.js
CHANGED
|
@@ -1,51 +1 @@
|
|
|
1
|
-
export function merge(...objects) {
|
|
2
|
-
const result = {};
|
|
3
|
-
for (const obj of objects) {
|
|
4
|
-
if (!obj || typeof obj !== "object")
|
|
5
|
-
continue;
|
|
6
|
-
for (const key in obj) {
|
|
7
|
-
const value = obj[key], existing = result[key];
|
|
8
|
-
if (value === void 0)
|
|
9
|
-
continue;
|
|
10
|
-
if (Array.isArray(value))
|
|
11
|
-
result[key] = Array.isArray(existing) ? [...existing, ...value] : [...value];
|
|
12
|
-
else if (value && typeof value === "object" && !isSpecialObject(value))
|
|
13
|
-
result[key] = merge(existing || {}, value);
|
|
14
|
-
else
|
|
15
|
-
result[key] = value;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
export function createMerger(defaults) {
|
|
21
|
-
return (...objects) => {
|
|
22
|
-
return merge(defaults, ...objects);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export function mergeDefaults(obj, ...defaults) {
|
|
26
|
-
return merge({}, ...defaults, obj);
|
|
27
|
-
}
|
|
28
|
-
function isSpecialObject(obj) {
|
|
29
|
-
if (obj instanceof Date)
|
|
30
|
-
return !0;
|
|
31
|
-
if (obj instanceof RegExp)
|
|
32
|
-
return !0;
|
|
33
|
-
if (obj instanceof Error)
|
|
34
|
-
return !0;
|
|
35
|
-
if (obj instanceof Promise)
|
|
36
|
-
return !0;
|
|
37
|
-
if (obj instanceof Map)
|
|
38
|
-
return !0;
|
|
39
|
-
if (obj instanceof Set)
|
|
40
|
-
return !0;
|
|
41
|
-
if (obj instanceof WeakMap)
|
|
42
|
-
return !0;
|
|
43
|
-
if (obj instanceof WeakSet)
|
|
44
|
-
return !0;
|
|
45
|
-
if (ArrayBuffer.isView(obj))
|
|
46
|
-
return !0;
|
|
47
|
-
return !1;
|
|
48
|
-
}
|
|
49
|
-
export const defu = mergeDefaults, defuArrayFn = merge;
|
|
50
|
-
|
|
51
|
-
export { merge as default };
|
|
1
|
+
export function merge(...objects){const result={};for(const obj of objects){if(!obj||typeof obj!=="object")continue;for(const key in obj){const value=obj[key],existing=result[key];if(value===void 0)continue;if(Array.isArray(value))result[key]=Array.isArray(existing)?[...existing,...value]:[...value];else if(value&&typeof value==="object"&&!isSpecialObject(value))result[key]=merge(existing||{},value);else result[key]=value}}return result}export function createMerger(defaults){return(...objects)=>{return merge(defaults,...objects)}}export function mergeDefaults(obj,...defaults){return merge({},...defaults,obj)}function isSpecialObject(obj){if(obj instanceof Date)return!0;if(obj instanceof RegExp)return!0;if(obj instanceof Error)return!0;if(obj instanceof Promise)return!0;if(obj instanceof Map)return!0;if(obj instanceof Set)return!0;if(obj instanceof WeakMap)return!0;if(obj instanceof WeakSet)return!0;if(ArrayBuffer.isView(obj))return!0;return!1}export const defu=mergeDefaults,defuArrayFn=merge;export{merge as default};
|
package/dist/observer.js
CHANGED
|
@@ -1,78 +1 @@
|
|
|
1
|
-
export function isResizeObserverSupported() {
|
|
2
|
-
return typeof window < "u" && "ResizeObserver" in window;
|
|
3
|
-
}
|
|
4
|
-
export function getResizeObserver() {
|
|
5
|
-
if (isResizeObserverSupported())
|
|
6
|
-
return window.ResizeObserver;
|
|
7
|
-
return class ResizeObserverPolyfill {
|
|
8
|
-
callback;
|
|
9
|
-
observedElements = new Set;
|
|
10
|
-
rafId = null;
|
|
11
|
-
constructor(callback) {
|
|
12
|
-
this.callback = callback;
|
|
13
|
-
}
|
|
14
|
-
observe(target) {
|
|
15
|
-
if (!this.observedElements.has(target)) {
|
|
16
|
-
this.observedElements.add(target);
|
|
17
|
-
this.scheduleCheck();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
unobserve(target) {
|
|
21
|
-
this.observedElements.delete(target);
|
|
22
|
-
if (this.observedElements.size === 0 && this.rafId !== null) {
|
|
23
|
-
(typeof cancelAnimationFrame < "u" ? cancelAnimationFrame : clearTimeout)(this.rafId);
|
|
24
|
-
this.rafId = null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
disconnect() {
|
|
28
|
-
this.observedElements.clear();
|
|
29
|
-
if (this.rafId !== null) {
|
|
30
|
-
(typeof cancelAnimationFrame < "u" ? cancelAnimationFrame : clearTimeout)(this.rafId);
|
|
31
|
-
this.rafId = null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
scheduleCheck() {
|
|
35
|
-
if (this.rafId !== null)
|
|
36
|
-
return;
|
|
37
|
-
const raf = typeof requestAnimationFrame < "u" ? requestAnimationFrame : setTimeout;
|
|
38
|
-
this.rafId = raf(() => {
|
|
39
|
-
this.check();
|
|
40
|
-
this.rafId = null;
|
|
41
|
-
if (this.observedElements.size > 0)
|
|
42
|
-
this.scheduleCheck();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
check() {
|
|
46
|
-
const entries = [];
|
|
47
|
-
for (const element of this.observedElements) {
|
|
48
|
-
const rect = element.getBoundingClientRect(), entry = {
|
|
49
|
-
target: element,
|
|
50
|
-
contentRect: rect,
|
|
51
|
-
borderBoxSize: [{ inlineSize: rect.width, blockSize: rect.height }],
|
|
52
|
-
contentBoxSize: [{ inlineSize: rect.width, blockSize: rect.height }],
|
|
53
|
-
devicePixelContentBoxSize: [{ inlineSize: rect.width, blockSize: rect.height }]
|
|
54
|
-
};
|
|
55
|
-
entries.push(entry);
|
|
56
|
-
}
|
|
57
|
-
if (entries.length > 0)
|
|
58
|
-
this.callback(entries, this);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
export function createResizeObserver(callback, target) {
|
|
63
|
-
const observer = new (getResizeObserver())(callback), targets = Array.isArray(target) ? target : [target];
|
|
64
|
-
for (const element of targets)
|
|
65
|
-
observer.observe(element);
|
|
66
|
-
return () => {
|
|
67
|
-
observer.disconnect();
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
export function observeElementSize(element, callback) {
|
|
71
|
-
return createResizeObserver((entries) => {
|
|
72
|
-
const entry = entries.find((e) => e.target === element);
|
|
73
|
-
if (entry)
|
|
74
|
-
callback(entry);
|
|
75
|
-
}, element);
|
|
76
|
-
}
|
|
77
|
-
export const ResizeObserver = getResizeObserver();
|
|
78
|
-
export default ResizeObserver;
|
|
1
|
+
export function isResizeObserverSupported(){return typeof window<"u"&&"ResizeObserver"in window}export function getResizeObserver(){if(isResizeObserverSupported())return window.ResizeObserver;return class ResizeObserverPolyfill{callback;observedElements=new Set;rafId=null;constructor(callback){this.callback=callback}observe(target){if(!this.observedElements.has(target)){this.observedElements.add(target);this.scheduleCheck()}}unobserve(target){this.observedElements.delete(target);if(this.observedElements.size===0&&this.rafId!==null){(typeof cancelAnimationFrame<"u"?cancelAnimationFrame:clearTimeout)(this.rafId);this.rafId=null}}disconnect(){this.observedElements.clear();if(this.rafId!==null){(typeof cancelAnimationFrame<"u"?cancelAnimationFrame:clearTimeout)(this.rafId);this.rafId=null}}scheduleCheck(){if(this.rafId!==null)return;const raf=typeof requestAnimationFrame<"u"?requestAnimationFrame:setTimeout;this.rafId=raf(()=>{this.check();this.rafId=null;if(this.observedElements.size>0)this.scheduleCheck()})}check(){const entries=[];for(const element of this.observedElements){const rect=element.getBoundingClientRect(),entry={target:element,contentRect:rect,borderBoxSize:[{inlineSize:rect.width,blockSize:rect.height}],contentBoxSize:[{inlineSize:rect.width,blockSize:rect.height}],devicePixelContentBoxSize:[{inlineSize:rect.width,blockSize:rect.height}]};entries.push(entry)}if(entries.length>0)this.callback(entries,this)}}}export function createResizeObserver(callback,target){const observer=new(getResizeObserver())(callback),targets=Array.isArray(target)?target:[target];for(const element of targets)observer.observe(element);return()=>{observer.disconnect()}}export function observeElementSize(element,callback){return createResizeObserver((entries)=>{const entry=entries.find((e)=>e.target===element);if(entry)callback(entry)},element)}export const ResizeObserver=getResizeObserver();export default ResizeObserver;
|
package/dist/pipeline.js
CHANGED
|
@@ -1,37 +1 @@
|
|
|
1
|
-
export class Pipeline {
|
|
2
|
-
passable;
|
|
3
|
-
pipes = [];
|
|
4
|
-
method = "handle";
|
|
5
|
-
static send(passable) {
|
|
6
|
-
const pipeline = new Pipeline;
|
|
7
|
-
pipeline.passable = passable;
|
|
8
|
-
return pipeline;
|
|
9
|
-
}
|
|
10
|
-
through(pipes) {
|
|
11
|
-
this.pipes = pipes;
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
pipe(...pipes) {
|
|
15
|
-
this.pipes.push(...pipes);
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
via(method) {
|
|
19
|
-
this.method = method;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
then(destination) {
|
|
23
|
-
return this.pipes.reduceRight((next, pipe) => {
|
|
24
|
-
return (passable) => {
|
|
25
|
-
if (typeof pipe === "function")
|
|
26
|
-
return pipe(passable, next);
|
|
27
|
-
const handler = pipe[this.method];
|
|
28
|
-
if (typeof handler === "function")
|
|
29
|
-
return handler.call(pipe, passable, next);
|
|
30
|
-
return next(passable);
|
|
31
|
-
};
|
|
32
|
-
}, destination)(this.passable);
|
|
33
|
-
}
|
|
34
|
-
thenReturn() {
|
|
35
|
-
return this.then((passable) => passable);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
export class Pipeline{passable;pipes=[];method="handle";static send(passable){const pipeline=new Pipeline;pipeline.passable=passable;return pipeline}through(pipes){this.pipes=pipes;return this}pipe(...pipes){this.pipes.push(...pipes);return this}via(method){this.method=method;return this}then(destination){return this.pipes.reduceRight((next,pipe)=>{return(passable)=>{if(typeof pipe==="function")return pipe(passable,next);const handler=pipe[this.method];if(typeof handler==="function")return handler.call(pipe,passable,next);return next(passable)}},destination)(this.passable)}thenReturn(){return this.then((passable)=>passable)}}
|
package/dist/safe-json.js
CHANGED
|
@@ -1,33 +1 @@
|
|
|
1
|
-
export function safeJsonParse(text, defaultValue) {
|
|
2
|
-
if (typeof text !== "string" || text.length === 0)
|
|
3
|
-
return defaultValue;
|
|
4
|
-
try {
|
|
5
|
-
return JSON.parse(text);
|
|
6
|
-
} catch {
|
|
7
|
-
return defaultValue;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export function safeJsonParseResult(text) {
|
|
11
|
-
if (typeof text !== "string")
|
|
12
|
-
return { ok: !1, reason: "not-string" };
|
|
13
|
-
if (text.length === 0)
|
|
14
|
-
return { ok: !1, reason: "empty" };
|
|
15
|
-
try {
|
|
16
|
-
return { ok: !0, value: JSON.parse(text) };
|
|
17
|
-
} catch (err) {
|
|
18
|
-
return { ok: !1, reason: "malformed", error: err };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export function safeJsonStringify(value, space) {
|
|
22
|
-
const seen = new WeakSet;
|
|
23
|
-
return JSON.stringify(value, (_key, v) => {
|
|
24
|
-
if (typeof v === "bigint")
|
|
25
|
-
return v.toString();
|
|
26
|
-
if (v && typeof v === "object") {
|
|
27
|
-
if (seen.has(v))
|
|
28
|
-
return "[Circular]";
|
|
29
|
-
seen.add(v);
|
|
30
|
-
}
|
|
31
|
-
return v;
|
|
32
|
-
}, space);
|
|
33
|
-
}
|
|
1
|
+
export function safeJsonParse(text,defaultValue){if(typeof text!=="string"||text.length===0)return defaultValue;try{return JSON.parse(text)}catch{return defaultValue}}export function safeJsonParseResult(text){if(typeof text!=="string")return{ok:!1,reason:"not-string"};if(text.length===0)return{ok:!1,reason:"empty"};try{return{ok:!0,value:JSON.parse(text)}}catch(err){return{ok:!1,reason:"malformed",error:err}}}export function safeJsonStringify(value,space){const seen=new WeakSet;return JSON.stringify(value,(_key,v)=>{if(typeof v==="bigint")return v.toString();if(v&&typeof v==="object"){if(seen.has(v))return"[Circular]";seen.add(v)}return v},space)}
|
package/dist/size.js
CHANGED
|
@@ -1,66 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export async function getFileSize(filePath) {
|
|
5
|
-
try {
|
|
6
|
-
return (await stat(filePath)).size;
|
|
7
|
-
} catch {
|
|
8
|
-
return 0;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export async function getExportsSize(distPath) {
|
|
12
|
-
const exports = [];
|
|
13
|
-
let totalSize = 0;
|
|
14
|
-
try {
|
|
15
|
-
const files = await getAllJsFiles(distPath);
|
|
16
|
-
for (const file of files) {
|
|
17
|
-
const size = await getFileSize(file.path);
|
|
18
|
-
totalSize += size;
|
|
19
|
-
exports.push({
|
|
20
|
-
name: file.name,
|
|
21
|
-
size,
|
|
22
|
-
readable: formatBytes(size)
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
} catch (error) {}
|
|
26
|
-
return {
|
|
27
|
-
totalSize,
|
|
28
|
-
totalReadable: formatBytes(totalSize),
|
|
29
|
-
exports: exports.sort((a, b) => b.size - a.size)
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
async function getAllJsFiles(dir) {
|
|
33
|
-
const files = [];
|
|
34
|
-
try {
|
|
35
|
-
const entries = await Bun.$.throws(!1)`find ${dir} -type f \\( -name "*.js" -o -name "*.mjs" -o -name "*.cjs" \\)`.text();
|
|
36
|
-
for (const entry of entries.split(`
|
|
37
|
-
`).filter(Boolean)) {
|
|
38
|
-
const name = entry.replace(dir, "").replace(/^\//, "");
|
|
39
|
-
files.push({ name, path: entry });
|
|
40
|
-
}
|
|
41
|
-
} catch {}
|
|
42
|
-
return files;
|
|
43
|
-
}
|
|
44
|
-
export function estimateGzipSize(size) {
|
|
45
|
-
return Math.floor(size * 0.3);
|
|
46
|
-
}
|
|
47
|
-
export function estimateBrotliSize(size) {
|
|
48
|
-
return Math.floor(size * 0.25);
|
|
49
|
-
}
|
|
50
|
-
export function formatExportSizes(result) {
|
|
51
|
-
if (result.exports.length === 0)
|
|
52
|
-
return "No exports found";
|
|
53
|
-
const lines = ["Export Sizes:", ""], maxNameLength = Math.max(...result.exports.map((e) => e.name.length));
|
|
54
|
-
for (const exp of result.exports) {
|
|
55
|
-
const name = exp.name.padEnd(maxNameLength, " ");
|
|
56
|
-
lines.push(` ${name} ${exp.readable}`);
|
|
57
|
-
}
|
|
58
|
-
lines.push("");
|
|
59
|
-
lines.push(`Total: ${result.totalReadable}`);
|
|
60
|
-
lines.push(`Estimated gzipped: ${formatBytes(estimateGzipSize(result.totalSize))}`);
|
|
61
|
-
lines.push(`Estimated brotli: ${formatBytes(estimateBrotliSize(result.totalSize))}`);
|
|
62
|
-
return lines.join(`
|
|
63
|
-
`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { getExportsSize as default };
|
|
1
|
+
import{stat}from"node:fs/promises";import{join}from"node:path";import{formatBytes}from"./bytes";export async function getFileSize(filePath){try{return(await stat(filePath)).size}catch{return 0}}export async function getExportsSize(distPath){const exports=[];let totalSize=0;try{const files=await getAllJsFiles(distPath);for(const file of files){const size=await getFileSize(file.path);totalSize+=size;exports.push({name:file.name,size,readable:formatBytes(size)})}}catch(error){}return{totalSize,totalReadable:formatBytes(totalSize),exports:exports.sort((a,b)=>b.size-a.size)}}async function getAllJsFiles(dir){const files=[];try{const entries=await Bun.$.throws(!1)`find ${dir} -type f \\( -name "*.js" -o -name "*.mjs" -o -name "*.cjs" \\)`.text();for(const entry of entries.split(`
|
|
2
|
+
`).filter(Boolean)){const name=entry.replace(dir,"").replace(/^\//,"");files.push({name,path:entry})}}catch{}return files}export function estimateGzipSize(size){return Math.floor(size*0.3)}export function estimateBrotliSize(size){return Math.floor(size*0.25)}export function formatExportSizes(result){if(result.exports.length===0)return"No exports found";const lines=["Export Sizes:",""],maxNameLength=Math.max(...result.exports.map((e)=>e.name.length));for(const exp of result.exports){const name=exp.name.padEnd(maxNameLength," ");lines.push(` ${name} ${exp.readable}`)}lines.push("");lines.push(`Total: ${result.totalReadable}`);lines.push(`Estimated gzipped: ${formatBytes(estimateGzipSize(result.totalSize))}`);lines.push(`Estimated brotli: ${formatBytes(estimateBrotliSize(result.totalSize))}`);return lines.join(`
|
|
3
|
+
`)}export{getExportsSize as default};
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
var __dirname = "";
|
|
2
|
-
import { resolve } from "@stacksjs/path";
|
|
3
|
-
import { fs } from "@stacksjs/storage";
|
|
4
|
-
import { kebabCase } from "@stacksjs/strings";
|
|
5
|
-
const ignore = ["readme-md"];
|
|
6
|
-
export const components = fs.readdirSync(resolve(__dirname, "./resources/components")).map((item) => kebabCase(item.replace(/\.stx/g, ""))).filter((item) => !ignore.includes(item)), functions = fs.readdirSync(resolve(__dirname, "./resources/functions")).map((item) => kebabCase(item.replace(/.ts/g, ""))).filter((item) => !ignore.includes(item));
|
|
1
|
+
var __dirname="";import{resolve}from"@stacksjs/path";import{fs}from"@stacksjs/storage";import{kebabCase}from"@stacksjs/strings";const ignore=["readme-md"];export const components=fs.readdirSync(resolve(__dirname,"./resources/components")).map((item)=>kebabCase(item.replace(/\.stx/g,""))).filter((item)=>!ignore.includes(item)),functions=fs.readdirSync(resolve(__dirname,"./resources/functions")).map((item)=>kebabCase(item.replace(/.ts/g,""))).filter((item)=>!ignore.includes(item));
|