@kamen/create-webapp 1.0.27 → 1.0.28

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 +84 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -65,28 +65,62 @@ export function randomFromList(list = []) {
65
65
  }
66
66
 
67
67
  /**
68
- * @param {string} [text='']
69
68
  * @param {number} [saturation=80]
70
69
  * @param {number} [lightness=80]
71
70
  * @param {number} [alpha=1]
72
71
  * @returns {string}
73
72
  */
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})`;
73
+ export function randomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
74
+ const hue = randomFromRange(0, 359);
75
+ return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
76
+ }
77
+
78
+ /**
79
+ * @param {number} [min=0]
80
+ * @param {number} [max=255]
81
+ * @returns {Function<number>}
82
+ */
83
+ export function createRandomFromRange(min = 0, max = 255) {
84
+ return function () {
85
+ return randomFromRange(min, max);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * @template T
91
+ * @param {T[]} [list=[]]
92
+ * @returns {Function<T>}
93
+ */
94
+ export function createRandomFromList(list = []) {
95
+ return function () {
96
+ return randomFromList(list);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * @param {number} [saturation=80]
102
+ * @param {number} [lightness=80]
103
+ * @param {number} [alpha=1]
104
+ * @returns {Function<string>}
105
+ */
106
+ export function createRandomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
107
+ return function () {
108
+ return randomColorFromSaturationLightnessAlpha(saturation, lightness, alpha);
109
+ }
79
110
  }
80
111
 
81
112
  /**
113
+ * @param {string} [text='']
82
114
  * @param {number} [saturation=80]
83
115
  * @param {number} [lightness=80]
84
116
  * @param {number} [alpha=1]
85
117
  * @returns {string}
86
118
  */
87
- export function randomColorFromSaturationLightnessAlpha(saturation = 80, lightness = 80, alpha = 1) {
88
- const hue = randomFromRange(0, 359);
89
- return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
119
+ export function textToHsla(text = '', saturation = 80, lightness = 80, alpha = 1) {
120
+ let hash = 0;
121
+ for (let i = 0, {length} = text; i < length; i++)
122
+ hash = text.charCodeAt(i) + ((hash << 5) - hash);
123
+ return `hsla(${hash % 360}, ${saturation}%, ${lightness}%, ${alpha})`;
90
124
  }
91
125
 
92
126
  /**
@@ -221,4 +255,45 @@ export function findVue(version = 2, root = document, hook = '__VUE_DEVTOOLS_GLO
221
255
  }
222
256
 
223
257
  return 'Vue mountpoint not found';
258
+ }
259
+
260
+ /**
261
+ * URL wrapper implementing builder pattern
262
+ */
263
+ export class URLBuilder {
264
+ static create(url, base) {
265
+ return new this(url, base);
266
+ }
267
+
268
+ constructor(url, base) {
269
+ this.url = new URL(url, base);
270
+ }
271
+
272
+ appendParams(name, value) {
273
+ this.url.searchParams.append(name, value);
274
+ return this;
275
+ }
276
+
277
+ deleteParams(name, value) {
278
+ this.url.searchParams.delete(name, value);
279
+ return this;
280
+ }
281
+
282
+ setParams(name, value) {
283
+ this.url.searchParams.set(name, value);
284
+ return this;
285
+ }
286
+
287
+ createParams(options) {
288
+ this.url.searchParams = new URLSearchParams(options);
289
+ return this;
290
+ }
291
+
292
+ get hash() {
293
+ return this.url.hash;
294
+ }
295
+
296
+ toString() {
297
+ return this.url.toString();
298
+ }
224
299
  }
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.28",
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",