my-gadgetry 1.0.0-alpha.0 → 1.0.8
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/color/package.json +6 -0
- package/converters/array/package.json +6 -0
- package/converters/number/package.json +6 -0
- package/converters/string/package.json +6 -0
- package/dist/_core/type-check.d.ts +3 -3
- package/dist/_core/type-check.js +19 -4
- package/dist/_internal/dev-ops/package-generator/generate-alias/write-package-json.js +2 -4
- package/package.json +27 -15
- package/src/_core/type-check.ts +19 -4
- package/src/_internal/dev-ops/package-generator/generate-alias/write-package-json.ts +10 -5
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare const getValueType: (value: any) => string;
|
|
2
|
-
export declare const isNumber: (value: any) => boolean;
|
|
3
2
|
export declare const isBoolean: (value: any) => boolean;
|
|
4
3
|
export declare const isString: (value: any) => boolean;
|
|
5
4
|
export declare const isArray: (value: any) => boolean;
|
|
6
5
|
export declare const isObject: (value: any) => boolean;
|
|
7
6
|
export declare const isDate: (value: any) => boolean;
|
|
8
7
|
export declare const isUrlString: (value: string) => boolean;
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
8
|
+
export declare const isStringNumbers: (name: string) => boolean;
|
|
9
|
+
export declare const isNumber: (value: any, allowString?: boolean) => boolean;
|
|
10
|
+
export declare const isJson: (str: string) => boolean;
|
package/dist/_core/type-check.js
CHANGED
|
@@ -6,20 +6,35 @@ const urlPattern = new RegExp('^(https?:\\/\\/)?' +
|
|
|
6
6
|
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
|
|
7
7
|
'(\\?[;&a-z\\d%_.~+=-]*)?' +
|
|
8
8
|
'(\\#[-a-z\\d_]*)?$', 'i');
|
|
9
|
-
|
|
9
|
+
const _isNumber = (value) => getValueType(value) === 'Number' && !Number.isNaN(value);
|
|
10
10
|
export const isBoolean = (value) => getValueType(value) === 'Boolean';
|
|
11
11
|
export const isString = (value) => getValueType(value) === 'String';
|
|
12
12
|
export const isArray = (value) => getValueType(value) === 'Array';
|
|
13
13
|
export const isObject = (value) => getValueType(value) === 'Object';
|
|
14
14
|
export const isDate = (value) => getValueType(value) === 'Date';
|
|
15
15
|
export const isUrlString = (value) => urlPattern.test(value);
|
|
16
|
-
export const
|
|
17
|
-
export const
|
|
18
|
-
if (
|
|
16
|
+
export const isStringNumbers = (name) => onlyNumberReg.test(name);
|
|
17
|
+
export const isNumber = (value, allowString = false) => {
|
|
18
|
+
if (_isNumber(value)) {
|
|
19
19
|
return value - value === 0;
|
|
20
20
|
}
|
|
21
|
+
if (!allowString) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
21
24
|
if (isString(value) && value.trim() !== '') {
|
|
22
25
|
return Number.isFinite ? Number.isFinite(+value) : isFinite(+value);
|
|
23
26
|
}
|
|
24
27
|
return false;
|
|
25
28
|
};
|
|
29
|
+
export const isJson = (str) => {
|
|
30
|
+
if (!isString(str)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const result = JSON.parse(str);
|
|
35
|
+
return isString(result) || isObject(result);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -4,10 +4,8 @@ import { cleanDirectory } from './clean-directories.js';
|
|
|
4
4
|
export const writePackageJson = (prefix, author, name, outputDir, aliases, ignoreDirectory = '') => {
|
|
5
5
|
for (const alias of aliases) {
|
|
6
6
|
const splits = alias.split(/\//g);
|
|
7
|
-
const outputPaths = splits.filter(
|
|
8
|
-
const relative = outputPaths
|
|
9
|
-
.map(() => '..')
|
|
10
|
-
.join('/');
|
|
7
|
+
const outputPaths = splits.filter(dir => dir !== ignoreDirectory);
|
|
8
|
+
const relative = outputPaths.map(() => '..').join('/');
|
|
11
9
|
const outputPath = outputPaths.join('/');
|
|
12
10
|
const pkgManifest = {
|
|
13
11
|
name: `${author}/${[name, ...splits].join('-')}`,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-gadgetry",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"repository": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"prepare": "husky",
|
|
21
21
|
"jest": "jest",
|
|
22
22
|
"lint": "eslint .",
|
|
23
|
+
"lint:fix": "npm run lint -- --fix",
|
|
23
24
|
"_prettier": "prettier .",
|
|
24
25
|
"prettier:write": "npm run _prettier -- --write",
|
|
25
26
|
"prettier": "npm run prettier:write",
|
|
@@ -27,42 +28,47 @@
|
|
|
27
28
|
"clean": "rimraf ./dist ./dev-ops ./type-check",
|
|
28
29
|
"tsc": "tsc -p tsconfig.publish.json && tsc-alias -p tsconfig.publish.json",
|
|
29
30
|
"generate": "tsx --tsconfig ./tsconfig.zx.json ./tools/generate-alias.zx.ts",
|
|
30
|
-
"ci:update-version": "zx ./
|
|
31
|
+
"ci:update-version": "tsx --tsconfig ./tsconfig.zx.json ./tools/update-version.zx.ts",
|
|
32
|
+
|
|
31
33
|
"//--- test ---//": "",
|
|
32
34
|
"test": "run-s test:*",
|
|
33
35
|
"test:lint": "npm run lint",
|
|
34
36
|
"test:prettier": "npm run prettier:check",
|
|
35
37
|
"test:jest": "npm run jest",
|
|
38
|
+
|
|
36
39
|
"//--- build ---//": "",
|
|
37
40
|
"build": "run-s build:*",
|
|
38
41
|
"build:test": "npm run test",
|
|
39
42
|
"build:clean": "npm run clean",
|
|
40
43
|
"build:tsc": "npm run tsc",
|
|
41
|
-
"build:generate": "npm run generate"
|
|
44
|
+
"build:generate": "npm run generate",
|
|
45
|
+
|
|
46
|
+
"//--- publish ---//": "",
|
|
47
|
+
"publish:build": "run-s build:{clean,tsc,generate}"
|
|
42
48
|
},
|
|
43
49
|
"dependencies": {
|
|
44
50
|
"@actions/core": "^1.10.1",
|
|
45
51
|
"@actions/exec": "^1.1.1",
|
|
46
52
|
"@actions/github": "^6.0.0",
|
|
47
|
-
"
|
|
53
|
+
"fs-extra": "^11.2.0",
|
|
54
|
+
"zx": "^8.1.0"
|
|
48
55
|
},
|
|
49
56
|
"devDependencies": {
|
|
50
|
-
"@babel/core": "^7.24.
|
|
51
|
-
"@babel/preset-env": "^7.24.
|
|
57
|
+
"@babel/core": "^7.24.5",
|
|
58
|
+
"@babel/preset-env": "^7.24.5",
|
|
52
59
|
"@babel/preset-typescript": "^7.24.1",
|
|
53
60
|
"@eslint/js": "^8.57.0",
|
|
54
61
|
"@types/jest": "^29.5.12",
|
|
55
|
-
"@types/node": "^20.12.
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
57
|
-
"@typescript-eslint/parser": "^7.
|
|
62
|
+
"@types/node": "^20.12.11",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
|
64
|
+
"@typescript-eslint/parser": "^7.9.0",
|
|
58
65
|
"babel-jest": "^29.7.0",
|
|
59
66
|
"eslint": "^8.57.0",
|
|
60
67
|
"eslint-config-prettier": "^9.1.0",
|
|
61
68
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
62
69
|
"eslint-plugin-import": "^2.29.1",
|
|
63
|
-
"eslint-plugin-jest": "^28.
|
|
64
|
-
"eslint-plugin-unused-imports": "^3.
|
|
65
|
-
"fs-extra": "^11.2.0",
|
|
70
|
+
"eslint-plugin-jest": "^28.5.0",
|
|
71
|
+
"eslint-plugin-unused-imports": "^3.2.0",
|
|
66
72
|
"husky": "^9.0.11",
|
|
67
73
|
"jest": "^29.7.0",
|
|
68
74
|
"lint-staged": "^15.2.2",
|
|
@@ -70,13 +76,17 @@
|
|
|
70
76
|
"prettier": "^3.2.5",
|
|
71
77
|
"ts-jest": "^29.1.2",
|
|
72
78
|
"ts-node": "^10.9.2",
|
|
73
|
-
"tsc-alias": "^1.8.
|
|
74
|
-
"tsx": "^4.
|
|
79
|
+
"tsc-alias": "^1.8.10",
|
|
80
|
+
"tsx": "^4.10.2",
|
|
75
81
|
"typescript": "^5.4.5",
|
|
76
|
-
"typescript-eslint": "^7.
|
|
82
|
+
"typescript-eslint": "^7.9.0"
|
|
77
83
|
},
|
|
78
84
|
"exports": {
|
|
79
85
|
".": "./dist/**/*.js",
|
|
86
|
+
"./color": "./dist/modules/color.js",
|
|
87
|
+
"./converters/array": "./dist/modules/converters/array.js",
|
|
88
|
+
"./converters/number": "./dist/modules/converters/number.js",
|
|
89
|
+
"./converters/string": "./dist/modules/converters/string.js",
|
|
80
90
|
"./dev-ops/package-generator/generate-alias": "./dist/modules/dev-ops/package-generator/generate-alias.js",
|
|
81
91
|
"./type-check": "./dist/modules/type-check.js",
|
|
82
92
|
"./package.json": "./package.json"
|
|
@@ -84,6 +94,8 @@
|
|
|
84
94
|
"files": [
|
|
85
95
|
"!**/__tests__",
|
|
86
96
|
"dist",
|
|
97
|
+
"color",
|
|
98
|
+
"converters",
|
|
87
99
|
"dev-ops",
|
|
88
100
|
"type-check",
|
|
89
101
|
"src",
|
package/src/_core/type-check.ts
CHANGED
|
@@ -13,7 +13,7 @@ const urlPattern = new RegExp(
|
|
|
13
13
|
) // fragment locator
|
|
14
14
|
|
|
15
15
|
// export const isNumber = (value): boolean => getValueType(value) === 'Number'
|
|
16
|
-
|
|
16
|
+
const _isNumber = (value: any): boolean => getValueType(value) === 'Number' && !Number.isNaN(value)
|
|
17
17
|
export const isBoolean = (value: any): boolean => getValueType(value) === 'Boolean'
|
|
18
18
|
export const isString = (value: any): boolean => getValueType(value) === 'String'
|
|
19
19
|
export const isArray = (value: any): boolean => getValueType(value) === 'Array'
|
|
@@ -21,14 +21,29 @@ export const isArray = (value: any): boolean => getValueType(value) === 'Array'
|
|
|
21
21
|
export const isObject = (value: any): boolean => getValueType(value) === 'Object'
|
|
22
22
|
export const isDate = (value: any): boolean => getValueType(value) === 'Date'
|
|
23
23
|
export const isUrlString = (value: string): boolean => urlPattern.test(value)
|
|
24
|
-
export const
|
|
25
|
-
export const
|
|
26
|
-
if (
|
|
24
|
+
export const isStringNumbers = (name: string) => onlyNumberReg.test(name)
|
|
25
|
+
export const isNumber = (value: any, allowString = false) => {
|
|
26
|
+
if (_isNumber(value)) {
|
|
27
27
|
return value - value === 0
|
|
28
28
|
}
|
|
29
|
+
if (!allowString) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
29
32
|
if (isString(value) && value.trim() !== '') {
|
|
30
33
|
return Number.isFinite ? Number.isFinite(+value) : isFinite(+value)
|
|
31
34
|
}
|
|
32
35
|
return false
|
|
33
36
|
}
|
|
37
|
+
|
|
38
|
+
export const isJson = (str: string): boolean => {
|
|
39
|
+
if (!isString(str)) {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const result = JSON.parse(str)
|
|
44
|
+
return isString(result) || isObject(result)
|
|
45
|
+
} catch (err) {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
34
49
|
/* eslint-enable */
|
|
@@ -4,13 +4,18 @@ import { writeJsonSync } from 'fs-extra/esm'
|
|
|
4
4
|
|
|
5
5
|
import { cleanDirectory } from './clean-directories.js'
|
|
6
6
|
|
|
7
|
-
export const writePackageJson = (
|
|
7
|
+
export const writePackageJson = (
|
|
8
|
+
prefix: string,
|
|
9
|
+
author: string,
|
|
10
|
+
name: string,
|
|
11
|
+
outputDir: string,
|
|
12
|
+
aliases: string[],
|
|
13
|
+
ignoreDirectory = ''
|
|
14
|
+
) => {
|
|
8
15
|
for (const alias of aliases) {
|
|
9
16
|
const splits = alias.split(/\//g)
|
|
10
|
-
const outputPaths = splits.filter(
|
|
11
|
-
const relative = outputPaths
|
|
12
|
-
.map(() => '..')
|
|
13
|
-
.join('/')
|
|
17
|
+
const outputPaths = splits.filter(dir => dir !== ignoreDirectory)
|
|
18
|
+
const relative = outputPaths.map(() => '..').join('/')
|
|
14
19
|
const outputPath = outputPaths.join('/')
|
|
15
20
|
const pkgManifest = {
|
|
16
21
|
name: `${author}/${[name, ...splits].join('-')}`,
|