Namespace: chars

core. chars

The core.chars package is a modular JavaScript library that provides extra String methods to validate and transform the basic characters.

You can use this library for example to parse a string (JSON, csv, etc.).

Author:
License:

Members


<constant> lineTerminators :Array

Like white space characters, line terminator characters are used to improve source text readability and to separate tokens (indivisible lexical units) from each other. However, unlike white space characters, line terminators have some influence over the behaviour of the syntactic grammar. In general, line terminators may occur between any two tokens, but there are a few places where they are forbidden by the syntactic grammar. A line terminator cannot occur within any token, not even a string. Line terminators also affect the process of automatic semicolon insertion.

ECMAScript specification.

Type:

<constant> operators :Array

The collection representation of all operators characters.

Type:

<constant> symbols :Array

The collection representation of all ASCII symbols characters.

Type:

<constant> whiteSpaces :Array

This collection contains all white space chars.

Note :

  • http://www.fileformat.info/info/unicode/category/Zs/list.htm
  • http://www.fileformat.info/info/unicode/category/Zl/list.htm
  • http://www.fileformat.info/info/unicode/category/Zp/list.htm
  • http://www.fileformat.info/info/unicode/char/200b/index.htm
  • http://www.fileformat.info/info/unicode/char/feff/index.htm
  • http://www.fileformat.info/info/unicode/char/2060/index.htm
Type:
See:
  • The ECMAScript specification.

Methods


compare(charA, charB)

Compares the two caracteres passed in argument for order.

Parameters:
Name Type Description
charA string

The first char to compare.

charB string

The second char to compare.

Returns:

An integer value :

  • -1 if charA is "lower" than (less than, before, etc.) charB ;
  • 1 if charA is "higher" than (greater than, after, etc.) charB ;
  • 0 if charA and charB are equal.
  • Type
    number
    Example
    trace( compare("a","a") ) ; // 0
    trace( compare("a","b") ) ; // -1
    trace( compare("b","a") ) ; // 1

    isAlpha(c [, index])

    Indicates if the specified character is an alpha (A-Z or a-z) character.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the specified character is an alpha character.

    Type
    boolean

    isAlphaOrDigit(c [, index])

    Indicates if the specified character is an alpha (A-Z or a-z) or a digit character.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the specified character is an alpha or digit character.

    Example
    trace( isAlphaOrDigit( "Z" ) ) ; // true
    trace( isAlphaOrDigit( "a" ) ) ; // true
    trace( isAlphaOrDigit( "0" ) ) ; // true
    trace( isAlphaOrDigit( "9" ) ) ; // true
    trace( isAlphaOrDigit( "+" ) ) ; // false

    isASCII(c [, index])

    Indicates if the specified character is an ASCII character.

    Parameters:
    Name Type Argument Default Description
    c string

    The character expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the specified character is a ASCII character.

    Type
    boolean
    Example
    trace( isASCII( "Z" ) ) ; // true
    trace( isASCII( "a" ) ) ; // true
    trace( isASCII( "+" ) ) ; // true

    isContained(c, index, charset)

    Indicates if the specified character is a digit.

    Parameters:
    Name Type Description
    c string

    The expression to evaluate.

    index number

    The optional index to evaluate a specific character in the passed-in expression.

    charset string

    The list of characters to evaluate.

    Returns:

    True if the specified character is a digit.

    Example
    trace( isContained( "a" , "bubble" ) ) ; // false
    trace( isContained( "u" , "bubble" ) ) ; // true

    isDigit(c [, index])

    Indicates if the specified character is a digit.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    True if the specified character is a digit.

    Type
    boolean
    Example
    trace( isDigit( "Z" ) ) ; // false
    trace( isDigit( "+" ) ) ; // false
    trace( isDigit( "0" ) ) ; // true
    trace( isDigit( "9" ) ) ; // true

    isHexDigit(c [, index])

    Indicates if the specified character is a hexadecimal digit.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    if the specified character is an hexadecimal digit.

    Example
    trace( isHexDigit( "Z" ) ) ; // false
    trace( isHexDigit( "+" ) ) ; // false
    trace( isHexDigit( "0" ) ) ; // true
    trace( isHexDigit( "1" ) ) ; // true
    trace( isHexDigit( "2" ) ) ; // true
    trace( isHexDigit( "9" ) ) ; // true
    trace( isHexDigit( "A" ) ) ; // true
    trace( isHexDigit( "F" ) ) ; // true

    isIdentifierStart(c [, index])

    Indicates if the specified character is a start identifier : UnicodeLetter, $, _ or the \ unicode escape sequence.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    See:
    Returns:

    true if the specified character is an identifier start character.


    isLineTerminator(c [, index])

    Indicates if the specified character is a line terminator :

    • "\n" - u000A - LF : Line Feed
    • "\r" - u000D - CR : Carriage Return
    • ??? - u2028 - LS : Line Separator
    • ??? - u2029 - PS : Paragraphe Separator
    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    See:
    Returns:

    true if the passed-in string value is a line terminator defines in the core.chars.lineTerminators collection.

    Example
    trace( isLineTerminator( "h" ) ) ; // false
    trace( isLineTerminator( "\n" ) ) ; // true

    isLower(c [, index])

    Indicates if the character is lowercase.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the specified character is lowercase.

    Example
    trace( isLower( "a" ) ) ; // true
    trace( isLower( "A" ) ) ; // false
    trace( isLower( "-" ) ) ; // false
    trace( isLower( "#" ) ) ; // false
    trace( isLower( "1" ) ) ; // false

    isOctalDigit(c [, index])

    Indicates if the specified character is an octal digit. The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the specified character is an octal digit.

    Example
    var chars =
    [
        "0" , "1" , "2" , "3" , "4" ,
        "5" , "6" , "7" , "8" , "A" , "a" , "$"
    ] ;
    for( var i = 0 ; i<chars.length ; i++ )
    {
        trace( chars[i] + " isOctalDigit " + isOctalDigit( chars[i] ) ) ;
    }

    isOperator(c [, index])

    Indicates if the passed-in string value is a operator digit.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the passed-in string value is a operator digit.

    Example
    trace( isOperator( "a" ) ) ; // false
    trace( isOperator( "+" ) ) ; // true

    isSymbol(c [, index])

    Indicates if the character is an ASCII symbol.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the passed-in string value is a symbol defines in the core.chars.symbols collection.


    isUnicode(c [, index])

    Indicates if the specified character is a unicode character (the charcode of the character must be > 255).

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the passed-in string value is a unicode character.


    isUpper(c [, index])

    Indicates if the character is an uppercase letter.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the specified character is lowercase. trace( isUpper( "A" ) ) ; // true trace( isUpper( "B" ) ) ; // true trace( isUpper( "Z" ) ) ; // true trace( isUpper( "a" ) ) ; // false trace( isUpper( "b" ) ) ; // false trace( isUpper( "-" ) ) ; // false trace( isUpper( "#" ) ) ; // false trace( isUpper( "1" ) ) ; // false


    isWhiteSpace(c [, index])

    Indicates if the character is white space.

    Parameters:
    Name Type Argument Default Description
    c string

    The expression to evaluate.

    index number <optional>
    0

    The optional index to evaluate a specific character in the passed-in expression.

    Returns:

    true if the passed-in string value is a white space defines in the core.chars.whiteSpaces collection.

    Example
    trace( isWhiteSpace( '!' ) ) ;
    trace( isWhiteSpace( ' ' ) ) ;
    trace( isWhiteSpace( '\r' ) ) ;