@kamen/create-webapp 1.0.18 → 1.0.20
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 +1 -3
- package/index.js +17 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
## Project Scaffolding
|
|
4
4
|
|
|
5
|
-
With NPM:
|
|
6
|
-
|
|
7
5
|
```bash
|
|
8
6
|
$ npm init @kamen/webapp
|
|
9
7
|
```
|
|
@@ -16,7 +14,7 @@ import {randomFromRange, randomFromList} from "@kamen/create-webapp";
|
|
|
16
14
|
const colors = ['red', 'green', 'blue'];
|
|
17
15
|
const data = {
|
|
18
16
|
color: randomFromList(colors),
|
|
19
|
-
|
|
17
|
+
count: randomFromRange(0, 99),
|
|
20
18
|
state: Boolean(randomFromRange(0, 1))
|
|
21
19
|
};
|
|
22
20
|
|
package/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export function isObject(value) {
|
|
|
20
20
|
/**
|
|
21
21
|
* @param {number} offset
|
|
22
22
|
* @param {number} length
|
|
23
|
-
* @
|
|
23
|
+
* @returns {number}
|
|
24
24
|
*/
|
|
25
25
|
export function modulo(offset, length) {
|
|
26
26
|
return ((offset % length) + length) % length;
|
|
@@ -30,7 +30,7 @@ export function modulo(offset, length) {
|
|
|
30
30
|
* @param {number} [min=0]
|
|
31
31
|
* @param {number} [max=255]
|
|
32
32
|
* @param {number} [step=1]
|
|
33
|
-
* @
|
|
33
|
+
* @returns {number[]}
|
|
34
34
|
*/
|
|
35
35
|
export function range(min = 0, max = 255, step = 1) {
|
|
36
36
|
return Array.from({length: (max - min) / step + 1}, (_, index) => index * step + min);
|
|
@@ -40,7 +40,7 @@ export function range(min = 0, max = 255, step = 1) {
|
|
|
40
40
|
* @param {number} value
|
|
41
41
|
* @param {number} [min=0]
|
|
42
42
|
* @param {number} [max=255]
|
|
43
|
-
* @
|
|
43
|
+
* @returns {number}
|
|
44
44
|
*/
|
|
45
45
|
export function clamp(value, min = 0, max = 255) {
|
|
46
46
|
return Math.min(Math.max(value, min), max);
|
|
@@ -49,7 +49,7 @@ export function clamp(value, min = 0, max = 255) {
|
|
|
49
49
|
/**
|
|
50
50
|
* @param {number} [min=0]
|
|
51
51
|
* @param {number} [max=255]
|
|
52
|
-
* @
|
|
52
|
+
* @returns {number}
|
|
53
53
|
*/
|
|
54
54
|
export function randomFromRange(min = 0, max = 255) {
|
|
55
55
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
@@ -87,4 +87,17 @@ export function textToHsla(text = '', saturation = 80, lightness = 80, alpha = 1
|
|
|
87
87
|
export function randomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
|
|
88
88
|
const hue = randomFromRange(0, 359);
|
|
89
89
|
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {number} [max=1<<24]
|
|
94
|
+
* @returns {Set<number>}
|
|
95
|
+
*/
|
|
96
|
+
export function sieveOfEratosthenes(max = 1 << 24) {
|
|
97
|
+
const primes = new Set;
|
|
98
|
+
for (let i = 2; i < max; i++) primes.add(i);
|
|
99
|
+
for (let p = 2; p * p <= max; p++)
|
|
100
|
+
if (primes.has(p))
|
|
101
|
+
for (let i = p * p; i <= max; i += p) primes.delete(i);
|
|
102
|
+
return primes;
|
|
90
103
|
}
|