@awesomeness-js/utils 1.0.6 → 1.0.10

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
@@ -4,20 +4,26 @@
4
4
  * Do not edit manually.
5
5
  */
6
6
  import _build from './src/build.js';
7
+ import _combineFiles from './src/combineFiles.js';
7
8
  import _convertBytes from './src/convertBytes.js';
8
9
  import _each from './src/each.js';
9
10
  import _eachAsync from './src/eachAsync.js';
10
11
  import _getAllFiles from './src/getAllFiles.js';
12
+ import _isUUID from './src/isUUID.js';
11
13
  import _md5 from './src/md5.js';
12
14
  import _toPennies from './src/toPennies.js';
15
+ import _uuid from './src/uuid.js';
13
16
 
14
17
  export { _build as build };
18
+ export { _combineFiles as combineFiles };
15
19
  export { _convertBytes as convertBytes };
16
20
  export { _each as each };
17
21
  export { _eachAsync as eachAsync };
18
22
  export { _getAllFiles as getAllFiles };
23
+ export { _isUUID as isUUID };
19
24
  export { _md5 as md5 };
20
25
  export { _toPennies as toPennies };
26
+ export { _uuid as uuid };
21
27
 
22
28
  export default {
23
29
  /**
@@ -29,10 +35,13 @@ export default {
29
35
  * @returns {bool} - Returns true if the output file is generated successfully.
30
36
  */
31
37
  build: _build,
38
+ combineFiles: _combineFiles,
32
39
  convertBytes: _convertBytes,
33
40
  each: _each,
34
41
  eachAsync: _eachAsync,
35
42
  getAllFiles: _getAllFiles,
43
+ isUUID: _isUUID,
36
44
  md5: _md5,
37
- toPennies: _toPennies
45
+ toPennies: _toPennies,
46
+ uuid: _uuid
38
47
  };
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.10",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,69 @@
1
+ // main-module/index.js
2
+ import { readdirSync, statSync, readFileSync } from 'fs';
3
+
4
+ function combineFiles(dir, fileType, {
5
+ minify = false,
6
+ moduleToBrowser = false,
7
+ } = {}) {
8
+
9
+ var returnString = "";
10
+
11
+ let stuff = readdirSync(dir);
12
+
13
+ // sort it
14
+ stuff = stuff.sort();
15
+
16
+
17
+ stuff.forEach(stuff => {
18
+
19
+ const isDir = statSync(`${dir}/${stuff}`).isDirectory();
20
+
21
+ if(isDir){
22
+
23
+ returnString += combineFiles(`${dir}/${stuff}`, fileType);
24
+
25
+ } else {
26
+
27
+ // is file
28
+
29
+ // get file and extenstion from stuff
30
+ let file = stuff.split('.');
31
+ let ext = file[file.length - 1];
32
+
33
+ if(ext === fileType){
34
+
35
+ let thisData = readFileSync(`${dir}/${stuff}`, 'utf8');
36
+
37
+ if(moduleToBrowser){
38
+
39
+ // can this file be converted to browser?
40
+ let browserFriendly = thisData.startsWith('export default ');
41
+
42
+ if(browserFriendly){
43
+
44
+ // strip properly formatted file
45
+ thisData = thisData.replace('export default ', '');
46
+
47
+ } else {
48
+ thisData = "";
49
+ }
50
+
51
+ }
52
+
53
+ if(minify){
54
+ // todo
55
+ }
56
+
57
+ returnString += thisData + " \n ";
58
+
59
+ }
60
+
61
+ }
62
+
63
+ });
64
+
65
+ return returnString;
66
+
67
+ };
68
+
69
+ export default combineFiles;
package/src/isUUID.js ADDED
@@ -0,0 +1,4 @@
1
+ export default 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
+ }
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,22 @@
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});
14
+
15
+ let combineTest = utils.combineFiles('./src', 'js');
16
+ console.log('combineTest', combineTest.length);
17
+
18
+ let combineTestBrowser = utils.combineFiles('./src', 'js', {
19
+ moduleToBrowser: true
20
+ });
21
+ console.log('combineTestBrowser', combineTestBrowser.length);
22
+