src/Kit.js
function parseCharset(charset /*:String*/) {
  charset=charset.split('');
  var chars=[],ranges=[],
      exclude = charset[0]==='^' && charset.length > 1 && charset.shift();
  charset.forEach(function (c) {
    if (chars[0]=='-' && chars.length>1) {//chars=['-','a'],c=='z'
      if (chars[1] > c ) // z-a  is invalid
        throw new Error('Charset range out of order:'+chars[1]+'-'+c+'!');
      ranges.push(chars[1]+c);
      chars.splice(0,2);
    } else chars.unshift(c);
  });
  ranges=ranges.concat(chars);
  //convert exclude to include
  return exclude?negate(ranges):classify(ranges).ranges;
}
function parseCharset(charset /*:String*/) {
  charset=charset.split('');
  var chars=[],ranges=[],
      exclude = charset[0]==='^' && charset.length > 1 && charset.shift();
  charset.forEach(function (c) {
    if (chars[0]=='-' && chars.length>1) {//chars=['-','a'],c=='z'
      if (chars[1] > c ) // z-a  is invalid
        throw new Error('Charset range out of order:'+chars[1]+'-'+c+'!');
      ranges.push(chars[1]+c);
      chars.splice(0,2);
    } else chars.unshift(c);
  });
  ranges=ranges.concat(chars);
  //convert exclude to include
  return exclude?negate(ranges):classify(ranges).ranges;
}
function parseCharset ( charset /*:String*/ ) { charset = charset . split ( '' ) ; var chars = [ ] , ranges = [ ] , exclude = charset [ 0 ] === '^' && charset . length > 1 && charset . shift ( ) ; charset . forEach ( function ( c ) { if ( chars [ 0 ] == '-' && chars . length > 1 ) { //chars=['-','a'],c=='z' if ( chars [ 1 ] > c ) // z-a  is invalid throw new Error ( 'Charset range out of order:' + chars [ 1 ] + '-' + c + '!' ) ; ranges . push ( chars [ 1 ] + c ) ; chars . splice ( 0 , 2 ) ; } else chars . unshift ( c ) ; } ) ; ranges = ranges . concat ( chars ) ; //convert exclude to include return exclude ? negate ( ranges ) : classify ( ranges ) . ranges ; }
Parse simple regex style charset string like '^a-bcdf' to disjoint ranges.
Character classes like "\w\s" are not supported!
@param {String} charset  Valid regex charset [^a-z0-9_] input as "^a-z0-9_".
@return {[Range]} return sorted disjoint ranges
Parse simple regex style charset string like ^a - bcdf to disjoint ranges . Character classes like \ w \ s are not supported!