@kamen/create-webapp 1.0.49 → 1.0.51
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/helpers/list.js +34 -0
- package/helpers/random.js +79 -0
- package/helpers/temporal.js +55 -0
- package/index.js +6 -115
- package/package.json +5 -2
- package/scripts/index.js +2 -4
- package/temporal.js +0 -55
package/helpers/list.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {number} offset
|
|
3
|
+
* @param {number} length
|
|
4
|
+
* @returns {number}
|
|
5
|
+
*/
|
|
6
|
+
export function modulo(offset, length) {
|
|
7
|
+
return ((offset % length) + length) % length;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {number} [min=0]
|
|
12
|
+
* @param {number} [max=255]
|
|
13
|
+
* @param {number} [step=1]
|
|
14
|
+
* @returns {number[]}
|
|
15
|
+
*/
|
|
16
|
+
export function range(min = 0, max = 255, step = 1) {
|
|
17
|
+
return Array.from({length: (max - min) / step + 1}, (_, index) => index * step + min);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {number} value
|
|
22
|
+
* @param {number} [min=0]
|
|
23
|
+
* @param {number} [max=255]
|
|
24
|
+
* @returns {number}
|
|
25
|
+
*/
|
|
26
|
+
export function clamp(value, min = 0, max = 255) {
|
|
27
|
+
return Math.min(Math.max(value, min), max);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
modulo,
|
|
32
|
+
range,
|
|
33
|
+
clamp
|
|
34
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @returns {string}
|
|
3
|
+
*/
|
|
4
|
+
export function randomSlug() {
|
|
5
|
+
return Math.random().toString(36).slice(2);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {number} [min=0]
|
|
10
|
+
* @param {number} [max=255]
|
|
11
|
+
* @returns {number}
|
|
12
|
+
*/
|
|
13
|
+
export function randomFromRange(min = 0, max = 255) {
|
|
14
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @template T
|
|
19
|
+
* @param {T[]} [list=[]]
|
|
20
|
+
* @returns {T}
|
|
21
|
+
*/
|
|
22
|
+
export function randomFromList(list = []) {
|
|
23
|
+
return list[randomFromRange(0, list.length - 1)];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {number} [saturation=80]
|
|
28
|
+
* @param {number} [lightness=80]
|
|
29
|
+
* @param {number} [alpha=1]
|
|
30
|
+
* @returns {string}
|
|
31
|
+
*/
|
|
32
|
+
export function randomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
|
|
33
|
+
const hue = randomFromRange(0, 359);
|
|
34
|
+
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {number} [min=0]
|
|
39
|
+
* @param {number} [max=255]
|
|
40
|
+
* @returns {Function<number>}
|
|
41
|
+
*/
|
|
42
|
+
export function createRandomFromRange(min = 0, max = 255) {
|
|
43
|
+
return function () {
|
|
44
|
+
return randomFromRange(min, max);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @template T
|
|
50
|
+
* @param {T[]} [list=[]]
|
|
51
|
+
* @returns {Function<T>}
|
|
52
|
+
*/
|
|
53
|
+
export function createRandomFromList(list = []) {
|
|
54
|
+
return function () {
|
|
55
|
+
return randomFromList(list);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {number} [saturation=80]
|
|
61
|
+
* @param {number} [lightness=80]
|
|
62
|
+
* @param {number} [alpha=1]
|
|
63
|
+
* @returns {Function<string>}
|
|
64
|
+
*/
|
|
65
|
+
export function createRandomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
|
|
66
|
+
return function () {
|
|
67
|
+
return randomColorFromSaturationLightnessAlpha(saturation, lightness, alpha);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default {
|
|
72
|
+
randomSlug,
|
|
73
|
+
randomFromRange,
|
|
74
|
+
randomFromList,
|
|
75
|
+
randomColorFromSaturationLightnessAlpha,
|
|
76
|
+
createRandomFromRange,
|
|
77
|
+
createRandomFromList,
|
|
78
|
+
createRandomColorFromSaturationLightnessAlpha
|
|
79
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export const WEEKS_PER_YEAR = 52;
|
|
2
|
+
|
|
3
|
+
export const DAYS_PER_WEEK = 7;
|
|
4
|
+
export const DAYS_PER_YEAR = DAYS_PER_WEEK * WEEKS_PER_YEAR;
|
|
5
|
+
|
|
6
|
+
export const HOURS_PER_DAY = 24;
|
|
7
|
+
export const HOURS_PER_WEEK = HOURS_PER_DAY * DAYS_PER_WEEK;
|
|
8
|
+
export const HOURS_PER_YEAR = HOURS_PER_WEEK * WEEKS_PER_YEAR;
|
|
9
|
+
|
|
10
|
+
export const MINUTES_PER_HOUR = 60;
|
|
11
|
+
export const MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY;
|
|
12
|
+
export const MINUTES_PER_WEEK = MINUTES_PER_DAY * DAYS_PER_WEEK;
|
|
13
|
+
export const MINUTES_PER_YEAR = MINUTES_PER_WEEK * WEEKS_PER_YEAR;
|
|
14
|
+
|
|
15
|
+
export const SECONDS_PER_MINUTE = 60;
|
|
16
|
+
export const SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR;
|
|
17
|
+
export const SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
|
|
18
|
+
export const SECONDS_PER_WEEK = SECONDS_PER_DAY * DAYS_PER_WEEK;
|
|
19
|
+
export const SECONDS_PER_YEAR = SECONDS_PER_WEEK * WEEKS_PER_YEAR;
|
|
20
|
+
|
|
21
|
+
export const MILLISECONDS_PER_SECOND = 1000;
|
|
22
|
+
export const MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE;
|
|
23
|
+
export const MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * MINUTES_PER_HOUR;
|
|
24
|
+
export const MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * HOURS_PER_DAY;
|
|
25
|
+
export const MILLISECONDS_PER_WEEK = MILLISECONDS_PER_DAY * DAYS_PER_WEEK;
|
|
26
|
+
export const MILLISECONDS_PER_YEAR = MILLISECONDS_PER_WEEK * WEEKS_PER_YEAR;
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
WEEKS_PER_YEAR,
|
|
30
|
+
|
|
31
|
+
DAYS_PER_WEEK,
|
|
32
|
+
DAYS_PER_YEAR,
|
|
33
|
+
|
|
34
|
+
HOURS_PER_DAY,
|
|
35
|
+
HOURS_PER_WEEK,
|
|
36
|
+
HOURS_PER_YEAR,
|
|
37
|
+
|
|
38
|
+
MINUTES_PER_HOUR,
|
|
39
|
+
MINUTES_PER_DAY,
|
|
40
|
+
MINUTES_PER_WEEK,
|
|
41
|
+
MINUTES_PER_YEAR,
|
|
42
|
+
|
|
43
|
+
SECONDS_PER_MINUTE,
|
|
44
|
+
SECONDS_PER_HOUR,
|
|
45
|
+
SECONDS_PER_DAY,
|
|
46
|
+
SECONDS_PER_WEEK,
|
|
47
|
+
SECONDS_PER_YEAR,
|
|
48
|
+
|
|
49
|
+
MILLISECONDS_PER_SECOND,
|
|
50
|
+
MILLISECONDS_PER_MINUTE,
|
|
51
|
+
MILLISECONDS_PER_HOUR,
|
|
52
|
+
MILLISECONDS_PER_DAY,
|
|
53
|
+
MILLISECONDS_PER_WEEK,
|
|
54
|
+
MILLISECONDS_PER_YEAR
|
|
55
|
+
};
|
package/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
const primitiveTypeRe = /^string|number|bigint|boolean|symbol$/;
|
|
2
2
|
const objectTypeRe = /^object|function$/;
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import {modulo} from './helpers/list';
|
|
5
|
+
|
|
6
|
+
export {default as list} from './helpers/list';
|
|
7
|
+
export {default as random} from './helpers/random';
|
|
8
|
+
export {default as temporal} from './helpers/temporal';
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* @param {*} value
|
|
@@ -18,105 +23,6 @@ export function isObject(value) {
|
|
|
18
23
|
return value !== null && objectTypeRe.test(typeof value);
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
/**
|
|
22
|
-
* @param {number} offset
|
|
23
|
-
* @param {number} length
|
|
24
|
-
* @returns {number}
|
|
25
|
-
*/
|
|
26
|
-
export function modulo(offset, length) {
|
|
27
|
-
return ((offset % length) + length) % length;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @param {number} [min=0]
|
|
32
|
-
* @param {number} [max=255]
|
|
33
|
-
* @param {number} [step=1]
|
|
34
|
-
* @returns {number[]}
|
|
35
|
-
*/
|
|
36
|
-
export function range(min = 0, max = 255, step = 1) {
|
|
37
|
-
return Array.from({length: (max - min) / step + 1}, (_, index) => index * step + min);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @param {number} value
|
|
42
|
-
* @param {number} [min=0]
|
|
43
|
-
* @param {number} [max=255]
|
|
44
|
-
* @returns {number}
|
|
45
|
-
*/
|
|
46
|
-
export function clamp(value, min = 0, max = 255) {
|
|
47
|
-
return Math.min(Math.max(value, min), max);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @returns {string}
|
|
52
|
-
*/
|
|
53
|
-
export function randomSlug() {
|
|
54
|
-
return Math.random().toString(36).slice(2);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param {number} [min=0]
|
|
59
|
-
* @param {number} [max=255]
|
|
60
|
-
* @returns {number}
|
|
61
|
-
*/
|
|
62
|
-
export function randomFromRange(min = 0, max = 255) {
|
|
63
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @template T
|
|
68
|
-
* @param {T[]} [list=[]]
|
|
69
|
-
* @returns {T}
|
|
70
|
-
*/
|
|
71
|
-
export function randomFromList(list = []) {
|
|
72
|
-
return list[randomFromRange(0, list.length - 1)];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @param {number} [saturation=80]
|
|
77
|
-
* @param {number} [lightness=80]
|
|
78
|
-
* @param {number} [alpha=1]
|
|
79
|
-
* @returns {string}
|
|
80
|
-
*/
|
|
81
|
-
export function randomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
|
|
82
|
-
const hue = randomFromRange(0, 359);
|
|
83
|
-
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @param {number} [min=0]
|
|
88
|
-
* @param {number} [max=255]
|
|
89
|
-
* @returns {Function<number>}
|
|
90
|
-
*/
|
|
91
|
-
export function createRandomFromRange(min = 0, max = 255) {
|
|
92
|
-
return function () {
|
|
93
|
-
return randomFromRange(min, max);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @template T
|
|
99
|
-
* @param {T[]} [list=[]]
|
|
100
|
-
* @returns {Function<T>}
|
|
101
|
-
*/
|
|
102
|
-
export function createRandomFromList(list = []) {
|
|
103
|
-
return function () {
|
|
104
|
-
return randomFromList(list);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @param {number} [saturation=80]
|
|
110
|
-
* @param {number} [lightness=80]
|
|
111
|
-
* @param {number} [alpha=1]
|
|
112
|
-
* @returns {Function<string>}
|
|
113
|
-
*/
|
|
114
|
-
export function createRandomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
|
|
115
|
-
return function () {
|
|
116
|
-
return randomColorFromSaturationLightnessAlpha(saturation, lightness, alpha);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
26
|
/**
|
|
121
27
|
* @param {string} [text='']
|
|
122
28
|
* @param {number} [saturation=80]
|
|
@@ -377,18 +283,3 @@ export const introspection = {
|
|
|
377
283
|
isPrimitive,
|
|
378
284
|
isObject
|
|
379
285
|
};
|
|
380
|
-
|
|
381
|
-
export const numbering = {
|
|
382
|
-
modulo,
|
|
383
|
-
range,
|
|
384
|
-
clamp
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
export const randomness = {
|
|
388
|
-
randomFromRange,
|
|
389
|
-
createRandomFromRange,
|
|
390
|
-
randomFromList,
|
|
391
|
-
createRandomFromList,
|
|
392
|
-
randomColorFromSaturationLightnessAlpha,
|
|
393
|
-
createRandomColorFromSaturationLightnessAlpha
|
|
394
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamen/create-webapp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.51",
|
|
4
4
|
"description": "npm init @kamen/webapp",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"init",
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
"create-webapp": "scripts/index.js"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
|
-
".": "./index.js"
|
|
19
|
+
".": "./index.js",
|
|
20
|
+
"./helpers/list": "./helpers/list.js",
|
|
21
|
+
"./helpers/random": "./helpers/random.js",
|
|
22
|
+
"./helpers/temporal": "./helpers/temporal.js"
|
|
20
23
|
},
|
|
21
24
|
"author": {
|
|
22
25
|
"name": "Kamen Balabanov",
|
package/scripts/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import {cwd, versions} from 'node:process';
|
|
4
|
-
|
|
5
|
-
import {modulo} from '@kamen/create-webapp';
|
|
4
|
+
import {modulo} from '@kamen/create-webapp/helpers/list';
|
|
6
5
|
|
|
7
6
|
console.log(modulo(-10, 4));
|
|
8
|
-
|
|
9
7
|
console.log('versions', versions);
|
|
10
8
|
console.log('cwd()', cwd());
|
|
11
9
|
|
|
12
|
-
process.exit(0);
|
|
10
|
+
process.exit(0);
|
package/temporal.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const WEEKS_PER_YEAR = 52;
|
|
2
|
-
|
|
3
|
-
const DAYS_PER_WEEK = 7;
|
|
4
|
-
const DAYS_PER_YEAR = DAYS_PER_WEEK * WEEKS_PER_YEAR;
|
|
5
|
-
|
|
6
|
-
const HOURS_PER_DAY = 24;
|
|
7
|
-
const HOURS_PER_WEEK = HOURS_PER_DAY * DAYS_PER_WEEK;
|
|
8
|
-
const HOURS_PER_YEAR = HOURS_PER_WEEK * WEEKS_PER_YEAR;
|
|
9
|
-
|
|
10
|
-
const MINUTES_PER_HOUR = 60;
|
|
11
|
-
const MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY;
|
|
12
|
-
const MINUTES_PER_WEEK = MINUTES_PER_DAY * DAYS_PER_WEEK;
|
|
13
|
-
const MINUTES_PER_YEAR = MINUTES_PER_WEEK * WEEKS_PER_YEAR;
|
|
14
|
-
|
|
15
|
-
const SECONDS_PER_MINUTE = 60;
|
|
16
|
-
const SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR;
|
|
17
|
-
const SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
|
|
18
|
-
const SECONDS_PER_WEEK = SECONDS_PER_DAY * DAYS_PER_WEEK;
|
|
19
|
-
const SECONDS_PER_YEAR = SECONDS_PER_WEEK * WEEKS_PER_YEAR;
|
|
20
|
-
|
|
21
|
-
const MILLISECONDS_PER_SECOND = 1000;
|
|
22
|
-
const MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE;
|
|
23
|
-
const MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * MINUTES_PER_HOUR;
|
|
24
|
-
const MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * HOURS_PER_DAY;
|
|
25
|
-
const MILLISECONDS_PER_WEEK = MILLISECONDS_PER_DAY * DAYS_PER_WEEK;
|
|
26
|
-
const MILLISECONDS_PER_YEAR = MILLISECONDS_PER_WEEK * WEEKS_PER_YEAR;
|
|
27
|
-
|
|
28
|
-
export default {
|
|
29
|
-
WEEKS_PER_YEAR,
|
|
30
|
-
|
|
31
|
-
DAYS_PER_WEEK,
|
|
32
|
-
DAYS_PER_YEAR,
|
|
33
|
-
|
|
34
|
-
HOURS_PER_DAY,
|
|
35
|
-
HOURS_PER_WEEK,
|
|
36
|
-
HOURS_PER_YEAR,
|
|
37
|
-
|
|
38
|
-
MINUTES_PER_HOUR,
|
|
39
|
-
MINUTES_PER_DAY,
|
|
40
|
-
MINUTES_PER_WEEK,
|
|
41
|
-
MINUTES_PER_YEAR,
|
|
42
|
-
|
|
43
|
-
SECONDS_PER_MINUTE,
|
|
44
|
-
SECONDS_PER_HOUR,
|
|
45
|
-
SECONDS_PER_DAY,
|
|
46
|
-
SECONDS_PER_WEEK,
|
|
47
|
-
SECONDS_PER_YEAR,
|
|
48
|
-
|
|
49
|
-
MILLISECONDS_PER_SECOND,
|
|
50
|
-
MILLISECONDS_PER_MINUTE,
|
|
51
|
-
MILLISECONDS_PER_HOUR,
|
|
52
|
-
MILLISECONDS_PER_DAY,
|
|
53
|
-
MILLISECONDS_PER_WEEK,
|
|
54
|
-
MILLISECONDS_PER_YEAR
|
|
55
|
-
};
|