forked from elixirscript/elixirscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.js
More file actions
195 lines (149 loc) · 3.06 KB
/
Copy pathstring.js
File metadata and controls
195 lines (149 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import Kernel from './kernel';
import Chars from './string/chars';
function to_atom(string){
return Symbol.for(string);
}
function to_existing_atom(string){
return Symbol.for(string);
}
function to_char_list(string){
return string.split('');
}
function to_float(string){
return parseFloat(string);
}
function to_integer(string, base = 10){
return parseInt(string, base);
}
function upcase(binary){
return binary.toUpperCase();
}
function downcase(binary){
return binary.toLowerCase();
}
function at(string, position){
if(position > (string.length - 1)){
return null;
}
return string[position];
}
function capitalize(string){
let returnString = "";
for(let i = 0; i < string.length; i++){
if(i === 0){
returnString = returnString + string[i].toUpperCase();
}else{
returnString = returnString + string[i].toLowerCase();
}
}
return returnString;
}
function codepoints(string){
return to_char_list(string).map(function(c){
return c.codePointAt(0);
});
}
function contains__qm__(string, contains){
if(Array.isArray(contains)){
return contains.some(function(s){
return string.indexOf(s) > -1;
});
}
return string.indexOf(contains) > -1;
}
function duplicate(subject, n){
return subject.repeat(n);
}
function ends_with__qm__(string, suffixes){
if(Array.isArray(suffixes)){
return suffixes.some(function(s){
return string.endsWith(s);
});
}
return string.endsWith(suffixes);
}
function first(string){
if(!string){
return null;
}
return string[0];
}
function graphemes(string){
return string.split('');
}
function last(string){
if(!string){
return null;
}
return string[string.length - 1];
}
function length(string){
return string.length;
}
function match__qm__(string, regex){
return string.match(regex) != null;
}
function next_codepoint(string){
if(!string || string === ""){
return null;
}
return Kernel.SpecialForms.tuple(string[0].codePointAt(0), string.substr(1));
}
function next_grapheme(string){
if(!string || string === ""){
return null;
}
return Kernel.SpecialForms.tuple(string[0], string.substr(1));
}
function reverse(string){
let returnValue = "";
for (var i = string.length - 1; i >= 0; i--) {
returnValue = returnValue + string[i];
};
return returnValue;
}
function split(string){
return string.split();
}
function starts_with__qm__(string, prefixes){
if(Array.isArray(prefixes)){
return prefixes.some(function(s){
return string.startsWith(s);
});
}
return string.startsWith(prefixes);
}
function valid_character__qm__(codepoint){
try{
return String.fromCodePoint(codepoint) != null;
}catch(e){
return false;
}
}
export default {
at,
capitalize,
codepoints,
contains__qm__,
downcase,
duplicate,
ends_with__qm__,
first,
graphemes,
last,
length,
match__qm__,
next_codepoint,
next_grapheme,
reverse,
split,
starts_with__qm__,
to_atom,
to_char_list,
to_existing_atom,
to_float,
to_integer,
upcase,
valid_character__qm__,
Chars
}