expose how resources should be serialized
Closed this issue · 14 comments
Problem
Different codebases prefer different serialization styles, see MagicMirrorOrg/MagicMirror#3025 (comment).
Solution
Expose the possibility to override the default serialization style. See https://stackoverflow.com/a/3515761
Hey folks:
working on the formatting of the json files.
I think there are two main things that need to be added regarding the format of json files.
- serialize spacing
- flatten all keys
I suggest somthing like that:
export type PluginSettings = {
pathPattern: string;
variableReferencePattern?: [string, string];
sourceFormat: {
spacing: number;
flatten: boolean;
}
};
@NilsJacobsen What do you mean with flatten?
We need to also consider tabs
vs spaces
.
Guys, don't complicate things. Just expose the JSON.stringify
arguments.
To expose serialization, you can just expose the arguments of JSON.stringify
.
export type PluginSettings = {
pathPattern: string;
variableReferencePattern?: [string, string];
stringify: [replacer: Parameters<typeof JSON.stringify>[1], space: Parameters<typeof JSON.stringify>[2]]
};
OR use an object for explicit naming and get rid of required "spacer" argument
export type PluginSettings = {
pathPattern: string;
variableReferencePattern?: [string, string];
stringify?: {
replacer?: Parameters<typeof JSON.stringify>[1],
space?: Parameters<typeof JSON.stringify>[2]]
}
};
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
I agree using the types of stringify makes sense to me
Actually space and flatten shoundn't be required. I would say default spacing 2 or 4 and flatten false.
What do you think?
export type PluginSettings = {
pathPattern: string;
variableReferencePattern?: [string, string];
stringify?: {
space?: Parameters<typeof JSON.stringify>[2];
flatten?: boolean;
}
};
Actually space and flatten shoundn't be required. I would say default spacing 2 or 4 and flatten false.
What do you think?
Agree. Everything in stringify
is optional.
export type PluginSettings = {
pathPattern: string;
variableReferencePattern?: [string, string];
stringify?: {
replacer?: Parameters[1],
space?: Parameters[2]]
}
};
@NilsJacobsen What do you think about renaming stringify
to serialize
to illustrate that this property is defining how things are "serialized"? Adding flatten seems to be a good fit then.
export type PluginSettings = {
pathPattern: string;
variableReferencePattern?: [string, string];
- stringify?: {
+ serialize?: {
- replacer?: Parameters<typeof JSON.stringify>[1],
space?: Parameters<typeof JSON.stringify>[2]],
+ flatten?: boolean
}
};
@NilsJacobsen haha we prorposed the same type! Should we stick with stringify or serialize?
😂 I would prefer serialize
@NilsJacobsen lets go with serialize then 🚀
Another issue with the file ending: opral/monorepo#875
This issue is complete. The bug @ivanhofer mentioned is tracked in #28 (comment)