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

[request] string().replace(pattern) #586

Closed
AdriVanHoudt opened this issue Mar 5, 2015 · 8 comments
Closed

[request] string().replace(pattern) #586

AdriVanHoudt opened this issue Mar 5, 2015 · 8 comments
Labels
feature New functionality or improvement
Milestone

Comments

@AdriVanHoudt
Copy link
Contributor

This works like you would expect.

 Joi.string().replace(/\*/g, '%')

Would replace all * with %.

This use case is for converting default wildcards to wildcards from sql but can be used for many things.

@Marsup Marsup added the request label Mar 5, 2015
@Marsup Marsup self-assigned this Mar 5, 2015
@DavidTPate
Copy link
Contributor

I wonder if this would be approached better by adding functionality with something like:

Joi.string().transform(function(value) {
  return value.replace(/\*/g, '%');
});

I could see Any.transform([function]) being pretty useful and handling lots of cases.

@AdriVanHoudt
Copy link
Contributor Author

I agree, making it more general makes it more usable.
Although a basic replace function is quicker/easier than implementing the function every time. (insert link to custom Joi rules/types here :D)
Also maybe call it transform like date? (not sure about this)

@DavidTPate
Copy link
Contributor

Yeah, I could definitely see that. replace on String might just be a predefined use of transform.

@AdriVanHoudt
Copy link
Contributor Author

Yeah internally it can call a general transform function
Also referencing #577 for cutom joi rules

@pfumagalli
Copy link
Contributor

I have a patch for replace(pattern, replacement) in #649.

@satazor
Copy link

satazor commented May 20, 2015

+1

1 similar comment
@zebateira
Copy link
Contributor

👍

@Marsup Marsup added this to the 6.5.0 milestone Jun 6, 2015
@Marsup Marsup closed this as completed Jun 6, 2015
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

7 participants