This content originally appeared on DEV Community and was authored by Wonjang Son
??-?????-??? ?
Hi, I've just opened a public space to build up a useful collection of helper functions for ordinary and concurrent daily problems.
I'm a freelance Software Engineer, my stack is Javascript & React. After some time working on different projects, I found myself facing the same problems and solving them with the same pattern. This is a repository for saving valuable time and stay as DRY as possible while working.
This open-source has his goal on stay as ??? (Don't Repeat Yourself) as possible.
Example
How many times do I have to write a function to mask/format a mobile phone number input????
This is how I implemented:
// Parameter> $inputValue: string
// Output> "xxx-xxxx-xxxx"
export const phoneMask = (inputValue = "") =>
inputValue
.replace(/\D/g, "")
.replace(/(\d{1,3})(\d{1,4})?(\d{1,4})?/g, function (_, a, b, c) {
return c ? `${a}-${b}-${c}` : b ? `${a}-${b}` : `${a}`;
});
SAME CODE to solve the SAME PROBLEMS?
Contribute your grain of code?
This content originally appeared on DEV Community and was authored by Wonjang Son
Wonjang Son | Sciencx (2021-06-11T09:39:11+00:00) ??-?????-??? ?. Retrieved from https://www.scien.cx/2021/06/11/%f0%9f%85%b9%f0%9f%86%82-%f0%9f%86%81%f0%9f%85%b4%f0%9f%85%b0%f0%9f%85%b2%f0%9f%86%83-%f0%9f%85%b3%f0%9f%86%81%f0%9f%86%88-%f0%9f%8e%89/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
