@awesomeness-js/utils 1.0.6 → 1.0.7

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/index.js CHANGED
@@ -8,16 +8,20 @@ import _convertBytes from './src/convertBytes.js';
8
8
  import _each from './src/each.js';
9
9
  import _eachAsync from './src/eachAsync.js';
10
10
  import _getAllFiles from './src/getAllFiles.js';
11
+ import _isUUID from './src/isUUID.js';
11
12
  import _md5 from './src/md5.js';
12
13
  import _toPennies from './src/toPennies.js';
14
+ import _uuid from './src/uuid.js';
13
15
 
14
16
  export { _build as build };
15
17
  export { _convertBytes as convertBytes };
16
18
  export { _each as each };
17
19
  export { _eachAsync as eachAsync };
18
20
  export { _getAllFiles as getAllFiles };
21
+ export { _isUUID as isUUID };
19
22
  export { _md5 as md5 };
20
23
  export { _toPennies as toPennies };
24
+ export { _uuid as uuid };
21
25
 
22
26
  export default {
23
27
  /**
@@ -33,6 +37,8 @@ export default {
33
37
  each: _each,
34
38
  eachAsync: _eachAsync,
35
39
  getAllFiles: _getAllFiles,
40
+ isUUID: _isUUID,
36
41
  md5: _md5,
37
- toPennies: _toPennies
42
+ toPennies: _toPennies,
43
+ uuid: _uuid
38
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomeness-js/utils",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
package/src/isUUID.js ADDED
@@ -0,0 +1,6 @@
1
+ function isUUID(uuid) {
2
+ const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
3
+ return uuidV4Regex.test(uuid);
4
+ }
5
+
6
+ export default isUUID;
package/src/uuid.js ADDED
@@ -0,0 +1,16 @@
1
+ import crypto from 'crypto';
2
+
3
+ // V4
4
+ function uuid() {
5
+ const arr = crypto.randomBytes(16);
6
+
7
+ // Set the UUID version and clock sequence bits as per RFC4122
8
+ arr[6] = (arr[6] & 0x0f) | 0x40;
9
+ arr[8] = (arr[8] & 0x3f) | 0x80;
10
+
11
+ return [...arr].map((b, i) =>
12
+ [4, 6, 8, 10].includes(i) ? '-' + b.toString(16).padStart(2, '0') : b.toString(16).padStart(2, '0')
13
+ ).join('');
14
+ }
15
+
16
+ export default uuid;
package/test.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import utils from './index.js';
2
2
 
3
3
  let fileList = utils.getAllFiles('./src');
4
- console.log(fileList);
4
+ console.log({fileList});
5
5
 
6
6
  let md5Test = utils.md5('test');
7
- console.log(md5Test);
7
+ console.log({md5Test});
8
+
9
+ let uuidTest = utils.uuid();
10
+ console.log({uuidTest});
11
+
12
+ let isUUIDTest = utils.isUUID(uuidTest);
13
+ console.log({isUUIDTest});