-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(crush): support dot in property name #23
Conversation
35fc67a
to
04bad7b
Compare
@aleclarson, I fixed the problem but I'm having trouble with the tooling. type Primitive = number | string | boolean | Date | symbol | bigint | undefined | null;
const crush = <TValue extends object>(value: TValue): Record<string, Primitive> | Record<string, never> => {
if (!value) return {};
const crushToPvArray: (obj: object, path: string) => Array<{ p: string; v: Primitive }> = (
obj: object,
path: string
) =>
Object.entries(obj).flatMap(([key, value]) =>
isPrimitive(value) ? { p: path ? `${path}.${key}` : key, v: value } : crushToPvArray(value, `${path}.${key}`)
);
return objectify(
crushToPvArray(value, ''),
(o) => o.p,
(o) => o.v
);
}; |
Hi @stefaanMLB, If PNPM is causing you trouble locally, you could try using Github codespaces instead. In my experience, PNPM hasn't been hard to use, but I don't know your set up. If you'd prefer to use NPM, it should be okay, but you don't get the lockfile (which normally isn't a big deal). npm install --no-package-lock Feel free to open a new PR with your solution and I'll review it there, thanks. |
@aleclarson, I believe I solved this problem and succeeded to create PR#95. |
2154f96
to
6a4b4f6
Compare
e789c1f
to
0168241
Compare
Closed in favor of #95 |
Tip
The owner of this PR can publish a preview release by commenting
/publish
in this PR. Afterwards, anyone can try it out by runningpnpm add radashi@pr<PR_NUMBER>
.Description
Currently, the
crush
function combines theobjectify
andkeys
functions to achieve its behavior.The cause of the issue is with
keys
creating no discernible difference between a property with a dot in it (i.e.{"a.b":1} => "a.b"
) and a property path of multiple property names (i.e.{a:{b:1}} => "a.b"
).As of now, this PR only adds a test case to verify the bug report by @stefaanMLB.
Checklist
/docs
directory) has been updatedResolves
Resolves sodiray/radash#365
Bundle impact
src/object/crush.ts
Footnotes
Function size includes the
import
dependencies of the function. ↩