Skip to content

Instantly share code, notes, and snippets.

@padolsey
Created June 17, 2012 15:33
Show Gist options
  • Save padolsey/2944861 to your computer and use it in GitHub Desktop.
Save padolsey/2944861 to your computer and use it in GitHub Desktop.
var ALPHA = 'abcdefghijklmnopqrstuvwxyz',
ALPHA_UPPER = ALPHA.toUpperCase(),
NUMERIC = '0123456789',
PUNCTUATION = '-!@£$%^&*()[]{}\'"/?.>,<;:\\|~`€#',
UNDERSCORE = '_',
WHITESPACE = '\x20\t\n\r\f\v\xa0\u2028\u2029\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff'; // thanks Mathias!
var SHORTHAND_CC = {
'\\S': ALPHA + ALPHA_UPPER + NUMERIC + PUNCTUATION + UNDERSCORE,
'\\s': WHITESPACE,
'\\W': NUMERIC + PUNCTUATION + UNDERSCORE,
'\\w': ALPHA + ALPHA_UPPER + NUMERIC + '_',
'\\d': NUMERIC,
'\\D': ALPHA + ALPHA_UPPER + PUNCTUATION + UNDERSCORE + WHITESPACE
};
@mathiasbynens
Copy link

I like where this is going!


FWIW, WHITESPACE is [\x20\t\n\r\f\v\xa0\u2028\u2029\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff] as per ES 5.1.

http://es5.github.com/x15.10.html#x15.10.2.12:

The production CharacterClassEscape :: s evaluates by returning the set of characters containing the characters that are on the right-hand side of the WhiteSpace (7.2) or LineTerminator (7.3) productions.

http://es5.github.com/x7.html#x7.2:

ECMAScript implementations must recognize all of the white space characters defined in Unicode 3.0. Later editions of the Unicode Standard may define other white space characters. ECMAScript implementations may recognize white space characters from later editions of the Unicode Standard.

@padolsey
Copy link
Author

@mathiasbynens, I wasn't sure where to find that, so thank you! I think my PUNCTUATION is missing a bunch too, but I think it's enough for basic generations.

@mathiasbynens
Copy link

This project moved here: https://github.com/padolsey/rGen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment