arcadible 0.1.3 → 0.1.4

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/package.json CHANGED
@@ -51,5 +51,5 @@
51
51
  "license": "Apache-2.0",
52
52
  "main": "./src/cli/index.js",
53
53
  "name": "arcadible",
54
- "version": "0.1.3"
54
+ "version": "0.1.4"
55
55
  }
@@ -14,11 +14,11 @@ const objs = require("../util/objs");
14
14
 
15
15
  // [use]
16
16
 
17
+ const compactObjs = objs.compact;
17
18
  const extname = path.extname;
18
19
  const join = path.join;
19
20
  const pathExists = fs.pathExists;
20
21
  const pathParse = path.parse;
21
- const pruneEmpty = objs.pruneEmpty;
22
22
  const readdir = fs.promises.readdir;
23
23
 
24
24
  // [declare]
@@ -84,7 +84,7 @@ const parse = function (root) {
84
84
  Promise.resolve({})
85
85
  .then(art(root))
86
86
  .then(gallery(root))
87
- .then(pruneEmpty)
87
+ .then(compactObjs)
88
88
  .then((game) => ({ game }))
89
89
  .then(resolve)
90
90
  .catch(reject);
@@ -17,9 +17,9 @@ const strs = require("../util/strs");
17
17
 
18
18
  // [use]
19
19
 
20
+ const compactObjs = objs.compact;
20
21
  const join = path.join;
21
22
  const pathExists = fs.pathExists;
22
- const pruneEmpty = objs.pruneEmpty;
23
23
  const readFile = fs.readFile;
24
24
  const trimWhitespace = strs.trimWhitespace;
25
25
 
@@ -145,7 +145,7 @@ const parse = function (root) {
145
145
  return findReadme(root)
146
146
  .then((file) => (file ? readFile(join(root, file), "utf8") : null))
147
147
  .then((buf) => (buf === null ? null : parseReadme(buf)))
148
- .then(pruneEmpty)
148
+ .then(compactObjs)
149
149
  .then((game) => ({ game: game || null }));
150
150
  };
151
151
 
package/src/user.js CHANGED
@@ -11,6 +11,7 @@ const fs = require("fs-extra");
11
11
  // [import]
12
12
 
13
13
  const api = require("./api");
14
+ const objs = require("./util/objs");
14
15
  const os = require("./util/os");
15
16
 
16
17
  // [use]
@@ -19,6 +20,7 @@ const configDir = os.configDir;
19
20
  const join = path.join;
20
21
  const mkdir = fs.promises.mkdir;
21
22
  const readFile = fs.promises.readFile;
23
+ const sortObjs = objs.sort;
22
24
  const unlink = fs.promises.unlink;
23
25
  const writeFile = fs.promises.writeFile;
24
26
 
@@ -42,7 +44,9 @@ const expired = function (session) {
42
44
 
43
45
  const save = function (user) {
44
46
  return mkdir(dir, { recursive: true })
45
- .then(() => writeFile(file, JSON.stringify(user, null, 2), "utf8"))
47
+ .then(() =>
48
+ writeFile(file, JSON.stringify(sortObjs(user), null, 2), "utf8"),
49
+ )
46
50
  .then(() => user);
47
51
  };
48
52
 
package/src/util/objs.js CHANGED
@@ -6,19 +6,19 @@ const stringify = require("fast-json-stable-stringify");
6
6
 
7
7
  // [function]
8
8
 
9
- const pruneEmpty = function (value) {
9
+ const compact = function (value) {
10
10
  /* eslint-disable no-undefined */
11
11
  if (value === null || value === undefined) {
12
12
  return undefined;
13
13
  }
14
14
  if (Array.isArray(value)) {
15
- const cleaned = value.map(pruneEmpty).filter((v) => v !== undefined);
15
+ const cleaned = value.map(compact).filter((v) => v !== undefined);
16
16
  return cleaned.length ? cleaned : undefined;
17
17
  }
18
18
  if (typeof value === "object") {
19
19
  const cleaned = Object.fromEntries(
20
20
  Object.entries(value)
21
- .map(([k, v]) => [k, pruneEmpty(v)])
21
+ .map(([k, v]) => [k, compact(v)])
22
22
  .filter(([, v]) => v !== undefined),
23
23
  );
24
24
  return Object.keys(cleaned).length ? cleaned : undefined;
@@ -35,4 +35,4 @@ const sort = function (value) {
35
35
 
36
36
  // [export]
37
37
 
38
- module.exports = { pruneEmpty, sort };
38
+ module.exports = { compact, sort };
@@ -10,7 +10,7 @@ const objs = require("./objs");
10
10
 
11
11
  // [use]
12
12
 
13
- const sort = objs.sort;
13
+ const sortObjs = objs.sort;
14
14
 
15
15
  // [function]
16
16
 
@@ -21,7 +21,7 @@ const write = function (data) {
21
21
  // [function]
22
22
 
23
23
  const printJson = function (data) {
24
- write(JSON.stringify(sort(data), null, 2));
24
+ write(JSON.stringify(sortObjs(data), null, 2));
25
25
  };
26
26
 
27
27
  // [function]
@@ -33,7 +33,7 @@ const printToml = function (data, key = "value") {
33
33
  return;
34
34
  }
35
35
  try {
36
- write(TOML.stringify(sort(data)));
36
+ write(TOML.stringify(sortObjs(data)));
37
37
  } catch (ex) {
38
38
  write(TOML.stringify({ [field]: data }));
39
39
  }
package/src/util/zip.js CHANGED
@@ -9,10 +9,15 @@ const path = require("node:path");
9
9
 
10
10
  const AdmZip = require("adm-zip");
11
11
 
12
+ // [import]
13
+
14
+ const objs = require("./objs");
15
+
12
16
  // [use]
13
17
 
14
18
  const createHash = crypto.createHash;
15
19
  const join = path.join;
20
+ const sortObjs = objs.sort;
16
21
 
17
22
  // [class]
18
23
 
@@ -35,7 +40,10 @@ const Main = class {
35
40
 
36
41
  addJson(name, value) {
37
42
  const entry = join(this.prefix, name);
38
- const content = Buffer.from(JSON.stringify(value, null, 2), "utf8");
43
+ const content = Buffer.from(
44
+ JSON.stringify(sortObjs(value), null, 2),
45
+ "utf8",
46
+ );
39
47
  this.zip.addFile(entry, content);
40
48
  }
41
49