Namespace: String

SuperMap.String

A series of commonly used extended functions for the string.

Members

SuperMap.String.numberRegExRegExp

Determine whether the string contains only one value. It's default: numberRegEx=/^([+-]?)(?=\d|.\d)\d(.\d)?(Ee)?$/.

SuperMap.String.tokenRegExRegExp

Used to find tokens in a string. It's default: tokenRegEx=/\${([\w.]+?)}/g.

Example
Examples: ${a}, ${a.b.c}, ${a-b}, ${5}

Methods

SuperMap.String.camelize(str){string}

BaseTypes.js, line 116

The string processing of hump type ("-") hyphen For instance: "chicken-head" becomes "chickenHead", "-chicken-head" becomes "ChickenHead".

Name Type Description
str string

The string to be processed,the original content shouldn't be modified.

Returns:
Type Description
string

SuperMap.String.contains(str, sub){boolean}

BaseTypes.js, line 95

Determine whether the target string contain the specified substring.

Name Type Description
str string

The target string.

sub string

The substring to lookup.

Returns:
Type Description
boolean Return to true when the target string contain the specified substring, otherwise, return to false.

SuperMap.String.format(template, context, args){string}

BaseTypes.js, line 134

Provide a string with the ${token} tag, Returns the attribute value of the specified tag in the context object property.

Name Type Default Description
template string

The tagged string will be replaced. Format of the template parameter is "${token}", This token tag will be replaced with the the value of the context["token"] attribute.

context Object window optional

The attribute of the optional object is used to match the markup in the formatted string.

args Array optional

The optional parameters pass to the function that found on the context object.

Returns:
Type Description
string The string that replaced from the marker location on the context object property.
Example
For instance:
(code)
1、template = "${value,getValue}";
        context = {value: {getValue:function(){return Math.max.apply(null,argument);}}};
        args = [2,23,12,36,21];
      return:36
(end)
For instance:
(code)
2、template = "$${{value,getValue}}";
        context = {value: {getValue:function(){return Math.max.apply(null,argument);}}};
        args = [2,23,12,36,21];
      return:"${36}"
(end)
For instance:
(code)
3、template = "${a,b}";
        context = {a: {b:"format"}};
        args = null;
      return:"format"
(end)
For instance:
(code)
3、template = "${a,b}";
        context = null;
        args = null;
      return:"${a.b}"
(end)

SuperMap.String.isNumeric(){boolean}

BaseTypes.js, line 229

Determine whether the string contains only one value.

Returns:
Type Description
boolean Retrun to true when the string contains only one value, otherwise, return to false.
Example
(code)
SuperMap.String.isNumeric("6.02e23") // true
SuperMap.String.isNumeric("12 dozen") // false
SuperMap.String.isNumeric("4") // true
SuperMap.String.isNumeric(" 4 ") // false
(end)

SuperMap.String.numericIf(){number|string}

BaseTypes.js, line 245

Transform a seemingly numeric string to a numeric.

Returns:
Type Description
number | string Returns the numeric value if it can be turned to a numeric value, otherwise the string itself is returned.

SuperMap.String.startsWith(str, sub){boolean}

BaseTypes.js, line 84

Determine whether the target string begins with the specified substring.

Name Type Description
str string

The target string.

sub string

The substring to lookup.

Returns:
Type Description
boolean Return to true when the target string begins with the specified substring, otherwise, return to false.

SuperMap.String.trim(str){string}

BaseTypes.js, line 106

Delete all the blank characters at the beginning and end of a string.

Name Type Description
str string

(possibly) A string that has a blank character filling.

Returns:
Type Description
string The string that after deleted the blank characters at the beginning and end of this string.