mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 02:44:45 +00:00
feat(packages/platform): init new package
This commit is contained in:
@@ -15,18 +15,18 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/robonen/tools.git"
|
"url": "git+https://github.com/robonen/tools.git"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.1.3",
|
"packageManager": "pnpm@9.4.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.13.1"
|
"node": ">=20.13.1"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.12.13",
|
"@types/node": "^20.14.8",
|
||||||
"citty": "^0.1.6",
|
"citty": "^0.1.6",
|
||||||
"jiti": "^1.21.0",
|
"jiti": "^1.21.6",
|
||||||
"pathe": "^1.1.2",
|
"pathe": "^1.1.2",
|
||||||
"scule": "^1.3.0",
|
"scule": "^1.3.0",
|
||||||
"vitepress": "^1.2.2"
|
"vitepress": "^1.2.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"all:test": "pnpm -r test",
|
"all:test": "pnpm -r test",
|
||||||
|
|||||||
1
packages/platform/README.md
Normal file
1
packages/platform/README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# @robonen/platform
|
||||||
5
packages/platform/jsr.json
Normal file
5
packages/platform/jsr.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "@robonen/platform",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"exports": "./src/index.ts"
|
||||||
|
}
|
||||||
38
packages/platform/package.json
Normal file
38
packages/platform/package.json
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"name": "@robonen/platform",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"license": "UNLICENSED",
|
||||||
|
"description": "",
|
||||||
|
"keywords": [],
|
||||||
|
"author": "Robonen Andrew <robonenandrew@gmail.com>",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/robonen/tools.git",
|
||||||
|
"directory": "./packages/platform"
|
||||||
|
},
|
||||||
|
"packageManager": "pnpm@9.4.0",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.13.1"
|
||||||
|
},
|
||||||
|
"type": "module",
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"main": "./dist/index.umd.js",
|
||||||
|
"module": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"import": "./dist/index.js",
|
||||||
|
"require": "./dist/index.umd.js",
|
||||||
|
"types": "./dist/index.d.ts"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@robonen/tsconfig": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
||||||
47
packages/platform/src/multi/debounce/index.ts
Normal file
47
packages/platform/src/multi/debounce/index.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
export interface DebounceOptions {
|
||||||
|
/**
|
||||||
|
* Call the function on the leading edge of the timeout, instead of waiting for the trailing edge
|
||||||
|
*/
|
||||||
|
readonly immediate?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the function on the trailing edge with the last used arguments.
|
||||||
|
* Result of call is from previous call
|
||||||
|
*/
|
||||||
|
readonly trailing?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_DEBOUNCE_OPTIONS: DebounceOptions = {
|
||||||
|
trailing: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function debounce<FnArguments extends unknown[], FnReturn>(
|
||||||
|
fn: (...args: FnArguments) => PromiseLike<FnReturn> | FnReturn,
|
||||||
|
timeout: number = 20,
|
||||||
|
options: DebounceOptions = {},
|
||||||
|
) {
|
||||||
|
options = {
|
||||||
|
...DEFAULT_DEBOUNCE_OPTIONS,
|
||||||
|
...options,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!Number.isFinite(timeout) || timeout <= 0)
|
||||||
|
throw new TypeError('Debounce timeout must be a positive number');
|
||||||
|
|
||||||
|
// Last result for leading edge
|
||||||
|
let leadingValue: PromiseLike<FnReturn> | FnReturn;
|
||||||
|
|
||||||
|
// Debounce timeout id
|
||||||
|
let timeoutId: NodeJS.Timeout;
|
||||||
|
|
||||||
|
// Promises to be resolved when debounce is finished
|
||||||
|
let resolveList: Array<(value: unknown) => void> = [];
|
||||||
|
|
||||||
|
// State of currently resolving promise
|
||||||
|
let currentResolve: Promise<FnReturn>;
|
||||||
|
|
||||||
|
// Trailing call information
|
||||||
|
let trailingArgs: unknown[];
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
15
packages/platform/src/multi/global/index.ts
Normal file
15
packages/platform/src/multi/global/index.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* @name _global
|
||||||
|
* @category Multi
|
||||||
|
* @description Global object that works in any environment
|
||||||
|
*/
|
||||||
|
export const _global =
|
||||||
|
typeof globalThis !== 'undefined'
|
||||||
|
? globalThis
|
||||||
|
: typeof window !== 'undefined'
|
||||||
|
? window
|
||||||
|
: typeof global !== 'undefined'
|
||||||
|
? global
|
||||||
|
: typeof self !== 'undefined'
|
||||||
|
? self
|
||||||
|
: {};
|
||||||
2
packages/platform/src/multi/index.ts
Normal file
2
packages/platform/src/multi/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './global';
|
||||||
|
export * from './debounce';
|
||||||
3
packages/platform/tsconfig.json
Normal file
3
packages/platform/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "@robonen/tsconfig/tsconfig.json"
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"url": "git+https://github.com/robonen/tools.git",
|
"url": "git+https://github.com/robonen/tools.git",
|
||||||
"directory": "packages/renovate"
|
"directory": "packages/renovate"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.1.3",
|
"packageManager": "pnpm@9.4.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.13.1"
|
"node": ">=20.13.1"
|
||||||
},
|
},
|
||||||
@@ -27,6 +27,6 @@
|
|||||||
"test": "renovate-config-validator ./default.json"
|
"test": "renovate-config-validator ./default.json"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"renovate": "^37.381.9"
|
"renovate": "^37.415.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"url": "git+https://github.com/robonen/tools.git",
|
"url": "git+https://github.com/robonen/tools.git",
|
||||||
"directory": "packages/stdlib"
|
"directory": "packages/stdlib"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.1.3",
|
"packageManager": "pnpm@9.4.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.13.1"
|
"node": ">=20.13.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"url": "git+https://github.com/robonen/tools.git",
|
"url": "git+https://github.com/robonen/tools.git",
|
||||||
"directory": "packages/tsconfig"
|
"directory": "packages/tsconfig"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.1.3",
|
"packageManager": "pnpm@9.4.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.13.1"
|
"node": ">=20.13.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"url": "git+https://github.com/robonen/tools.git",
|
"url": "git+https://github.com/robonen/tools.git",
|
||||||
"directory": "./packages/vue"
|
"directory": "./packages/vue"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.1.3",
|
"packageManager": "pnpm@9.4.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.13.1"
|
"node": ">=20.13.1"
|
||||||
},
|
},
|
||||||
@@ -41,6 +41,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@robonen/stdlib": "workspace:*",
|
"@robonen/stdlib": "workspace:*",
|
||||||
"vue": "^3.4.27"
|
"vue": "^3.4.30"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3459
pnpm-lock.yaml
generated
3459
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user