Skip to content

Commit 2d98dd6

Browse files
committed
Add is_* functions
1 parent 626602f commit 2d98dd6

File tree

1 file changed

+71
-0
lines changed
  • src/javascript/lib/core/erlang_compat

1 file changed

+71
-0
lines changed

src/javascript/lib/core/erlang_compat/erlang.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// http://erlang.org/doc/man/erlang.html
2+
import ErlangTypes from 'erlang-types';
23

34
function atom_to_binary(atom, encoding = Symbol.for('utf8')) {
45
if (encoding !== Symbol.for('utf8')) {
@@ -122,6 +123,62 @@ function bxor(left, right) {
122123
return left ^ right;
123124
}
124125

126+
function is_atom(value) {
127+
return value instanceof Symbol || value.__MODULE__ === true;
128+
}
129+
130+
function is_bitstring(value) {
131+
return value instanceof ErlangTypes.BitString;
132+
}
133+
134+
function is_boolean(value) {
135+
return value instanceof Boolean;
136+
}
137+
138+
function is_float(value) {
139+
return value instanceof Number && !Number.isInteger(value);
140+
}
141+
142+
function is_function(value) {
143+
return value instanceof Function;
144+
}
145+
146+
function is_integer(value) {
147+
return Number.isInteger(value);
148+
}
149+
150+
function is_list(value) {
151+
return Array.isArray(value);
152+
}
153+
154+
function is_map(value) {
155+
return value instanceof Object;
156+
}
157+
158+
function is_number(value) {
159+
return value instanceof Number;
160+
}
161+
162+
function is_pid(value) {
163+
return value instanceof ErlangTypes.PID;
164+
}
165+
166+
function is_port() {
167+
return false;
168+
}
169+
170+
function is_reference(value) {
171+
return value instanceof ErlangTypes.Reference;
172+
}
173+
174+
function is_tuple(value) {
175+
return value instanceof ErlangTypes.Tuple;
176+
}
177+
178+
function is_binary(value) {
179+
return value instanceof String;
180+
}
181+
125182
export default {
126183
atom_to_binary,
127184
list_concatenation,
@@ -148,4 +205,18 @@ export default {
148205
bsr,
149206
bxor,
150207
bnot,
208+
is_bitstring,
209+
is_boolean,
210+
is_float,
211+
is_function,
212+
is_integer,
213+
is_list,
214+
is_map,
215+
is_number,
216+
is_pid,
217+
is_port,
218+
is_reference,
219+
is_tuple,
220+
is_atom,
221+
is_binary,
151222
};

0 commit comments

Comments
 (0)