summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api.js18
-rwxr-xr-xsrc/cli.js2
-rw-r--r--src/utils.js43
3 files changed, 60 insertions, 3 deletions
diff --git a/src/api.js b/src/api.js
index 1ce7bcc..99ba01c 100644
--- a/src/api.js
+++ b/src/api.js
@@ -1,3 +1,17 @@
-export const main = async () => {
- console.log({ argv: process.argv });
+const { eq } = require("./utils.js");
+
+const main = async () => {
+ if (process.argv.length !== 2) {
+ console.log("papo 1970-01-01 0.1.0");
+ return;
+ }
+
+ console.log({
+ argv: process.argv,
+ eq: eq({a: 1}, {a: 1}),
+ });
+};
+
+module.exports = {
+ main,
};
diff --git a/src/cli.js b/src/cli.js
index aa602f7..2b486fe 100755
--- a/src/cli.js
+++ b/src/cli.js
@@ -1,4 +1,4 @@
#!/usr/bin/env node
-import { main } from "papo";
+const { main } = require("papo");
(async () => await main())();
diff --git a/src/utils.js b/src/utils.js
new file mode 100644
index 0000000..1877a58
--- /dev/null
+++ b/src/utils.js
@@ -0,0 +1,43 @@
+const eq = (a, b) => {
+ if (a === b) {
+ return true;
+ }
+
+ if (a === null || b === null) {
+ return false;
+ }
+
+ if (typeof a != "object" || typeof b != "object") {
+ return false;
+ }
+
+ if (Array.isArray(a) !== Array.isArray(b)) {
+ return false;
+ }
+
+ if (Object.keys(a).length !== Object.keys(b).length) {
+ return false;
+ }
+
+ for (const k in a) {
+ if (!b.hasOwnProperty(k)) {
+ return false;
+ }
+ if (!eq(a[k], b[k])) {
+ return false;
+ }
+ }
+ return true;
+};
+
+const keys = (ks, obj) =>
+ ks.reduce(
+ (ret, k) =>
+ obj.hasOwnProperty(k) ? {...ret, [k]: obj[k]} : ret,
+ {},
+ );
+
+module.exports = {
+ eq,
+ keys,
+};