![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
string-mask
Advanced tools
A string formatter and validator based on masks.
With npm:
npm install --save string-mask
With bower:
bower install --save string-mask
Character | Description |
---|---|
0 | Any numbers |
9 | Any numbers (Optional) |
# | Any numbers (recursive) |
A | Any alphanumeric character |
a | Any alphanumeric character (Optional) Not implemented yet |
S | Any letter |
U | Any letter (All lower case character will be mapped to uppercase) |
L | Any letter (All upper case character will be mapped to lowercase) |
$ | Escape character, used to escape any of the special formatting characters. |
Optional characters: Used to parse characters that cold exist in the source string or not. See Date and time.
Recursive characters: Used to parse patterns that repeat in the end or in the start of the source string. See Two decimal number with thousands separators
Note: Any character of the mask positioned after a recursive character will be handled as a non special character.
Use it creating an mask instance with the StringMask contructor:
/**
* - optionsObject parameter is optional in the constructor
* - apply will return the a masked string value
* - validate will return `true` if the string matchs the mask
*/
var mask = new StringMask('some mask', optionsObject); //optionsObject is optional
var maskedValue = mask.apply('some value string');
var isValid = mask.validate('some value string to validate');
Or by the static interface:
/**
* - optionsObject parameter is optional in all methods
* - apply will return the a masked string value
* - validate will return `true` if the string matchs the mask
* - process will return a object: {result: <maskedValue>, valid: <isValid>}
*/
var maskedValue = StringMask.apply('some value string', 'some mask', optionsObject);
var isValid = StringMask.validate('some value string', 'some mask', optionsObject);
var result = StringMask.process('some value string', 'some mask', optionsObject);
var formatter = new StringMask('#0');
var result = formatter.apply('123'); // 123
var formatter = new StringMask('#.##0,00', {reverse: true});
var result = formatter.apply('100123456'); // 1.001.234,56
result = formatter.apply('6'); // 0,06
var formatter = new StringMask('+00 (00) 0000-0000');
var result = formatter.apply('553122222222'); // +55 (31) 2222-2222
var formatter = new StringMask('#0,00%');
var result = formatter.apply('001'); // 0,01%
var formatter = new StringMask('000.000.000-00');
var result = formatter.apply('12965815620'); // 129.658.156-20
var formatter = new StringMask('90/90/9900');
var result = formatter.apply('1187'); // 1/1/87
var formatter = new StringMask('UUUUUUUUUUUUU');
var result = formatter.apply('To Upper Case'); // TO UPPER CASE
var formatter = new StringMask('LLLLLLLLLLLLL');
var result = formatter.apply('To Lower Case'); // to lower case
var formatter = new StringMask('UUAA AAAA AAAA AAAA AAAA AAAA AAA');
var result = formatter.apply('FR761111900069410000AA33222');
// result: FR76 1111 BBBB 6941 0000 AA33 222
We'd love for you to contribute to our source code! We just ask to:
$ gulp pre-push
)$gulp pre-push
taskCopyright (c) 2016 Daniel Campos
Licensed under the MIT license.
FAQs
A string formatter and validator based on masks
We found that string-mask demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.