Skip to content

feat: add stringy number zod schema - #16

Open
Patai5 wants to merge 2 commits into
feat/add-zod-partial-safe-parsefrom
feat/add-stringy-number-zod-schema
Open

feat: add stringy number zod schema#16
Patai5 wants to merge 2 commits into
feat/add-zod-partial-safe-parsefrom
feat/add-stringy-number-zod-schema

Conversation

@Patai5

@Patai5 Patai5 commented Sep 11, 2026

Copy link
Copy Markdown

useful for parsing stringy numbers - "123"

@Patai5
Patai5 added this pull request to stack #17 September 11, 2026 13:55
Comment thread src/zod/stringy-number-schema.ts Outdated
* This validates the string is a plain non-negative integer and converts it to a `number`.
* - Also rejects values that would lose precision past `Number.MAX_SAFE_INTEGER`
*/
export const StringyNumberSchema = z

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe worth renaming to StringyIntegerSchema

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

21d0319

Comment thread src/zod/stringy-number-schema.ts Outdated
ctx.addIssue({
code: 'custom',
message:
`Invalid input: stringy number "${value}" exceeds Number.MAX_SAFE_INTEGER and would lose precision` +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you ever encounter this in the wild?????

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but in the opposite way, where this error prevents bugs - TikTok uses really long stringy numbers as IDs, so you can get 123456789123456789123456789123456789 as an ID, and you want to keep that as a string to not corrupt your data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants