npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@united-code/string-mask

v1.0.1

Published

[![npm version](https://badge.fury.io/js/string-mask.svg)](http://badge.fury.io/js/string-mask) [![Bower version](https://badge.fury.io/bo/string-mask.svg)](http://badge.fury.io/bo/string-mask) [![Build Status](https://travis-ci.org/the-darc/string-mask.s

Downloads

17

Readme

#string-mask npm version Bower version Build Status Coverage Status

A string formatter and validator based on masks.

Why the fork?

The package seems stalled and there is one unpublished typescript fork. Because i need this in a ci/cd environment i decided to publish it myself. Currently all credits go to: https://github.com/the-darc/string-mask (original creator) and https://github.com/js-system/string-mask for a typescript fork.

INSTALLATION

With npm:

npm install --save @united-code/string-mask

With bower:

bower install --save @united-code/string-mask

SPECIAL MASK CHARACTERS

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.

Special characters types

Note: Any character of the mask positioned after a recursive character will be handled as a non special character.

USAGE

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);

Some masks examples

Number

	var formatter = new StringMask('#0');
	var result = formatter.apply('123'); // 123

Two decimal number with thousands separators

	var formatter = new StringMask('#.##0,00', {reverse: true});
	var result = formatter.apply('100123456'); // 1.001.234,56
	result = formatter.apply('6'); // 0,06

Phone number

	var formatter = new StringMask('+00 (00) 0000-0000');
	var result = formatter.apply('553122222222'); // +55 (31) 2222-2222

Percentage

	var formatter = new StringMask('#0,00%');
	var result = formatter.apply('001'); // 0,01%

Brazilian CPF number

	var formatter = new StringMask('000.000.000-00');
	var result = formatter.apply('12965815620'); // 129.658.156-20

Date and time

	var formatter = new StringMask('90/90/9900');
	var result = formatter.apply('1187'); // 1/1/87

Convert Case

	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

International Bank Number

	var formatter = new StringMask('UUAA AAAA AAAA AAAA AAAA AAAA AAA');
	var result = formatter.apply('FR761111900069410000AA33222');
	// result: FR76 1111 BBBB 6941 0000 AA33 222

CONTRIBUTING

We'd love for you to contribute to our source code! We just ask to:

  • Write tests for the new feature or bug fix that you are solving
  • Ensure all tests pass before send the pull-request (Use: $ gulp pre-push)
  • Use commit messages following the commit conventions of angular.js Git Commit Guidelines
  • Pull requests will not be merged if:
    • has not unit tests
    • reduce the code coverage
    • not passing in the $gulp pre-push task

LICENSE

Copyright (c) 2016 Daniel Campos

Licensed under the MIT license.