string-store & strings

I've been trying out string-store and it's a great utility, but it's becoming annoying to stringify everything (and it also makes my formatting look bad because a lot of times it forces prettier to wrap the lines). When I serialize a custom id, I have to do .setCustomId(store.serialize(Id.EditSomethingButton, ...).toString()), and when I just use a normal custom id, I have to do .setCustomId(Id.EditSomethingButton.toString()). I know this isn't a very big problem; should I just suck it up? (Or I would love a convenience method like serializeStr). Or is there a way to use an enum of strings for schema ids, even if they're just stringified numbers?
5 Replies
Lioness100
Lioness100OP4d ago
In the meantime I'll think I'll create a
export const StringId = Object.fromEntries(
Object.entries(CustomId).map(([key, value]) => [key, value.toString()])
) as Record<keyof typeof CustomId, string>;
export const StringId = Object.fromEntries(
Object.entries(CustomId).map(([key, value]) => [key, value.toString()])
) as Record<keyof typeof CustomId, string>;
for non-store use
kyra
kyra4d ago
Regarding the former, yes, I can make an alias serializeToString. Regarding the latter (IDs as strings), no, but you shouldn't mix string-store's binary data with non-binary data, you can do: store.serializeToString(Id.EditSomethingButton, {}) using an empty schema
Lioness100
Lioness100OP4d ago
Regarding the former, yes, I can make an alias serializeToString.
I'm wondering why serialize would return a buffer and serializeToString would be the variation when, to my expectations, the overwhelming overwhelming majority of use cases of serialize would be to get a string. Wouldn't it be more beneficial for serialize to return the string and serializeToBuffer to be the variation? And thank you for your quick response
kyra
kyra4d ago
That would be semver-major :p But tbf I could just do a v2, and make serialize return a string and serializeRaw return the buffer
Lioness100
Lioness100OP4d ago
:pepeBritish: Up to you of course, but I think it would be a nice change

Did you find this page helpful?