Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for String normalization #691

Closed
N0tExisting opened this issue Jun 30, 2024 · 2 comments
Closed

Support for String normalization #691

N0tExisting opened this issue Jun 30, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request workaround Workaround fixes problem

Comments

@N0tExisting
Copy link

N0tExisting commented Jun 30, 2024

It would be nice if there was built-in support for String.prototype.normalize as a built in transformer.

This would be usefull to avoid weird issues with strings:

const name1 = '\u0041\u006d\u00e9\u006c\u0069\u0065';
const name2 = '\u0041\u006d\u0065\u0301\u006c\u0069\u0065';

console.log(`${name1}, ${name2}`); // "Amélie, Amélie"
console.log(name1 === name2); // false
console.log(name1.length === name2.length); // false

const name1NFC = name1.normalize('NFC');
const name2NFC = name2.normalize('NFC');

console.log(`${name1NFC}, ${name2NFC}`); // "Amélie, Amélie"
console.log(name1NFC === name2NFC); // true
console.log(name1NFC.length === name2NFC.length); // true

For options and more detail see the MDN documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize

@fabian-hiller fabian-hiller self-assigned this Jul 1, 2024
@fabian-hiller fabian-hiller added the enhancement New feature or request label Jul 1, 2024
@fabian-hiller
Copy link
Owner

Great idea! I plan to add this in our next release. Until then, you can use transform:

import * form 'valibot';

const Schema = v.pipe(
  v.string(),
  v.transform((input) => input.normalize('NFC'))
);

@fabian-hiller fabian-hiller added the workaround Workaround fixes problem label Jul 1, 2024
@fabian-hiller
Copy link
Owner

v0.36.0 is available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request workaround Workaround fixes problem
Projects
None yet
Development

No branches or pull requests

2 participants