@awesomeness-js/utils 1.0.7 → 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,6 +4,7 @@
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';
@@ -14,6 +15,7 @@ import _toPennies from './src/toPennies.js';
14
15
  import _uuid from './src/uuid.js';
15
16
 
16
17
  export { _build as build };
18
+ export { _combineFiles as combineFiles };
17
19
  export { _convertBytes as convertBytes };
18
20
  export { _each as each };
19
21
  export { _eachAsync as eachAsync };
@@ -33,6 +35,7 @@ export default {
33
35
  * @returns {bool} - Returns true if the output file is generated successfully.
34
36
  */
35
37
  build: _build,
38
+ combineFiles: _combineFiles,
36
39
  convertBytes: _convertBytes,
37
40
  each: _each,
38
41
  eachAsync: _eachAsync,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomeness-js/utils",
3
- "version": "1.0.7",
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 CHANGED
@@ -1,6 +1,4 @@
1
- function isUUID(uuid) {
1
+ export default function isUUID(uuid) {
2
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
3
  return uuidV4Regex.test(uuid);
4
- }
5
-
6
- export default isUUID;
4
+ }
package/test.js CHANGED
@@ -10,4 +10,13 @@ let uuidTest = utils.uuid();
10
10
  console.log({uuidTest});
11
11
 
12
12
  let isUUIDTest = utils.isUUID(uuidTest);
13
- console.log({isUUIDTest});
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
+