@kamen/create-webapp 1.0.14 → 1.0.16
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/README.md +16 -1
- package/index.js +65 -13
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
# @kamen/create-weapp <a href="https://npmjs.com/package/@kamen/create-webapp"><img src="https://img.shields.io/npm/v/@kamen/create-webapp" alt="npm package"></a>
|
|
2
2
|
|
|
3
|
-
## Scaffolding
|
|
3
|
+
## Project Scaffolding
|
|
4
4
|
|
|
5
5
|
With NPM:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
$ npm init @kamen/webapp
|
|
9
9
|
```
|
|
10
|
+
|
|
11
|
+
## Utility Functions
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import {randomFromRange, randomFromList} from "@kamen/create-webapp";
|
|
15
|
+
|
|
16
|
+
const colors = ['red', 'green', 'blue'];
|
|
17
|
+
const data = {
|
|
18
|
+
color: randomFromList(colors),
|
|
19
|
+
length: randomFromRange(0, 99);
|
|
20
|
+
state: Boolean(randomFromRange(0, 1))
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
console.dir(data);
|
|
24
|
+
```
|
package/index.js
CHANGED
|
@@ -1,13 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
1
|
+
const primitiveTypeRe = /^string|number|bigint|boolean|symbol$/;
|
|
2
|
+
const objectTypeRe = /^object|function$/;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {*} value
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
*/
|
|
8
|
+
export function isPrimitive(value) {
|
|
9
|
+
return primitiveTypeRe.test(typeof value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {*} value
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
export function isObject(value) {
|
|
17
|
+
return value !== null && objectTypeRe.test(typeof value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {number} offset
|
|
22
|
+
* @param {number} length
|
|
23
|
+
* @return {number}
|
|
24
|
+
*/
|
|
25
|
+
export function modulo(offset, length) {
|
|
26
|
+
return ((offset % length) + length) % length;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {number} [min=0]
|
|
31
|
+
* @param {number} [max=255]
|
|
32
|
+
* @param {number} [step=1]
|
|
33
|
+
* @return {number[]}
|
|
34
|
+
*/
|
|
35
|
+
export function range(min = 0, max = 255, step = 1) {
|
|
36
|
+
return Array.from({length: (max - min) / step + 1}, (_, index) => index * step + min);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {number} value
|
|
41
|
+
* @param {number} [min=0]
|
|
42
|
+
* @param {number} [max=255]
|
|
43
|
+
* @return {number}
|
|
44
|
+
*/
|
|
45
|
+
export function clamp(value, min = 0, max = 255) {
|
|
46
|
+
return Math.min(Math.max(value, min), max);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {number} [min=0]
|
|
51
|
+
* @param {number} [max=255]
|
|
52
|
+
* @return {number}
|
|
53
|
+
*/
|
|
54
|
+
export function randomFromRange(min = 0, max = 255) {
|
|
55
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @template T
|
|
60
|
+
* @param {T[]} [list=[]]
|
|
61
|
+
* @returns {T}
|
|
62
|
+
*/
|
|
63
|
+
export function randomFromList(list = []) {
|
|
64
|
+
return list[randomFromRange(0, list.length - 1)];
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamen/create-webapp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "npm init @kamen/webapp",
|
|
5
5
|
"homepage": "https://www.npmjs.com/package/@kamen/create-webapp",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "GPL-2.0-only",
|
|
7
7
|
"private": false,
|
|
8
|
-
"keywords": ["web"],
|
|
8
|
+
"keywords": ["init", "utlity", "web"],
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "index.js",
|
|
11
11
|
"bin": {
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"url": "git+https://github.com/L1feF0rm/special-octo-barnacle.git"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
27
|
-
"npm": ">=
|
|
26
|
+
"node": ">=20",
|
|
27
|
+
"npm": ">=10"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|