1 | .. _api-zoo-string: |
---|
2 | |
---|
3 | ZOO.String |
---|
4 | ========== |
---|
5 | |
---|
6 | Contains convenience methods for string manipulation: |
---|
7 | |
---|
8 | Functions and Properties |
---|
9 | ------------------------ |
---|
10 | |
---|
11 | .. list-table:: |
---|
12 | :widths: 30 50 |
---|
13 | :header-rows: 1 |
---|
14 | |
---|
15 | * - NAME |
---|
16 | - DESCRIPTION |
---|
17 | * - :ref:`startsWith <startsWith>` |
---|
18 | - Test whether a string starts with another string. |
---|
19 | * - :ref:`contains <contains>` |
---|
20 | - Test whether a string contains another string. |
---|
21 | * - :ref:`trim <trim>` |
---|
22 | - Removes leading and trailing whitespace characters from a string. |
---|
23 | * - :ref:`camelize <camelize>` |
---|
24 | - Camel-case a hyphenated string. |
---|
25 | * - :ref:`tokenRegEx <tokenRegEx>` |
---|
26 | - Used to find tokens in a string. |
---|
27 | * - :ref:`numberRegEx <numberRegEx>` |
---|
28 | - Used to test strings as numbers. |
---|
29 | * - :ref:`isNumeric <isNumeric>` |
---|
30 | - Determine whether a string contains only a numeric value. |
---|
31 | * - :ref:`numericIf <numericIf>` |
---|
32 | - Converts a string that appears to be a numeric value into a number. |
---|
33 | |
---|
34 | .. _startsWith: |
---|
35 | |
---|
36 | startsWith |
---|
37 | :: |
---|
38 | |
---|
39 | startsWith: function(str,sub) |
---|
40 | |
---|
41 | Test whether a string starts with another string. |
---|
42 | |
---|
43 | *Parameters* |
---|
44 | |
---|
45 | | ``str {String}`` The string to test. |
---|
46 | | ``sub {Sring}`` The substring to look for. |
---|
47 | |
---|
48 | *Returns* |
---|
49 | |
---|
50 | ``{Boolean}`` The first string starts with the second. |
---|
51 | |
---|
52 | .. _contains: |
---|
53 | |
---|
54 | contains |
---|
55 | :: |
---|
56 | |
---|
57 | contains: function(str,sub) |
---|
58 | |
---|
59 | Test whether a string contains another string. |
---|
60 | |
---|
61 | *Parameters* |
---|
62 | |
---|
63 | | ``str {String}`` The string to test. |
---|
64 | | ``sub {String}`` The substring to look for. |
---|
65 | |
---|
66 | *Returns* |
---|
67 | |
---|
68 | ``{Boolean}`` The first string contains the second. |
---|
69 | |
---|
70 | .. _trim: |
---|
71 | |
---|
72 | trim |
---|
73 | :: |
---|
74 | |
---|
75 | trim: function(str) |
---|
76 | |
---|
77 | Removes leading and trailing whitespace characters from a string. |
---|
78 | |
---|
79 | *Parameters* |
---|
80 | |
---|
81 | ``str {String}`` The (potentially) space-padded string. This string is not modified. |
---|
82 | |
---|
83 | *Returns* |
---|
84 | |
---|
85 | ``{String}`` A trimmed version of the string with all leading and trailing spaces removed. |
---|
86 | |
---|
87 | .. _camelize: |
---|
88 | |
---|
89 | camelize |
---|
90 | :: |
---|
91 | |
---|
92 | camelize: function(str) |
---|
93 | |
---|
94 | Camel-case a hyphenated string. Ex. "chicken-head" becomes "chickenHead", and "-chicken-head" becomes "ChickenHead". |
---|
95 | |
---|
96 | *Parameters* |
---|
97 | |
---|
98 | ``str {String}`` The string to be camelized. The original is not modified. |
---|
99 | |
---|
100 | *Returns* |
---|
101 | |
---|
102 | ``{String}`` The string, camelized |
---|
103 | |
---|
104 | .. _tokenRegEx: |
---|
105 | |
---|
106 | tokenRegEx |
---|
107 | Used to find tokens in a string. Examples: *${a}, ${a.b.c}, ${a-b}, ${5}* |
---|
108 | |
---|
109 | .. _numberRegEx: |
---|
110 | |
---|
111 | numberRegEx |
---|
112 | Used to test strings as numbers. |
---|
113 | |
---|
114 | .. _isNumeric: |
---|
115 | |
---|
116 | isNumeric |
---|
117 | :: |
---|
118 | |
---|
119 | isNumeric: function(value) |
---|
120 | |
---|
121 | Determine whether a string contains only a numeric value. |
---|
122 | |
---|
123 | *Examples* |
---|
124 | |
---|
125 | :: |
---|
126 | |
---|
127 | ZOO.String.isNumeric("6.02e23") // true |
---|
128 | ZOO.String.isNumeric("12 dozen") // false |
---|
129 | ZOO.String.isNumeric("4") // true |
---|
130 | ZOO.String.isNumeric(" 4 ") // false |
---|
131 | |
---|
132 | *Returns* |
---|
133 | |
---|
134 | ``{Boolean}`` String contains only a number. |
---|
135 | |
---|
136 | .. _numericIf: |
---|
137 | |
---|
138 | numericIf |
---|
139 | :: |
---|
140 | |
---|
141 | numericIf: function(value) |
---|
142 | |
---|
143 | Converts a string that appears to be a numeric value into a number. |
---|
144 | |
---|
145 | *Returns* |
---|
146 | |
---|
147 | ``{Number|String}`` a Number if the passed value is a number, a String otherwise. |
---|