pathchain 1.0.5 → 1.0.6

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/checker.js +59 -1
  2. package/package.json +1 -1
package/checker.js CHANGED
@@ -17,4 +17,62 @@ function checkDir(dir){
17
17
  }
18
18
  }
19
19
 
20
- module.exports = { checkDir }
20
+ /** checkFiles
21
+ * [Function that returns files in directory]
22
+ *
23
+ * @param {string} dir (required)
24
+ *
25
+ * @return void
26
+ */
27
+ function checkFiles(dir){
28
+ var files = fs.readdirSync(dir);
29
+ return files;
30
+ }
31
+
32
+ /** checkEmptyDir
33
+ * [Function that returns TRUE if dir is empty, FALSE if not]
34
+ *
35
+ * @param {string} dir (required)
36
+ *
37
+ * @return {bool} empty_dir
38
+ */
39
+ function checkEmptyDir(dir) {
40
+ var empty_dir = emptyDir.sync(dir);
41
+ return empty_dir
42
+ }
43
+
44
+ /** isSecretUsed
45
+ * [Function that returns TRUE if secret has been used, FALSE if not]
46
+ *
47
+ * @param {string} xsecret (required)
48
+ *
49
+ * @return {bool} used_secret
50
+ */
51
+ function isSecretUsed(xsecret) {
52
+ // DECODING SECRET
53
+ var secret_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/secret.proto'))
54
+
55
+ // NOT FOUND EXCEPTION
56
+ var secret_enc;
57
+ try {
58
+ secret_enc = fs.readFileSync("files/"+xsecret)
59
+ } catch (err) {
60
+ if (err.code === 'ENOENT') {
61
+ return "Secret not found :(";
62
+ } else {
63
+ throw err;
64
+ }
65
+ }
66
+
67
+ var secret_obj = secret_pb.secret.decode(secret_enc)
68
+
69
+ if(secret_obj.used == false){
70
+ return false
71
+ }
72
+ return true;
73
+ }
74
+
75
+ // CHECKING THE SECRET CHECKS THE SECRET
76
+
77
+ module.exports = { checkDir, checkFiles, checkEmptyDir, isSecretUsed };
78
+
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "pathchain",
3
- "version": "1.0.5"
3
+ "version": "1.0.6"
4
4
  }