Jason Staten 8 months ago
commit a773f29eb9

@ -0,0 +1,23 @@
const iter = (obj, stack) => {
const key = stack.join('.');
if (obj === null) {
return `${key}=null`
}
if (typeof obj === "object") {
return `${key}={}`
}
if (typeof obj === "string") {
return `${key}=${JSON.stringify(obj)}`
}
return `${key}=${obj}`
}
export const gronify = (obj) => {
return iter(obj, ["json"])
}

@ -0,0 +1,28 @@
import test from "node:test"
import assert from "node:assert"
import { gronify } from "./ngron.mjs";
test("number", () => {
const result = gronify(3)
assert.strictEqual(result, `json=3`)
});
test("string", () => {
const result = gronify("hello")
assert.strictEqual(result, `json="hello"`)
});
test("empty obj", () => {
const result = gronify({})
assert.strictEqual(result, `json={}`)
});
test("null", () => {
const result = gronify(null)
assert.strictEqual(result, `json=null`)
});
Loading…
Cancel
Save