第一次收到别人的 PR 👻
早上送走爸妈之后才发现今天没看 GitHub 通知,一打开

大部分都是垃圾信息,但是发现居然有人给我的 partial-json 提了一个 PR
Sourcery 的总结还挺好的,一看就懂

说起来,很戏剧性地,由于我这个项目是刚开始用 JavaScript 的时候写的,当时还不太懂 CI,于是没有配 formatter 的 config,这个人直接不小心把所有文件都重新格式化了,造成 600 行的 diff 😂

说回到这个功能,虽然我自己先前也想搞这么个东西,但是由于觉得想不到完美的设计,所以就没干了。
Your proposal is great and this implementation works well. But due to my perfectionist tendencies, I often find myself wondering if there's an even better way to solve these kinds of problems.
但是直接拒绝别人也不太建设性。于是我就想了很久(一个中午下午都耗在这上面了)
想了两个解决方案:
Approach One — Input Predicate Function
The parse will take an options object to extend configuration besides simple allow. We may support inputing a validate predicate function to choose whether to allow an object / array. The signature of options may look like this:
interface options {
allow: number;
validate(parsed: any, text: string, parents: Parent[]): boolean
}
type Parent = {
type: "OBJ";
key: string;
} | {
type: "ARR";
index: number;
}For example, if user do this:
parse(`[0, {"a": [{`, { allow: ALL, (parsed, text, parents) => { ... } })The validate function will be called at most 4 times with
validate({},...剩余内容已隐藏
第一次收到别人的 PR 👻
早上送走爸妈之后才发现今天没看 GitHub 通知,一打开

大部分都是垃圾信息,但是发现居然有人给我的 partial-json 提了一个 PR
Sourcery 的总结还挺好的,一看就懂

说起来,很戏剧性地,由于我这个项目是刚开始用 JavaScript 的时候写的,当时还不太懂 CI,于是没有配 formatter 的 config,这个人直接不小心把所有文件都重新格式化了,造成 600 行的 diff 😂

说回到这个功能,虽然我自己先前也想搞这么个东西,但是由于觉得想不到完美的设计,所以就没干了。
Your proposal is great and this implementation works well. But due to my perfectionist tendencies, I often find myself wondering if there's an even better way to solve these kinds of problems.
但是直接拒绝别人也不太建设性。于是我就想了很久(一个中午下午都耗在这上面了)
想了两个解决方案:
Approach One — Input Predicate Function
The parse will take an options object to extend configuration besides simple allow. We may support inputing a validate predicate function to choose whether to allow an object / array. The signature of options may look like this:
interface options {
allow: number;
validate(parsed: any, text: string, parents: Parent[]): boolean
}
type Parent = {
type: "OBJ";
key: string;
} | {
type: "ARR";
index: number;
}For example, if user do this:
parse(`[0, {"a": [{`, { allow: ALL, (parsed, text, parents) => { ... } })The validate function will be called at most 4 times with
validate({},...剩余内容已隐藏