my-gadgetry 1.0.0-alpha.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/LICENSE +21 -0
- package/README.md +1 -0
- package/dev-ops/package-generator/generate-alias/package.json +6 -0
- package/dist/_core/type-check.d.ts +10 -0
- package/dist/_core/type-check.js +25 -0
- package/dist/_internal/color.d.ts +2 -0
- package/dist/_internal/color.js +4 -0
- package/dist/_internal/converters/array.d.ts +2 -0
- package/dist/_internal/converters/array.js +2 -0
- package/dist/_internal/converters/number.d.ts +1 -0
- package/dist/_internal/converters/number.js +1 -0
- package/dist/_internal/converters/string.d.ts +5 -0
- package/dist/_internal/converters/string.js +12 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/clean-directories.d.ts +2 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/clean-directories.js +14 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/get-aliases.d.ts +1 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/get-aliases.js +10 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/get-files.d.ts +1 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/get-files.js +14 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/write-package-json.d.ts +1 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/write-package-json.js +21 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias.d.ts +2 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias.js +2 -0
- package/dist/_internal/type-check.d.ts +1 -0
- package/dist/_internal/type-check.js +1 -0
- package/dist/modules/color.d.ts +1 -0
- package/dist/modules/color.js +1 -0
- package/dist/modules/converters/array.d.ts +1 -0
- package/dist/modules/converters/array.js +1 -0
- package/dist/modules/converters/number.d.ts +1 -0
- package/dist/modules/converters/number.js +1 -0
- package/dist/modules/converters/string.d.ts +1 -0
- package/dist/modules/converters/string.js +1 -0
- package/dist/modules/dev-ops/package-generator/generate-alias.d.ts +1 -0
- package/dist/modules/dev-ops/package-generator/generate-alias.js +1 -0
- package/dist/modules/type-check.d.ts +1 -0
- package/dist/modules/type-check.js +1 -0
- package/package.json +93 -0
- package/src/_core/type-check.ts +34 -0
- package/src/_internal/__tests__/color.spec.ts +156 -0
- package/src/_internal/color.ts +7 -0
- package/src/_internal/converters/__tests__/array.spec.ts +9 -0
- package/src/_internal/converters/array.ts +6 -0
- package/src/_internal/converters/number.ts +1 -0
- package/src/_internal/converters/string.ts +22 -0
- package/src/_internal/dev-ops/package-generator/generate-alias/clean-directories.ts +17 -0
- package/src/_internal/dev-ops/package-generator/generate-alias/get-aliases.ts +11 -0
- package/src/_internal/dev-ops/package-generator/generate-alias/get-files.ts +14 -0
- package/src/_internal/dev-ops/package-generator/generate-alias/write-package-json.ts +24 -0
- package/src/_internal/dev-ops/package-generator/generate-alias.ts +2 -0
- package/src/_internal/type-check.ts +1 -0
- package/src/modules/color.ts +1 -0
- package/src/modules/converters/array.ts +1 -0
- package/src/modules/converters/number.ts +1 -0
- package/src/modules/converters/string.ts +1 -0
- package/src/modules/dev-ops/package-generator/generate-alias.ts +1 -0
- package/src/modules/type-check.ts +1 -0
- package/tsconfig.json +26 -0
- package/type-check/package.json +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 cilly
|
|
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
|
+
# my gadgetry
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cilly/my-gadgetry-modules-dev-ops-package-generator-generate-alias",
|
|
3
|
+
"types": "../../../dist/modules/dev-ops/package-generator/generate-alias.d.ts",
|
|
4
|
+
"main": "../../../dist/modules/dev-ops/package-generator/generate-alias.js",
|
|
5
|
+
"sideEffects": false
|
|
6
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const getValueType: (value: any) => string;
|
|
2
|
+
export declare const isNumber: (value: any) => boolean;
|
|
3
|
+
export declare const isBoolean: (value: any) => boolean;
|
|
4
|
+
export declare const isString: (value: any) => boolean;
|
|
5
|
+
export declare const isArray: (value: any) => boolean;
|
|
6
|
+
export declare const isObject: (value: any) => boolean;
|
|
7
|
+
export declare const isDate: (value: any) => boolean;
|
|
8
|
+
export declare const isUrlString: (value: string) => boolean;
|
|
9
|
+
export declare const isOnlyNumbers: (name: string) => boolean;
|
|
10
|
+
export declare const isNumberAllowString: (value: any) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const getValueType = (value) => Object.prototype.toString.call(value).slice(8, -1);
|
|
2
|
+
const onlyNumberReg = new RegExp(/^[0-90-9]+$/);
|
|
3
|
+
const urlPattern = new RegExp('^(https?:\\/\\/)?' +
|
|
4
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
|
|
5
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' +
|
|
6
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
|
|
7
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' +
|
|
8
|
+
'(\\#[-a-z\\d_]*)?$', 'i');
|
|
9
|
+
export const isNumber = (value) => getValueType(value) === 'Number' && !Number.isNaN(value);
|
|
10
|
+
export const isBoolean = (value) => getValueType(value) === 'Boolean';
|
|
11
|
+
export const isString = (value) => getValueType(value) === 'String';
|
|
12
|
+
export const isArray = (value) => getValueType(value) === 'Array';
|
|
13
|
+
export const isObject = (value) => getValueType(value) === 'Object';
|
|
14
|
+
export const isDate = (value) => getValueType(value) === 'Date';
|
|
15
|
+
export const isUrlString = (value) => urlPattern.test(value);
|
|
16
|
+
export const isOnlyNumbers = (name) => onlyNumberReg.test(name);
|
|
17
|
+
export const isNumberAllowString = (value) => {
|
|
18
|
+
if (isNumber(value)) {
|
|
19
|
+
return value - value === 0;
|
|
20
|
+
}
|
|
21
|
+
if (isString(value) && value.trim() !== '') {
|
|
22
|
+
return Number.isFinite ? Number.isFinite(+value) : isFinite(+value);
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { hexdec } from './converters/string.js';
|
|
2
|
+
export const getLuminance = (code) => (hexdec(code.substring(1, 3)) * 0.299 + hexdec(code.substring(3, 5)) * 0.587 + hexdec(code.substring(5, 7)) * 0.114) /
|
|
3
|
+
2.55;
|
|
4
|
+
export const isDarker = (code) => getLuminance(`#${code}`.replace(/^#{2,}/, '#')) < 50;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const digits: (num: number | string, count?: number) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const digits = (num, count = 2) => `${'0'.repeat(count)}${num}`.slice(-count);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const camelCase: (text: string) => string;
|
|
2
|
+
export declare const snakeCase: (text: string) => string;
|
|
3
|
+
export declare const kebabCase: (text: string) => string;
|
|
4
|
+
export declare const pascalCase: (text: string) => string;
|
|
5
|
+
export declare const hexdec: (stringText: string) => number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isArray } from '../../_core/type-check.js';
|
|
2
|
+
isArray([]);
|
|
3
|
+
export const camelCase = (text) => `${text.charAt(0).toLowerCase()}${text.slice(1)}`.replace(/[-_](.)/g, (_, group1) => group1.toUpperCase());
|
|
4
|
+
export const snakeCase = (text) => camelCase(text).replace(/[A-Z]/g, s => `_${s.charAt(0).toLowerCase()}`);
|
|
5
|
+
export const kebabCase = (text) => camelCase(text).replace(/[A-Z]/g, s => `-${s.charAt(0).toLowerCase()}`);
|
|
6
|
+
export const pascalCase = (text) => {
|
|
7
|
+
const camel = camelCase(text);
|
|
8
|
+
return `${camel.charAt(0).toUpperCase()}${camel.slice(1)}`;
|
|
9
|
+
};
|
|
10
|
+
export const hexdec = (stringText) => {
|
|
11
|
+
return parseInt(stringText.replace(/[^a-f0-9]/gi, ''), 16);
|
|
12
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { ensureDirSync, pathExistsSync, removeSync } from 'fs-extra/esm';
|
|
3
|
+
export const cleanDirectory = (prefix, dir) => {
|
|
4
|
+
const path = resolve(prefix, dir);
|
|
5
|
+
if (pathExistsSync(path)) {
|
|
6
|
+
removeSync(path);
|
|
7
|
+
}
|
|
8
|
+
ensureDirSync(path);
|
|
9
|
+
};
|
|
10
|
+
export const cleanDirectories = (prefix, aliases) => {
|
|
11
|
+
for (const alias of aliases) {
|
|
12
|
+
cleanDirectory(prefix, alias);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getAliases: (path: string, excludes: string[]) => string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getFiles } from './get-files.js';
|
|
2
|
+
export const getAliases = (path, excludes) => {
|
|
3
|
+
const regExp = new RegExp(`^${path}/`);
|
|
4
|
+
const excludesExp = new RegExp(excludes.join('|'));
|
|
5
|
+
const aliases = getFiles(path).map(path => path.replace(regExp, '').replace(/\.ts$/, ''));
|
|
6
|
+
if (excludes.length) {
|
|
7
|
+
return aliases.filter(path => !excludesExp.test(path));
|
|
8
|
+
}
|
|
9
|
+
return aliases;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getFiles: (dir: string, _files?: string[]) => string[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { statSync, readdirSync } from 'fs';
|
|
2
|
+
export const getFiles = (dir, _files = []) => {
|
|
3
|
+
const files = readdirSync(dir);
|
|
4
|
+
for (const file of files) {
|
|
5
|
+
const name = dir + '/' + file;
|
|
6
|
+
if (statSync(name).isDirectory()) {
|
|
7
|
+
getFiles(name, _files);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
_files.push(name);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return _files;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const writePackageJson: (prefix: string, author: string, name: string, outputDir: string, aliases: string[], ignoreDirectory?: string) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { writeJsonSync } from 'fs-extra/esm';
|
|
3
|
+
import { cleanDirectory } from './clean-directories.js';
|
|
4
|
+
export const writePackageJson = (prefix, author, name, outputDir, aliases, ignoreDirectory = '') => {
|
|
5
|
+
for (const alias of aliases) {
|
|
6
|
+
const splits = alias.split(/\//g);
|
|
7
|
+
const outputPaths = splits.filter((dir) => dir !== ignoreDirectory);
|
|
8
|
+
const relative = outputPaths
|
|
9
|
+
.map(() => '..')
|
|
10
|
+
.join('/');
|
|
11
|
+
const outputPath = outputPaths.join('/');
|
|
12
|
+
const pkgManifest = {
|
|
13
|
+
name: `${author}/${[name, ...splits].join('-')}`,
|
|
14
|
+
types: `${relative}/${outputDir}/${alias}.d.ts`,
|
|
15
|
+
main: `${relative}/${outputDir}/${alias}.js`,
|
|
16
|
+
sideEffects: false,
|
|
17
|
+
};
|
|
18
|
+
cleanDirectory(prefix, outputPath);
|
|
19
|
+
writeJsonSync(join(prefix, outputPath, 'package.json'), pkgManifest, { spaces: 2 });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_core/type-check.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_core/type-check.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_internal/color.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_internal/color.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../_internal/converters/array.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../_internal/converters/array.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../_internal/converters/number.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../_internal/converters/number.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../_internal/converters/string.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../_internal/converters/string.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../_internal/dev-ops/package-generator/generate-alias.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../_internal/dev-ops/package-generator/generate-alias.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_internal/type-check.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_internal/type-check.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-gadgetry",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-alpha.0",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/cilly-yllic/gadgetry.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/cilly-yllic/gadgetry/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/cilly-yllic/gadgetry#readme",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18.x"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepare": "husky",
|
|
21
|
+
"jest": "jest",
|
|
22
|
+
"lint": "eslint .",
|
|
23
|
+
"_prettier": "prettier .",
|
|
24
|
+
"prettier:write": "npm run _prettier -- --write",
|
|
25
|
+
"prettier": "npm run prettier:write",
|
|
26
|
+
"prettier:check": "npm run _prettier -- --check",
|
|
27
|
+
"clean": "rimraf ./dist ./dev-ops ./type-check",
|
|
28
|
+
"tsc": "tsc -p tsconfig.publish.json && tsc-alias -p tsconfig.publish.json",
|
|
29
|
+
"generate": "tsx --tsconfig ./tsconfig.zx.json ./tools/generate-alias.zx.ts",
|
|
30
|
+
"ci:update-version": "zx ./scripts/ci/update-version.mjs",
|
|
31
|
+
"//--- test ---//": "",
|
|
32
|
+
"test": "run-s test:*",
|
|
33
|
+
"test:lint": "npm run lint",
|
|
34
|
+
"test:prettier": "npm run prettier:check",
|
|
35
|
+
"test:jest": "npm run jest",
|
|
36
|
+
"//--- build ---//": "",
|
|
37
|
+
"build": "run-s build:*",
|
|
38
|
+
"build:test": "npm run test",
|
|
39
|
+
"build:clean": "npm run clean",
|
|
40
|
+
"build:tsc": "npm run tsc",
|
|
41
|
+
"build:generate": "npm run generate"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@actions/core": "^1.10.1",
|
|
45
|
+
"@actions/exec": "^1.1.1",
|
|
46
|
+
"@actions/github": "^6.0.0",
|
|
47
|
+
"zx": "^8.0.2"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@babel/core": "^7.24.4",
|
|
51
|
+
"@babel/preset-env": "^7.24.4",
|
|
52
|
+
"@babel/preset-typescript": "^7.24.1",
|
|
53
|
+
"@eslint/js": "^8.57.0",
|
|
54
|
+
"@types/jest": "^29.5.12",
|
|
55
|
+
"@types/node": "^20.12.7",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
57
|
+
"@typescript-eslint/parser": "^7.7.1",
|
|
58
|
+
"babel-jest": "^29.7.0",
|
|
59
|
+
"eslint": "^8.57.0",
|
|
60
|
+
"eslint-config-prettier": "^9.1.0",
|
|
61
|
+
"eslint-import-resolver-typescript": "^3.6.1",
|
|
62
|
+
"eslint-plugin-import": "^2.29.1",
|
|
63
|
+
"eslint-plugin-jest": "^28.2.0",
|
|
64
|
+
"eslint-plugin-unused-imports": "^3.1.0",
|
|
65
|
+
"fs-extra": "^11.2.0",
|
|
66
|
+
"husky": "^9.0.11",
|
|
67
|
+
"jest": "^29.7.0",
|
|
68
|
+
"lint-staged": "^15.2.2",
|
|
69
|
+
"npm-run-all2": "^6.1.2",
|
|
70
|
+
"prettier": "^3.2.5",
|
|
71
|
+
"ts-jest": "^29.1.2",
|
|
72
|
+
"ts-node": "^10.9.2",
|
|
73
|
+
"tsc-alias": "^1.8.8",
|
|
74
|
+
"tsx": "^4.7.2",
|
|
75
|
+
"typescript": "^5.4.5",
|
|
76
|
+
"typescript-eslint": "^7.7.1"
|
|
77
|
+
},
|
|
78
|
+
"exports": {
|
|
79
|
+
".": "./dist/**/*.js",
|
|
80
|
+
"./dev-ops/package-generator/generate-alias": "./dist/modules/dev-ops/package-generator/generate-alias.js",
|
|
81
|
+
"./type-check": "./dist/modules/type-check.js",
|
|
82
|
+
"./package.json": "./package.json"
|
|
83
|
+
},
|
|
84
|
+
"files": [
|
|
85
|
+
"!**/__tests__",
|
|
86
|
+
"dist",
|
|
87
|
+
"dev-ops",
|
|
88
|
+
"type-check",
|
|
89
|
+
"src",
|
|
90
|
+
"package.json",
|
|
91
|
+
"tsconfig.json"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
export const getValueType = (value: any): string => Object.prototype.toString.call(value).slice(8, -1)
|
|
3
|
+
|
|
4
|
+
const onlyNumberReg = new RegExp(/^[0-90-9]+$/)
|
|
5
|
+
const urlPattern = new RegExp(
|
|
6
|
+
'^(https?:\\/\\/)?' + // protocol
|
|
7
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
|
8
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
9
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
10
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
11
|
+
'(\\#[-a-z\\d_]*)?$',
|
|
12
|
+
'i'
|
|
13
|
+
) // fragment locator
|
|
14
|
+
|
|
15
|
+
// export const isNumber = (value): boolean => getValueType(value) === 'Number'
|
|
16
|
+
export const isNumber = (value: any): boolean => getValueType(value) === 'Number' && !Number.isNaN(value)
|
|
17
|
+
export const isBoolean = (value: any): boolean => getValueType(value) === 'Boolean'
|
|
18
|
+
export const isString = (value: any): boolean => getValueType(value) === 'String'
|
|
19
|
+
export const isArray = (value: any): boolean => getValueType(value) === 'Array'
|
|
20
|
+
// export const isArray = (value: any): boolean => Array.isArray(value)
|
|
21
|
+
export const isObject = (value: any): boolean => getValueType(value) === 'Object'
|
|
22
|
+
export const isDate = (value: any): boolean => getValueType(value) === 'Date'
|
|
23
|
+
export const isUrlString = (value: string): boolean => urlPattern.test(value)
|
|
24
|
+
export const isOnlyNumbers = (name: string) => onlyNumberReg.test(name)
|
|
25
|
+
export const isNumberAllowString = (value: any) => {
|
|
26
|
+
if (isNumber(value)) {
|
|
27
|
+
return value - value === 0
|
|
28
|
+
}
|
|
29
|
+
if (isString(value) && value.trim() !== '') {
|
|
30
|
+
return Number.isFinite ? Number.isFinite(+value) : isFinite(+value)
|
|
31
|
+
}
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
/* eslint-enable */
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { isDarker } from '../color.js'
|
|
2
|
+
|
|
3
|
+
describe('isDarker', () => {
|
|
4
|
+
const DARK_LISTS = [
|
|
5
|
+
'#000000',
|
|
6
|
+
'#696969',
|
|
7
|
+
'#708090',
|
|
8
|
+
'#4682b4',
|
|
9
|
+
'#4169e1',
|
|
10
|
+
'#191970',
|
|
11
|
+
'#000080',
|
|
12
|
+
'#00008b',
|
|
13
|
+
'#0000cd',
|
|
14
|
+
'#0000ff',
|
|
15
|
+
'#1e90ff',
|
|
16
|
+
'#008b8b',
|
|
17
|
+
'#008080',
|
|
18
|
+
'#2f4f4f',
|
|
19
|
+
'#006400',
|
|
20
|
+
'#008000',
|
|
21
|
+
'#228b22',
|
|
22
|
+
'#2e8b57',
|
|
23
|
+
'#556b2f',
|
|
24
|
+
'#6b8e23',
|
|
25
|
+
'#808000',
|
|
26
|
+
'#a0522d',
|
|
27
|
+
'#8b4513',
|
|
28
|
+
'#800000',
|
|
29
|
+
'#8b0000',
|
|
30
|
+
'#a52a2a',
|
|
31
|
+
'#b22222',
|
|
32
|
+
'#cd5c5c',
|
|
33
|
+
'#ff4500',
|
|
34
|
+
'#ff0000',
|
|
35
|
+
'#dc143c',
|
|
36
|
+
'#c71585',
|
|
37
|
+
'#ff1493',
|
|
38
|
+
'#ff00ff',
|
|
39
|
+
'#9932cc',
|
|
40
|
+
'#9400d3',
|
|
41
|
+
'#8b008b',
|
|
42
|
+
'#800080',
|
|
43
|
+
'#4b0082',
|
|
44
|
+
'#483d8b',
|
|
45
|
+
'#8a2be2',
|
|
46
|
+
'#6a5acd',
|
|
47
|
+
'#7b68ee',
|
|
48
|
+
]
|
|
49
|
+
for (const DARK of DARK_LISTS) {
|
|
50
|
+
it(DARK, () => expect(isDarker(DARK)).toBeTruthy())
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('isNotDarker', () => {
|
|
55
|
+
const NOT_DARK_LISTS = [
|
|
56
|
+
'#808080',
|
|
57
|
+
'#a9a9a9',
|
|
58
|
+
'#c0c0c0',
|
|
59
|
+
'#d3d3d3',
|
|
60
|
+
'#dcdcdc',
|
|
61
|
+
'#f5f5f5',
|
|
62
|
+
'#ffffff',
|
|
63
|
+
'#fffafa',
|
|
64
|
+
'#f8f8ff',
|
|
65
|
+
'#fffaf0',
|
|
66
|
+
'#faf0e6',
|
|
67
|
+
'#faebd7',
|
|
68
|
+
'#ffefd5',
|
|
69
|
+
'#ffebcd',
|
|
70
|
+
'#ffe4c4',
|
|
71
|
+
'#ffe4b5',
|
|
72
|
+
'#ffdead',
|
|
73
|
+
'#ffdab9',
|
|
74
|
+
'#ffe4e1',
|
|
75
|
+
'#fff0f5',
|
|
76
|
+
'#fff5ee',
|
|
77
|
+
'#fdf5e6',
|
|
78
|
+
'#fffff0',
|
|
79
|
+
'#f0fff0',
|
|
80
|
+
'#f5fffa',
|
|
81
|
+
'#f0ffff',
|
|
82
|
+
'#f0f8ff',
|
|
83
|
+
'#e6e6fa',
|
|
84
|
+
'#b0c4de',
|
|
85
|
+
'#778899',
|
|
86
|
+
'#6495ed',
|
|
87
|
+
'#00bfff',
|
|
88
|
+
'#87cefa',
|
|
89
|
+
'#87ceeb',
|
|
90
|
+
'#add8e6',
|
|
91
|
+
'#b0e0e6',
|
|
92
|
+
'#afeeee',
|
|
93
|
+
'#e0ffff',
|
|
94
|
+
'#00ffff',
|
|
95
|
+
'#40e0d0',
|
|
96
|
+
'#48d1cc',
|
|
97
|
+
'#00ced1',
|
|
98
|
+
'#20b2aa',
|
|
99
|
+
'#5f9ea0',
|
|
100
|
+
'#3cb371',
|
|
101
|
+
'#66cdaa',
|
|
102
|
+
'#8fbc8f',
|
|
103
|
+
'#7fffd4',
|
|
104
|
+
'#98fb98',
|
|
105
|
+
'#90ee90',
|
|
106
|
+
'#00ff7f',
|
|
107
|
+
'#00fa9a',
|
|
108
|
+
'#7cfc00',
|
|
109
|
+
'#7fff00',
|
|
110
|
+
'#adff2f',
|
|
111
|
+
'#00ff00',
|
|
112
|
+
'#32cd32',
|
|
113
|
+
'#9acd32',
|
|
114
|
+
'#bdb76b',
|
|
115
|
+
'#eee8aa',
|
|
116
|
+
'#fff8dc',
|
|
117
|
+
'#f5f5dc',
|
|
118
|
+
'#ffffe0',
|
|
119
|
+
'#fafad2',
|
|
120
|
+
'#fffacd',
|
|
121
|
+
'#f5deb3',
|
|
122
|
+
'#deb887',
|
|
123
|
+
'#d2b48c',
|
|
124
|
+
'#f0e68c',
|
|
125
|
+
'#ffff00',
|
|
126
|
+
'#ffd700',
|
|
127
|
+
'#ffa500',
|
|
128
|
+
'#f4a460',
|
|
129
|
+
'#ff8c00',
|
|
130
|
+
'#daa520',
|
|
131
|
+
'#cd853f',
|
|
132
|
+
'#b8860b',
|
|
133
|
+
'#d2691e',
|
|
134
|
+
'#bc8f8f',
|
|
135
|
+
'#e9967a',
|
|
136
|
+
'#f08080',
|
|
137
|
+
'#fa8072',
|
|
138
|
+
'#ffa07a',
|
|
139
|
+
'#ff7f50',
|
|
140
|
+
'#ff6347',
|
|
141
|
+
'#ff69b4',
|
|
142
|
+
'#db7093',
|
|
143
|
+
'#ffc0cb',
|
|
144
|
+
'#ffb6c1',
|
|
145
|
+
'#d8bfd8',
|
|
146
|
+
'#ee82ee',
|
|
147
|
+
'#dda0dd',
|
|
148
|
+
'#da70d6',
|
|
149
|
+
'#ba55d3',
|
|
150
|
+
'#9370db',
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
for (const NOT_DARK of NOT_DARK_LISTS) {
|
|
154
|
+
it(NOT_DARK, () => expect(isDarker(NOT_DARK)).toBeFalsy())
|
|
155
|
+
}
|
|
156
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { hexdec } from './converters/string.js'
|
|
2
|
+
|
|
3
|
+
export const getLuminance = (code: string): number =>
|
|
4
|
+
(hexdec(code.substring(1, 3)) * 0.299 + hexdec(code.substring(3, 5)) * 0.587 + hexdec(code.substring(5, 7)) * 0.114) /
|
|
5
|
+
2.55
|
|
6
|
+
|
|
7
|
+
export const isDarker = (code: string): boolean => getLuminance(`#${code}`.replace(/^#{2,}/, '#')) < 50
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getUnique } from '../array.js'
|
|
2
|
+
|
|
3
|
+
describe('getUnique', () => {
|
|
4
|
+
const list = [1, 2, 3, 1, 1, 1, 3, 100, 'foo', 'hoge', 1, 'foo']
|
|
5
|
+
const expects = [1, 2, 3, 100, 'foo', 'hoge']
|
|
6
|
+
it('should be equal', () => {
|
|
7
|
+
expect(JSON.stringify(getUnique(list))).toBe(JSON.stringify(expects))
|
|
8
|
+
})
|
|
9
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const getUnique = <T extends string | number>(list: T[]): T[] => [...new Set(list)]
|
|
2
|
+
export const chunk = <T = unknown>(list: T[], size: number): T[][] =>
|
|
3
|
+
list.reduce(
|
|
4
|
+
(acc: T[][], _: T, i: number, self: T[]) => (i % size ? acc : [...acc, self.slice(i, i + size)]),
|
|
5
|
+
[] as T[][]
|
|
6
|
+
) as T[][]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const digits = (num: number | string, count = 2) => `${'0'.repeat(count)}${num}`.slice(-count)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isArray } from '~core/type-check.js'
|
|
2
|
+
// const validate = (text: string): RegExpMatchArray | null =>
|
|
3
|
+
// text.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
|
4
|
+
|
|
5
|
+
isArray([])
|
|
6
|
+
|
|
7
|
+
export const camelCase = (text: string) =>
|
|
8
|
+
`${text.charAt(0).toLowerCase()}${text.slice(1)}`.replace(/[-_](.)/g, (_, group1) => group1.toUpperCase())
|
|
9
|
+
|
|
10
|
+
export const snakeCase = (text: string) => camelCase(text).replace(/[A-Z]/g, s => `_${s.charAt(0).toLowerCase()}`)
|
|
11
|
+
|
|
12
|
+
export const kebabCase = (text: string): string =>
|
|
13
|
+
camelCase(text).replace(/[A-Z]/g, s => `-${s.charAt(0).toLowerCase()}`)
|
|
14
|
+
|
|
15
|
+
export const pascalCase = (text: string) => {
|
|
16
|
+
const camel = camelCase(text)
|
|
17
|
+
return `${camel.charAt(0).toUpperCase()}${camel.slice(1)}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const hexdec = (stringText: string): number => {
|
|
21
|
+
return parseInt(stringText.replace(/[^a-f0-9]/gi, ''), 16)
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolve } from 'path'
|
|
2
|
+
|
|
3
|
+
import { ensureDirSync, pathExistsSync, removeSync } from 'fs-extra/esm'
|
|
4
|
+
|
|
5
|
+
export const cleanDirectory = (prefix: string, dir: string) => {
|
|
6
|
+
const path = resolve(prefix, dir)
|
|
7
|
+
if (pathExistsSync(path)) {
|
|
8
|
+
removeSync(path)
|
|
9
|
+
}
|
|
10
|
+
ensureDirSync(path)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const cleanDirectories = (prefix: string, aliases: string[]) => {
|
|
14
|
+
for (const alias of aliases) {
|
|
15
|
+
cleanDirectory(prefix, alias)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getFiles } from './get-files.js'
|
|
2
|
+
|
|
3
|
+
export const getAliases = (path: string, excludes: string[]) => {
|
|
4
|
+
const regExp = new RegExp(`^${path}/`)
|
|
5
|
+
const excludesExp = new RegExp(excludes.join('|'))
|
|
6
|
+
const aliases = getFiles(path).map(path => path.replace(regExp, '').replace(/\.ts$/, ''))
|
|
7
|
+
if (excludes.length) {
|
|
8
|
+
return aliases.filter(path => !excludesExp.test(path))
|
|
9
|
+
}
|
|
10
|
+
return aliases
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { statSync, readdirSync } from 'fs'
|
|
2
|
+
|
|
3
|
+
export const getFiles = (dir: string, _files: string[] = []) => {
|
|
4
|
+
const files = readdirSync(dir)
|
|
5
|
+
for (const file of files) {
|
|
6
|
+
const name = dir + '/' + file
|
|
7
|
+
if (statSync(name).isDirectory()) {
|
|
8
|
+
getFiles(name, _files)
|
|
9
|
+
} else {
|
|
10
|
+
_files.push(name)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return _files
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { join } from 'path'
|
|
2
|
+
|
|
3
|
+
import { writeJsonSync } from 'fs-extra/esm'
|
|
4
|
+
|
|
5
|
+
import { cleanDirectory } from './clean-directories.js'
|
|
6
|
+
|
|
7
|
+
export const writePackageJson = (prefix: string, author: string, name: string, outputDir: string, aliases: string[], ignoreDirectory = '') => {
|
|
8
|
+
for (const alias of aliases) {
|
|
9
|
+
const splits = alias.split(/\//g)
|
|
10
|
+
const outputPaths = splits.filter((dir) => dir !== ignoreDirectory)
|
|
11
|
+
const relative = outputPaths
|
|
12
|
+
.map(() => '..')
|
|
13
|
+
.join('/')
|
|
14
|
+
const outputPath = outputPaths.join('/')
|
|
15
|
+
const pkgManifest = {
|
|
16
|
+
name: `${author}/${[name, ...splits].join('-')}`,
|
|
17
|
+
types: `${relative}/${outputDir}/${alias}.d.ts`,
|
|
18
|
+
main: `${relative}/${outputDir}/${alias}.js`,
|
|
19
|
+
sideEffects: false,
|
|
20
|
+
}
|
|
21
|
+
cleanDirectory(prefix, outputPath)
|
|
22
|
+
writeJsonSync(join(prefix, outputPath, 'package.json'), pkgManifest, { spaces: 2 })
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~core/type-check.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~internal/color.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~internal/converters/array.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~internal/converters/number.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~internal/converters/string.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~internal/dev-ops/package-generator/generate-alias.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~internal/type-check.js'
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esNext",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"types": ["jest", "node"],
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"checkJs": false,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"outDir": "dist",
|
|
12
|
+
"rootDir": "./src",
|
|
13
|
+
"removeComments": true,
|
|
14
|
+
"allowSyntheticDefaultImports": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"sourceMap": true,
|
|
17
|
+
"typeRoots": ["node_modules/@types", "src/types"],
|
|
18
|
+
"baseUrl": "./",
|
|
19
|
+
"paths": {
|
|
20
|
+
"~internal/*": ["./src/_internal/*"],
|
|
21
|
+
"~core/*": ["./src/_core/*"]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"include": ["src/**/*"],
|
|
25
|
+
"exclude": ["src/**/*.spec.ts"]
|
|
26
|
+
}
|