-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathjs.ex
More file actions
94 lines (76 loc) · 1.91 KB
/
js.ex
File metadata and controls
94 lines (76 loc) · 1.91 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
defmodule ElixirScript.JS do
@moduledoc """
This module defines macros and functions which implement
JavaScript functionality that may not translate easily to
Elixir. For instance, creating a new object
"""
use ElixirScript.FFI, global: true
@doc """
Creates new JavaScript objects.
```elixir
ElixirScript.JS.new User, ["first_name", "last_name"]
```
"""
defexternal new(module, params)
@doc """
Returns the type of the given value
"""
defexternal typeof(value)
@doc """
Determines if value is an instance of type.
"""
defexternal instanceof(value, type)
@doc """
Throws the term given
"""
defexternal throw(term)
@doc """
Creates a breakpoint for JavaScript debuggers to stop at
"""
defexternal debugger()
@doc """
The current JavaScript context
"""
defexternal this()
@doc """
Mutates an existing JavaScript object.
```elixir
ElixirScript.JS.mutate elem, "width", 100
```
"""
defexternal mutate(object, key, value)
@doc """
Takes the given map and returns an object
Throws an error if any key is not a
number, binary, or atom
```elixir
ElixirScript.JS.map_to_object(%{my: "map"})
```
"""
defexternal map_to_object(map)
@doc """
Takes the given map and returns an object
Throws an error if any key is not a
number, binary, or atom
```elixir
ElixirScript.JS.map_to_object(%{my: "map"}, keys: :string)
```
"""
defexternal map_to_object(map, options)
@doc """
Takes the given object and returns a map
Options include [{:keys, :atom}, {:recurse_array, true}]
```elixir
ElixirScript.JS.object_to_object({my: "object"})
```
"""
defexternal object_to_map(object)
@doc """
Takes the given object and returns a map
Options include [{:keys, :atom}, {:recurse_array, true}]
```elixir
ElixirScript.JS.object_to_object({my: "map"}, keys: :atom)
```
"""
defexternal object_to_map(object, options)
end