@kamen/create-webapp 1.0.27 → 1.0.29

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.
Files changed (2) hide show
  1. package/index.js +111 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,3 +1,9 @@
1
+ import packages from './package.json' with {type: 'json'};
2
+
3
+ console.dir(packages);
4
+
5
+
6
+
1
7
  const primitiveTypeRe = /^string|number|bigint|boolean|symbol$/;
2
8
  const objectTypeRe = /^object|function$/;
3
9
 
@@ -65,28 +71,62 @@ export function randomFromList(list = []) {
65
71
  }
66
72
 
67
73
  /**
68
- * @param {string} [text='']
69
74
  * @param {number} [saturation=80]
70
75
  * @param {number} [lightness=80]
71
76
  * @param {number} [alpha=1]
72
77
  * @returns {string}
73
78
  */
74
- export function textToHsla(text = '', saturation = 80, lightness = 80, alpha = 1) {
75
- let hash = 0;
76
- for (let i = 0, {length} = text; i < length; i++)
77
- hash = text.charCodeAt(i) + ((hash << 5) - hash);
78
- return `hsla(${hash % 360}, ${saturation}%, ${lightness}%, ${alpha})`;
79
+ export function randomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
80
+ const hue = randomFromRange(0, 359);
81
+ return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
82
+ }
83
+
84
+ /**
85
+ * @param {number} [min=0]
86
+ * @param {number} [max=255]
87
+ * @returns {Function<number>}
88
+ */
89
+ export function createRandomFromRange(min = 0, max = 255) {
90
+ return function () {
91
+ return randomFromRange(min, max);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * @template T
97
+ * @param {T[]} [list=[]]
98
+ * @returns {Function<T>}
99
+ */
100
+ export function createRandomFromList(list = []) {
101
+ return function () {
102
+ return randomFromList(list);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * @param {number} [saturation=80]
108
+ * @param {number} [lightness=80]
109
+ * @param {number} [alpha=1]
110
+ * @returns {Function<string>}
111
+ */
112
+ export function createRandomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
113
+ return function () {
114
+ return randomColorFromSaturationLightnessAlpha(saturation, lightness, alpha);
115
+ }
79
116
  }
80
117
 
81
118
  /**
119
+ * @param {string} [text='']
82
120
  * @param {number} [saturation=80]
83
121
  * @param {number} [lightness=80]
84
122
  * @param {number} [alpha=1]
85
123
  * @returns {string}
86
124
  */
87
- export function randomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
88
- const hue = randomFromRange(0, 359);
89
- return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
125
+ export function textToHsla(text = '', saturation = 80, lightness = 80, alpha = 1) {
126
+ let hash = 0;
127
+ for (let i = 0, {length} = text; i < length; i++)
128
+ hash = text.charCodeAt(i) + ((hash << 5) - hash);
129
+ return `hsla(${hash % 360}, ${saturation}%, ${lightness}%, ${alpha})`;
90
130
  }
91
131
 
92
132
  /**
@@ -221,4 +261,65 @@ export function findVue(version = 2, root = document, hook = '__VUE_DEVTOOLS_GLO
221
261
  }
222
262
 
223
263
  return 'Vue mountpoint not found';
224
- }
264
+ }
265
+
266
+ /**
267
+ * URL wrapper implementing builder pattern
268
+ */
269
+ export class URLBuilder {
270
+ static create(url, base) {
271
+ return new this(url, base);
272
+ }
273
+
274
+ constructor(url, base) {
275
+ this.url = new URL(url, base);
276
+ }
277
+
278
+ appendParams(name, value) {
279
+ this.url.searchParams.append(name, value);
280
+ return this;
281
+ }
282
+
283
+ deleteParams(name, value) {
284
+ this.url.searchParams.delete(name, value);
285
+ return this;
286
+ }
287
+
288
+ setParams(name, value) {
289
+ this.url.searchParams.set(name, value);
290
+ return this;
291
+ }
292
+
293
+ createParams(options) {
294
+ this.url.searchParams = new URLSearchParams(options);
295
+ return this;
296
+ }
297
+
298
+ get hash() {
299
+ return this.url.hash;
300
+ }
301
+
302
+ toString() {
303
+ return this.url.toString();
304
+ }
305
+ }
306
+
307
+ export const introspection = {
308
+ isPrimitive,
309
+ isObject
310
+ };
311
+
312
+ export const numbering = {
313
+ modulo,
314
+ range,
315
+ clamp
316
+ };
317
+
318
+ export const randomness = {
319
+ randomFromRange,
320
+ createRandomFromRange,
321
+ randomFromList,
322
+ createRandomFromList,
323
+ randomColorFromSaturationLightnessAlpha,
324
+ createRandomColorFromSaturationLightnessAlpha
325
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamen/create-webapp",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "npm init @kamen/webapp",
5
5
  "homepage": "https://www.npmjs.com/package/@kamen/create-webapp",
6
6
  "license": "GPL-2.0-only",