chars.js
All about single ascii characters. Experimental and under development, will evolve over time.
I use Chars mainly as a document for static character related data and methods. Parts of it can be found in my
other libraries, like strings.js for example.
You can use npm install chars.js
if you're on node.js.
API
ASCII_RANGE is an array with two indices: [bottomOfRange, topOfRange]. These ranges are directly related
to the ordinal values from the ascii-table.
Chars.ASCII_RANGE_UPPERCASE
Chars.ASCII_RANGE_LOWERCASE
Chars.ASCII_RANGE_NUMBERS
Chars.ASCII_RANGE_SPECIAL_1
Chars.ASCII_RANGE_SPECIAL_2
Chars.ASCII_RANGE_SPECIAL_3
Chars.ASCII_RANGE_SPECIAL_4
Chars.ASCII_RANGE_ALL
Chars.REGEXP_SPECIAL_CHARS
<array> REGEXP_SPECIAL_CHARS
Returns an array (like a set) with all special characters used in regular expressions.
I use this for one of my other libraries, strings.js, for escaping a string to prepare for making a new RegExp.
Chars.ascii
<string> Chars.ascii( <string>/<number> ordinal )
Returns the ascii character found at ordinal.
var space= Chars.ascii( 32 );
Chars.ordinal
<number> Chars.ordinal( <string>/<number> char )
Returns the ordinal for char.
var ordSpace= Chars.ordinal( ' ' );
Chars.isUpper
<boolean> Chars.isUpper( <string>/<number> char )
Returns true if char is uppercase.
var test= Chars.isUpper( 'z' );
Chars.isLower
<boolean> Chars.isLower( <string>/<number> char )
Returns true if char is lowercase.
var test= Chars.isLower( 'z' );
Chars.isAlpha
<boolean> Chars.isAlpha( <string>/<number> char )
Returns true if char is uppercase or lowercase alpha.
var test= Chars.isAlpha( 'a' );
Chars.isNumeric
<boolean> Chars.isNumeric( <string>/<number> char )
Returns true if char is a number.
var test= Chars.isNumeric( '0' );
var test= Chars.isNumeric( 0 );
Chars.isSpecial
<boolean> Chars.isSpecial( <string>/<number> char )
Returns true if char is a special character from the SPECIAL_1,2,3 or 4 range.
var test= Chars.isSpecial( '.' );
Chars.isAlphaNumeric
<boolean> Chars.isAlphaNumeric( <string>/<number> char )
Returns true if char is a uppercase, lowercase or number.
var test= Chars.isAlphaNumeric( 'A' );
var test= Chars.isAlphaNumeric( 1 );
Chars.random
<string> Chars.random( range )
Returns a random character in range range. range defaults to the Chars.ASCII_RANGE_ALL range
var test= Chars.random( Chars.ASCII_RANGE_UPPERCASE );
Chars.prototype.constructor
<this> constructor( <string>/<number> char, <array> range )
char can be a number character or ordinal, range has the format of ASCII_RANGE
var char= new Chars( '?' );
Chars.prototype.get
<string> get()
Returns this.char
console.log( char.get() );
Chars.prototype.set
<string> set( <string>/<number> char )
char can be a number character or ordinal. If char is an ordinal, the character represented by ordinal will be set.
console.log( char.set('!') );
Chars.prototype.next
<string> next( <string>/<number> amount )
Proceed this.char to the following ascii character and returns it, if no arguments are given. Proceed to amount ascii characters
ahead, limited by this.range, if amount is set.
console.log( char.next() );
Chars.prototype.prev
<this> prev( <string>/<number> amount )
Sets and returns this.char to the predecessor of the current ascii character in the ascii-table, if no arguments
are given. If amount is given, it will decrease and set to the amount characters back in the ascii table.
prev is limited to the current active range. So, casting a prev on the bounds of the range will keep returning
this bound.
console.log( char.prev() );
Chars.prototype.isUpper
<boolean> isUpper()
Chars.prototype.isLower
<boolean> isLower()
Chars.prototype.isAlpha
<boolean> isAlpha()
Chars.prototype.isNumeric
<boolean> isNumeric()
Chars.prototype.isSpecial
<boolean> isSpecial()
Chars.prototype.isAlphaNumeric
<boolean> isAlphaNumeric()
Chars.prototype.random
<string> random()