@jamesrock/rockjs 1.2.0 → 1.3.0

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 +27 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -25,6 +25,10 @@ export const shuffle = (array) => {
25
25
  return array;
26
26
  };
27
27
 
28
+ export const makeArray = (length, mapper = (a, i) => i) => {
29
+ return Array.from({length}).map(mapper);
30
+ };
31
+
28
32
  export const createNode = (type, className) => {
29
33
  const node = document.createElement(type);
30
34
  if(className) {
@@ -112,7 +116,7 @@ export class Storage {
112
116
  };
113
117
  fetch() {
114
118
 
115
- return JSON.parse(localStorage.getItem(this.namespace)||"{}");
119
+ return JSON.parse(localStorage.getItem(this.namespace)||'{}');
116
120
 
117
121
  };
118
122
  clear() {
@@ -126,3 +130,25 @@ export class Storage {
126
130
 
127
131
  };
128
132
  };
133
+
134
+ export class GUID {
135
+ constructor() {
136
+
137
+ this.chars = [...this.uppercase, ...this.lowercase, ...this.numeric];
138
+
139
+ };
140
+ uppercase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
141
+ lowercase = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
142
+ numeric = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
143
+ segment() {
144
+
145
+ return makeArray(4, (a, i) => getRandom(i > 0 ? this.chars : this.uppercase)).join('');
146
+
147
+ };
148
+ get() {
149
+
150
+ return makeArray(this.segments, () => this.segment()).join('-');
151
+
152
+ };
153
+ segments = 3;
154
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",