Skip to content

Implement code points validator - #888

Open
tats-u wants to merge 33 commits into
open-circle:mainfrom
tats-u:code-points
Open

Implement code points validator#888
tats-u wants to merge 33 commits into
open-circle:mainfrom
tats-u:code-points

Conversation

@tats-u

@tats-u tats-u commented Oct 20, 2024

Copy link
Copy Markdown
Contributor

Fixes #875

Implemented based on graphemes validation.

Summary by CodeRabbit

  • New Features
    • Added Unicode code point count validators: codePoints, minCodePoints, maxCodePoints, and notCodePoints.
    • Each validator supports custom validation messages and properly handles emoji and other multi-code-point strings.
    • Added public exports for the new validators and _getCodePointCount.
  • Documentation
    • Added API documentation and type references for all new validators and their action/issue types.
  • Tests
    • Added runtime tests and TypeScript declaration tests covering valid/invalid cases, Unicode edge cases, and _getCodePointCount.

@fabian-hiller fabian-hiller self-assigned this Oct 20, 2024
@fabian-hiller fabian-hiller added the enhancement New feature or request label Oct 20, 2024
@fabian-hiller

Copy link
Copy Markdown
Member

Thank you for creating this PR! I will try to review and merge it in the next weeks. 🙏

@tats-u

tats-u commented Oct 22, 2024

Copy link
Copy Markdown
Contributor Author

I might export the implementation of _getCodePointCoun to other validators (e.g. Zod) in the future.

@fabian-hiller

Copy link
Copy Markdown
Member

I just want to let you know that I am focusing on our v1 release first before reviewing this PR.

@tats-u

tats-u commented Oct 28, 2024

Copy link
Copy Markdown
Contributor Author

That's not good news. I'll wait for v1.1.0.
And I want to get permission to publish _getCodePointCount as my independent package from you.
If that function is improved by others, I'll try to get permission from them or keep mine as is.

@fabian-hiller

Copy link
Copy Markdown
Member

Yes, feel free to create your own package. No permission required.

@vercel

vercel Bot commented Apr 29, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
valibot ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 22, 2025 2:30pm

@tats-u

tats-u commented Apr 29, 2025

Copy link
Copy Markdown
Contributor Author

@fabian-hiller rebased to main (no additional changes)

@tats-u

tats-u commented Apr 29, 2025

Copy link
Copy Markdown
Contributor Author

Fix done. Could you allow this PR to run CIs?

@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jun 17, 2025
@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/valibot@888

commit: d4d8c0a

@fabian-hiller

Copy link
Copy Markdown
Member

Sorry for my late reply. 😐 I updated the branch and triggered CI.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 45 out of 45 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

library/src/actions/codePoints/codePoints.ts:125

  • The default issue message is built as Invalid ${label} in _addIssue. Using the label code_points will surface an underscore in user-facing messages ("Invalid code_points"). Consider using a human-readable label like code points (matching the docs/terminology).
          _addIssue(this, 'code_points', dataset, config, {

library/src/utils/_getCodePointCount/_getCodePointCount.ts:17

  • The inline comments are misleading: the last code unit of a JS string can be a lone high surrogate in an ill-formed sequence, and codePointAt(i) can’t be undefined here because the loop bounds keep i in-range. Updating the comments would make the intent clearer without changing behavior.
  // The last code unit of the input cannot be the start of a surrogate pair
  const lengthMinus1 = input.length - 1;
  for (let i = 0; i < lengthMinus1; ) {
    // If codePointAt returned undefined here, we would have already exited the loop
    if (input.codePointAt(i)! <= 65535) {

Comment thread library/src/actions/minCodePoints/minCodePoints.ts Outdated
Comment thread library/src/actions/maxCodePoints/maxCodePoints.ts Outdated
Comment thread library/src/actions/notCodePoints/notCodePoints.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@yslpn

yslpn commented Jul 26, 2026

Copy link
Copy Markdown
Member

Hi @tats-u Thanks for working on this. Let's continue.

  1. The new APIs from the codePoints family haven't been added to website/src/routes/api/menu.md.

  2. Reread my comment again: Implement code points validator #888 (comment) I think this is important to do.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread website/src/routes/api/(actions)/minGraphemes/index.mdx Outdated
Comment thread website/src/routes/api/(actions)/length/index.mdx Outdated
Comment thread website/src/routes/api/(actions)/minLength/index.mdx Outdated
@yslpn

yslpn commented Aug 6, 2026

Copy link
Copy Markdown
Member

@tats-u Hi. Thank you very much. LGTM, I'll send this PR to Fabian for merge.

Please finalize the comments from the AI ​​code review.

UPD:
I will help and make final corrections, you don't need to do anything.

@yslpn
yslpn self-requested a review August 6, 2026 16:46
yslpn
yslpn previously approved these changes Aug 6, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 6, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 8 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/to-json-schema/src/converters/convertAction/convertAction.ts Outdated
Comment thread packages/to-json-schema/src/converters/convertAction/convertAction.ts Outdated
@yslpn yslpn self-assigned this Aug 6, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/to-json-schema/src/converters/convertAction/convertAction.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

maxCodePoints / minCodePoints (UTF-32 code points)

4 participants