@awesomeness-js/utils 1.0.7 → 1.0.11

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,22 +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';
11
12
  import _isUUID from './src/isUUID.js';
12
13
  import _md5 from './src/md5.js';
14
+ import _setLocalEnvs from './src/setLocalEnvs.js';
13
15
  import _toPennies from './src/toPennies.js';
14
16
  import _uuid from './src/uuid.js';
15
17
 
16
18
  export { _build as build };
19
+ export { _combineFiles as combineFiles };
17
20
  export { _convertBytes as convertBytes };
18
21
  export { _each as each };
19
22
  export { _eachAsync as eachAsync };
20
23
  export { _getAllFiles as getAllFiles };
21
24
  export { _isUUID as isUUID };
22
25
  export { _md5 as md5 };
26
+ export { _setLocalEnvs as setLocalEnvs };
23
27
  export { _toPennies as toPennies };
24
28
  export { _uuid as uuid };
25
29
 
@@ -33,12 +37,14 @@ export default {
33
37
  * @returns {bool} - Returns true if the output file is generated successfully.
34
38
  */
35
39
  build: _build,
40
+ combineFiles: _combineFiles,
36
41
  convertBytes: _convertBytes,
37
42
  each: _each,
38
43
  eachAsync: _eachAsync,
39
44
  getAllFiles: _getAllFiles,
40
45
  isUUID: _isUUID,
41
46
  md5: _md5,
47
+ setLocalEnvs: _setLocalEnvs,
42
48
  toPennies: _toPennies,
43
49
  uuid: _uuid
44
50
  };
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.11",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1 @@
1
+ JUST_A_TEST='Dev just a test'
@@ -0,0 +1 @@
1
+ JUST_A_TEST='Local just a test'
@@ -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
+ }
@@ -0,0 +1,33 @@
1
+ import { readFile } from 'fs/promises';
2
+ export default async (localSecretsPath = './secrets/local.env') => {
3
+
4
+ // get the file
5
+ let localSecrets = await readFile(localSecretsPath, 'utf8');
6
+
7
+ // parse the file
8
+ let lines = localSecrets.split('\n');
9
+ for(let line of lines){
10
+
11
+ // skip #
12
+ if(line[0] === '#'){ continue; }
13
+
14
+ let parts = line.split('=');
15
+ if(parts.length === 2){
16
+ // remove outside single quotes
17
+ if(
18
+ parts[1][0] === "'"
19
+ && parts[1][parts[1].length - 1] === "'"
20
+ ){
21
+ parts[1] = parts[1].substring(1, parts[1].length - 1);
22
+ }
23
+
24
+ // remove \r
25
+ if(parts[1][parts[1].length - 1] === '\r'){
26
+ parts[1] = parts[1].substring(0, parts[1].length - 1);
27
+ }
28
+
29
+ process.env[parts[0]] = parts[1];
30
+ }
31
+ }
32
+
33
+ }
package/test.js CHANGED
@@ -10,4 +10,18 @@ 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
+
23
+ await utils.setLocalEnvs('./secrets/local.env');
24
+ console.log('localEnv', process.env.JUST_A_TEST);
25
+
26
+ await utils.setLocalEnvs('./secrets/dev.env');
27
+ console.log('localEnv', process.env.JUST_A_TEST);