godprotocol 1.1.32 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Datatypes/arr.js +559 -254
- package/Datatypes/bool.js +8 -5
- package/Datatypes/callable.js +1 -1
- package/Datatypes/cls.js +193 -24
- package/Datatypes/conf.js +2 -2
- package/Datatypes/err.js +25 -0
- package/Datatypes/func.js +89 -13
- package/Datatypes/functions/storage.js +572 -12
- package/Datatypes/functions/wallet.js +49 -0
- package/Datatypes/instance.js +87 -122
- package/Datatypes/num.js +192 -153
- package/Datatypes/str.js +188 -122
- package/Datatypes/twa.js +346 -71
- package/Datatypes/voi.js +9 -4
- package/Index.js +1 -1
- package/Instances/account.js +0 -0
- package/Instances/event.js +0 -0
- package/Instances/fold.js +103 -0
- package/Instances/folder_queries.js +46 -0
- package/Instances/response.js +31 -0
- package/Objects/Account.js +160 -110
- package/Objects/Blockweb.js +6 -11
- package/Objects/Callable.js +223 -188
- package/Objects/Chain.js +127 -142
- package/Objects/Datatypes.js +114 -588
- package/Objects/Manager.js +349 -39
- package/Objects/Oracle.js +283 -210
- package/Objects/Repository.js +12 -33
- package/Objects/Trinity.js +9 -7
- package/Objects/Utils.js +8 -8
- package/Objects/Virtual_machine.js +320 -320
- package/README.md +0 -0
- package/callables/functions/assert.js +10 -0
- package/callables/functions/display.js +2 -3
- package/callables/functions/env.js +5 -0
- package/callables/functions/event.js +14 -0
- package/callables/functions/exit.js +3 -2
- package/callables/functions/folder.js +15 -0
- package/callables/functions/get_uid.js +6 -0
- package/callables/functions/hash.js +7 -0
- package/callables/functions/import_.js +62 -0
- package/callables/functions/local.js +9 -0
- package/callables/functions/net.js +33 -18
- package/callables/functions/parse.js +35 -0
- package/callables/functions/query.js +12 -0
- package/callables/functions/render.js +9 -13
- package/callables/functions/servers.js +10 -0
- package/callables/functions/spawn.js +7 -0
- package/callables/functions/store.js +75 -0
- package/callables/functions/super_.js +24 -0
- package/callables/functions/typeof.js +32 -0
- package/callables/functions/wait.js +9 -0
- package/callables/register.js +193 -8
- package/html/create.js +110 -0
- package/html/index.js +114 -0
- package/html/load.js +165 -0
- package/html/parse.js +171 -0
- package/html/run.js +151 -0
- package/html/util.js +5 -0
- package/package.json +5 -3
- package/repos/fs.js +114 -0
- package/repos/github.js +73 -0
- package/repos/ram.js +47 -0
- package/utils/create_server.js +66 -26
- package/utils/hash.js +3 -2
- package/utils/ops.js +2 -0
- package/utils/oracle_handlers.js +7 -0
- package/utils/services.js +18 -51
- package/utils/socket_server.js +36 -0
- package/utils/vm_utils.js +241 -137
- package/callables/functions/assign.js +0 -6
package/Datatypes/instance.js
CHANGED
|
@@ -1,150 +1,115 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Storage from "godprotocol/Datatypes/functions/storage.js";
|
|
2
2
|
|
|
3
|
-
class Instance extends
|
|
4
|
-
constructor(
|
|
5
|
-
super()
|
|
3
|
+
class Instance extends Storage{
|
|
4
|
+
constructor(config, account){
|
|
5
|
+
super(account)
|
|
6
6
|
|
|
7
|
-
this.
|
|
8
|
-
this.value = payload;
|
|
7
|
+
this.config = config;
|
|
9
8
|
this.type = 'instance'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
operate = async(op, args, options={})=>{
|
|
13
|
-
let {classifier} = options;
|
|
14
|
-
let value;
|
|
15
|
-
switch(classifier){
|
|
16
|
-
case 'twain':
|
|
17
|
-
value = await this.twain(op, args, options)
|
|
18
|
-
break;
|
|
19
|
-
case 'number':
|
|
20
|
-
value = await this.number(op, args)
|
|
21
|
-
break;
|
|
22
|
-
case 'array':
|
|
23
|
-
value = await this.array(op, args, options)
|
|
24
|
-
break;
|
|
25
|
-
case 'string':
|
|
26
|
-
value = await this.string(op, args)
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
9
|
|
|
30
|
-
|
|
10
|
+
this.lits = ['listen', 'emit']
|
|
31
11
|
}
|
|
32
12
|
|
|
33
|
-
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let {content, path} = this.value
|
|
13
|
+
get_cls_fold = async()=>{
|
|
14
|
+
let cls = await this.account.manager.gds.folder(this.config.classifier)
|
|
15
|
+
return cls;
|
|
16
|
+
}
|
|
39
17
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let
|
|
43
|
-
|
|
18
|
+
run = async(call_config, options={})=>{
|
|
19
|
+
let {thread} = options;
|
|
20
|
+
let {identifier, arguments: args} = call_config;
|
|
21
|
+
let {value, _id} = identifier;
|
|
44
22
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
await
|
|
51
|
-
|
|
23
|
+
let func = await this.account.vm.cloth({
|
|
24
|
+
type: 'function',
|
|
25
|
+
address: value,
|
|
26
|
+
_id
|
|
27
|
+
})
|
|
28
|
+
await func.invoke([...args], {
|
|
29
|
+
thread,
|
|
30
|
+
instance_: {
|
|
31
|
+
type: 'address',
|
|
32
|
+
value: this.config.location,
|
|
33
|
+
_id: this.config._id
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
52
37
|
|
|
53
|
-
|
|
38
|
+
invoke = async(args, options)=>{
|
|
39
|
+
let cll = await this.get_('__call__')
|
|
40
|
+
let {vm} = this.account
|
|
41
|
+
if (!cll) return await vm.throw_error({type:"TypeError", message:`${this.config.name} Instance has no __call__ operator`})
|
|
54
42
|
|
|
55
|
-
let
|
|
56
|
-
await
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
let {chain} = options;
|
|
44
|
+
return await vm.execute_call({
|
|
45
|
+
type: 'call',
|
|
46
|
+
identifier: cll,
|
|
47
|
+
arguments: args,
|
|
48
|
+
location: vm.gen_location()
|
|
49
|
+
}, {chain})
|
|
59
50
|
}
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
let
|
|
63
|
-
let hsh = await oracle.hash(prop)
|
|
64
|
-
let {config, chain} = options;
|
|
65
|
-
let {content, path} = this.value, result;
|
|
52
|
+
literal = async (options={})=>{
|
|
53
|
+
let {raw, no_lit} = options
|
|
66
54
|
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
let val = await oracle.fs.read(pair[1])
|
|
70
|
-
|
|
71
|
-
let is_datatype = this.account.vm.datatypes.includes(val)
|
|
55
|
+
let chain = await this.chain(),
|
|
56
|
+
print = await this.get_('__print__', true), result;
|
|
72
57
|
|
|
73
|
-
if(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (result){
|
|
77
|
-
let res = await oracle.fs.read(result[1])
|
|
78
|
-
if(!res) result = {type: 'address', value: result[1]}
|
|
79
|
-
else result = res
|
|
80
|
-
}
|
|
81
|
-
|
|
58
|
+
if (print){
|
|
59
|
+
console.log(print, 'uh')
|
|
82
60
|
}else {
|
|
83
|
-
|
|
84
|
-
let res = {
|
|
85
|
-
type:'address',
|
|
86
|
-
value: prop,
|
|
87
|
-
object: path
|
|
88
|
-
}
|
|
89
|
-
if(val === 'array' && typeof prop === 'number' && options.obj){
|
|
90
|
-
result = await this.operate('index', [options.obj], {classifier: val})
|
|
91
|
-
}else if (val === 'twain'){
|
|
92
|
-
if (!this.is_literal && options.obj){
|
|
93
|
-
result = await this.operate('get', [options.obj], {classifier: val})
|
|
94
|
-
result= await this.account.vm.operate_result(result, config, chain)
|
|
95
|
-
}else result = res
|
|
96
|
-
} else result = res
|
|
97
|
-
}
|
|
98
|
-
|
|
61
|
+
result = `[Instance ${this.config.name}]`
|
|
99
62
|
}
|
|
100
|
-
|
|
101
|
-
return result;
|
|
63
|
+
return result
|
|
102
64
|
}
|
|
103
65
|
|
|
104
|
-
|
|
105
|
-
let
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
let {content, path} = this.value;
|
|
66
|
+
set_ = async(prop, value)=>{
|
|
67
|
+
let {vm, manager} = this.account
|
|
68
|
+
let propobj = await vm.cloth(prop)
|
|
69
|
+
let valobj = await vm.cloth(value)
|
|
109
70
|
|
|
110
|
-
|
|
111
|
-
let value = content[hsh];
|
|
71
|
+
let prop_lit = await propobj.literal()
|
|
112
72
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
73
|
+
if (['function', 'class'].includes(valobj.type)){
|
|
74
|
+
this.config.methods[prop_lit] = valobj.ref()
|
|
75
|
+
delete this.config.properties[prop_lit]
|
|
76
|
+
}else {
|
|
77
|
+
this.config.properties[prop_lit] = valobj.ref()
|
|
78
|
+
delete this.config.methods[prop_lit]
|
|
79
|
+
}
|
|
80
|
+
await (await manager.ds.folder(this.config.location)).write(this.config, {replace: true})
|
|
81
|
+
}
|
|
117
82
|
|
|
118
|
-
|
|
119
|
-
|
|
83
|
+
get_ = async(prop, raw)=>{
|
|
84
|
+
let res = this.config.properties[prop], is_method;
|
|
85
|
+
if (!res){
|
|
86
|
+
res = this.config.methods[prop]
|
|
87
|
+
is_method = true
|
|
120
88
|
}
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
}else if (this.lit.__classifier__ === 'array'){
|
|
135
|
-
let vm = this.account.vm;
|
|
89
|
+
|
|
90
|
+
if (!res){
|
|
91
|
+
if (this.methods[prop]){
|
|
92
|
+
res = {
|
|
93
|
+
type: 'address',
|
|
94
|
+
value: prop,
|
|
95
|
+
_id: prop.repeat(2),
|
|
96
|
+
object: this.ref(),
|
|
97
|
+
}
|
|
98
|
+
return res;
|
|
99
|
+
} else return !raw && await this.account.vm.voided()
|
|
100
|
+
}else{
|
|
136
101
|
|
|
137
|
-
|
|
138
|
-
this.lit.content_addr = [...this.lit.content]
|
|
139
|
-
for (let i=0; i< this.lit.content_addr.length; i++){
|
|
140
|
-
let item = this.lit.content_addr[i]
|
|
141
|
-
item = await vm.cloth_content(await vm.resolve_address(item))
|
|
142
|
-
|
|
143
|
-
this.lit.content[i] = await item.literal()
|
|
144
|
-
}
|
|
102
|
+
}
|
|
145
103
|
|
|
104
|
+
res = res.split('/')
|
|
105
|
+
res = {
|
|
106
|
+
type: 'address',
|
|
107
|
+
value: res.slice(0,-1).join('/'),
|
|
108
|
+
_id: res.slice(-1)[0],
|
|
146
109
|
}
|
|
147
|
-
|
|
110
|
+
if (is_method) res.object = this.ref()
|
|
111
|
+
|
|
112
|
+
return res;
|
|
148
113
|
}
|
|
149
114
|
|
|
150
115
|
sync = async()=>{
|
package/Datatypes/num.js
CHANGED
|
@@ -1,169 +1,208 @@
|
|
|
1
|
-
import Storage from "./functions/storage";
|
|
1
|
+
import Storage from "./functions/storage.js";
|
|
2
2
|
|
|
3
3
|
class Num extends Storage {
|
|
4
|
-
constructor(config,
|
|
5
|
-
super(
|
|
4
|
+
constructor(config, account) {
|
|
5
|
+
super(account)
|
|
6
6
|
|
|
7
7
|
this.config = config
|
|
8
8
|
this.type = 'number'
|
|
9
|
+
|
|
10
|
+
this.methods = {
|
|
11
|
+
...this.methods,
|
|
12
|
+
'inc': {args: [['other', 'number']], ret: ['result', 'number']},
|
|
13
|
+
'dec': {args: [['other', 'number']], ret: ['result', 'number']},
|
|
14
|
+
'__mod_': {args: [['other', 'number']], ret: ['result', 'number']},
|
|
15
|
+
'__exp__': {args: [['other', 'number']], ret: ['result', 'number']},
|
|
16
|
+
'__floordiv__': {args: [['other', 'number']], ret: ['result', 'number']},
|
|
17
|
+
|
|
18
|
+
'to_degrees': {args: [], ret: ['result', 'number']},
|
|
19
|
+
'to_radians': {args: [], ret: ['result', 'number']},
|
|
20
|
+
'to_string': {args: [], ret: ['result', 'number']},
|
|
21
|
+
'to_float': {args: [], ret: ['result', 'number']},
|
|
22
|
+
'to_int': {args: [], ret: ['result', 'number']},
|
|
23
|
+
'sqrt': {args: [], ret: ['result', 'number']},
|
|
24
|
+
'abs': {args: [], ret: ['result', 'number']},
|
|
25
|
+
'sin': {args: [], ret: ['result', 'number']},
|
|
26
|
+
'tan': {args: [], ret: ['result', 'number']},
|
|
27
|
+
'cos': {args: [], ret: ['result', 'number']},
|
|
28
|
+
'asin': {args: [], ret: ['result', 'number']},
|
|
29
|
+
'acos': {args: [], ret: ['result', 'number']},
|
|
30
|
+
'atan': {args: [], ret: ['result', 'number']},
|
|
31
|
+
'atan2': {args: [], ret: ['result', 'number']},
|
|
32
|
+
'tanh': {args: [], ret: ['result', 'number']},
|
|
33
|
+
'sinh': {args: [], ret: ['result', 'number']},
|
|
34
|
+
'cosh': {args: [], ret: ['result', 'number']},
|
|
35
|
+
'acosh': {args: [], ret: ['result', 'number']},
|
|
36
|
+
'asinh': {args: [], ret: ['result', 'number']},
|
|
37
|
+
'atanh': {args: [], ret: ['result', 'number']},
|
|
38
|
+
|
|
39
|
+
'floor': {args: [], ret: ['result', 'number']},
|
|
40
|
+
'ceil': {args: [], ret: ['result', 'number']},
|
|
41
|
+
'round': {args: [['other', 'number']], ret: ['result', 'number']},
|
|
42
|
+
|
|
43
|
+
'is_prime': {args: [], ret: ['result', 'boolean']},
|
|
44
|
+
'is_perfect_square': {args: [], ret: ['result', 'boolean']},
|
|
45
|
+
'log': {args: [['other', 'number']], ret: ['result', 'number']},
|
|
46
|
+
'is_even': {args: [], ret: ['result', 'boolean']},
|
|
47
|
+
'is_odd': {args: [], ret: ['result', 'boolean']},
|
|
48
|
+
'factorial': {args: [['factor', 'number']], ret: ['result', 'number']},
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
__or__ = other=>this.value || other
|
|
53
|
+
|
|
54
|
+
__and__ = other=>this.value && other
|
|
55
|
+
|
|
56
|
+
__add__ = (other)=>{
|
|
57
|
+
return this.value + other
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
inc = async(other)=>{
|
|
61
|
+
other = other || 1
|
|
62
|
+
let val = this.value + other;
|
|
63
|
+
let {vm, chain} = this.account
|
|
64
|
+
|
|
65
|
+
return await vm.instantiate({
|
|
66
|
+
type: 'number',
|
|
67
|
+
value: val.toString(),
|
|
68
|
+
location: this.address
|
|
69
|
+
}, {chain, _id: this.config._id})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
dec = async(other)=>{
|
|
73
|
+
other = other || 1
|
|
74
|
+
let val = this.value - other;
|
|
75
|
+
let {vm, chain} = this.account
|
|
76
|
+
|
|
77
|
+
return await vm.instantiate({
|
|
78
|
+
type: 'number',
|
|
79
|
+
value: val.toString(),
|
|
80
|
+
location: this.address
|
|
81
|
+
}, {chain, _id: this.config._id})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
__mul__ = (other)=>{
|
|
85
|
+
return this.value * other
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
__sub__ = (other)=>{
|
|
89
|
+
return this.value - other
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
__div__ = async (other)=>{
|
|
93
|
+
if(other === 0){
|
|
94
|
+
return await this.account.vm.throw_error({type:"ZeroDivisionError", message: "Cannot have 0 be a denominator"})
|
|
95
|
+
}else
|
|
96
|
+
return this.value / other
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
__gt__ = (other)=> this.value > other
|
|
100
|
+
__lt__ = (other)=> this.value < other
|
|
101
|
+
__gte__ = (other)=> this.value >= other
|
|
102
|
+
__lte__ = (other)=> this.value <= other
|
|
103
|
+
__ne__ = (other)=> this.value != other
|
|
104
|
+
__eq__ = (other)=> this.value == other
|
|
105
|
+
__mod__ = (other)=> this.value % other
|
|
106
|
+
__exp__ = (other)=> this.value ** other
|
|
107
|
+
__floordiv__ = (other)=> Math.floor(this.value / other)
|
|
108
|
+
|
|
109
|
+
to_degrees = ()=>{
|
|
110
|
+
return this.value * (180 / Math.PI)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
to_radians = ()=>{
|
|
114
|
+
return this.value * (Math.PI / 180)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
to_string = ()=>{
|
|
118
|
+
return this.value.toString()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
to_float = (other)=>{
|
|
122
|
+
return this.value.toFixed(other)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
to_int = ()=>parseInt(this.value)
|
|
126
|
+
|
|
127
|
+
sqrt = ()=>Math.sqrt(this.value)
|
|
128
|
+
|
|
129
|
+
abs = ()=>Math.abs(this.value)
|
|
130
|
+
|
|
131
|
+
sin = ()=>Math.sin(this.value)
|
|
132
|
+
tan = ()=>Math.tan(this.value)
|
|
133
|
+
cos = ()=>Math.cos(this.value)
|
|
134
|
+
asin = ()=>Math.asin(this.value)
|
|
135
|
+
acos = ()=>Math.acos(this.value)
|
|
136
|
+
atan = ()=>Math.atan(this.value)
|
|
137
|
+
atan2 = ()=>Math.atan2(this.value)
|
|
138
|
+
tanh = ()=>Math.tanh(this.value)
|
|
139
|
+
sinh = ()=>Math.sinh(this.value)
|
|
140
|
+
cosh = ()=>Math.cosh(this.value)
|
|
141
|
+
asinh = ()=>Math.asinh(this.value)
|
|
142
|
+
acosh = ()=>Math.acosh(this.value)
|
|
143
|
+
atanh = ()=>Math.atanh(this.value)
|
|
144
|
+
|
|
145
|
+
floor = ()=>Math.floor(this.value)
|
|
146
|
+
|
|
147
|
+
ceil = ()=>Math.ceil(this.value)
|
|
148
|
+
|
|
149
|
+
round = (other)=>{
|
|
150
|
+
let result;
|
|
151
|
+
if (other) {
|
|
152
|
+
result = Number(Number(this.value).toFixed(other));
|
|
153
|
+
} else result = Math.round(this.value);
|
|
154
|
+
|
|
155
|
+
return result;
|
|
9
156
|
}
|
|
10
157
|
|
|
11
|
-
|
|
12
|
-
let result
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
result =
|
|
21
|
-
|
|
22
|
-
case '__mul__':
|
|
23
|
-
result = me * other;
|
|
24
|
-
break;
|
|
25
|
-
case '__div__':
|
|
26
|
-
result = me / other;
|
|
27
|
-
break;
|
|
28
|
-
case '__exp__':
|
|
29
|
-
result = me ** other;
|
|
30
|
-
break;
|
|
31
|
-
case '__floordiv__':
|
|
32
|
-
result = Math.floor(me / other);
|
|
33
|
-
break;
|
|
34
|
-
case '__mod__':
|
|
35
|
-
result = me % other;
|
|
36
|
-
break;
|
|
37
|
-
case '__eq__':
|
|
38
|
-
result = me === other
|
|
39
|
-
break;
|
|
40
|
-
case '__ne__':
|
|
41
|
-
result = me !== other
|
|
42
|
-
break;
|
|
43
|
-
case '__lt__':
|
|
44
|
-
result = me < other
|
|
45
|
-
break;
|
|
46
|
-
case '__lte__':
|
|
47
|
-
result = me <= other
|
|
48
|
-
break;
|
|
49
|
-
case '__gt__':
|
|
50
|
-
result = me > other
|
|
51
|
-
break;
|
|
52
|
-
case '__gte__':
|
|
53
|
-
result = me >= other
|
|
54
|
-
break;
|
|
55
|
-
case 'abs':
|
|
56
|
-
result = Math.abs(me)
|
|
57
|
-
break;
|
|
58
|
-
case 'sqrt':
|
|
59
|
-
result = Math.sqrt(me)
|
|
60
|
-
break;
|
|
61
|
-
case 'to_int':
|
|
62
|
-
result = parseInt(me)
|
|
63
|
-
break;
|
|
64
|
-
case 'to_float':
|
|
65
|
-
result = Number(me).toFixed(other)
|
|
66
|
-
break;
|
|
67
|
-
case 'to_string':
|
|
68
|
-
result = me.toString()
|
|
69
|
-
break;
|
|
70
|
-
case 'tan':
|
|
71
|
-
result = Math.tan(me)
|
|
72
|
-
break;
|
|
73
|
-
case 'sin':
|
|
74
|
-
result = Math.sin(me)
|
|
75
|
-
break;
|
|
76
|
-
case 'cos':
|
|
77
|
-
result = Math.cos(me)
|
|
78
|
-
break;
|
|
79
|
-
case 'atan':
|
|
80
|
-
result = Math.atan(me)
|
|
81
|
-
break;
|
|
82
|
-
case 'atan2':
|
|
83
|
-
result = Math.atan2(me)
|
|
84
|
-
break;
|
|
85
|
-
case 'asin':
|
|
86
|
-
result = Math.asin(me)
|
|
87
|
-
break;
|
|
88
|
-
case 'acos':
|
|
89
|
-
result = Math.acos(me)
|
|
90
|
-
break;
|
|
91
|
-
case 'tanh':
|
|
92
|
-
result = Math.tanh(me)
|
|
93
|
-
break;
|
|
94
|
-
case 'sinh':
|
|
95
|
-
result = Math.sinh(me)
|
|
96
|
-
break;
|
|
97
|
-
case 'cosh':
|
|
98
|
-
result = Math.cosh(me)
|
|
99
|
-
break;
|
|
100
|
-
case 'asinh':
|
|
101
|
-
result = Math.asinh(me)
|
|
102
|
-
break;
|
|
103
|
-
case 'acosh':
|
|
104
|
-
result = Math.acosh(me)
|
|
105
|
-
break;
|
|
106
|
-
case 'atanh':
|
|
107
|
-
result = Math.atanh(me)
|
|
108
|
-
break;
|
|
109
|
-
case 'round':
|
|
110
|
-
if (other){
|
|
111
|
-
result = Number(Number(me).toFixed(other))
|
|
112
|
-
}else result = Math.round(me)
|
|
113
|
-
break;
|
|
114
|
-
case 'ceil':
|
|
115
|
-
result = Math.ceil(me)
|
|
116
|
-
break;
|
|
117
|
-
case 'floor':
|
|
118
|
-
result = Math.floor(me)
|
|
119
|
-
break;
|
|
120
|
-
case 'is_prime':
|
|
121
|
-
if (me <= 1) result = false;
|
|
122
|
-
if (me <= 3) result = true;
|
|
123
|
-
|
|
124
|
-
if (me % 2 === 0 || me % 3 === 0) result = false;
|
|
125
|
-
|
|
126
|
-
for (let i = 5; i * i <= me; i += 6) {
|
|
127
|
-
if (me % i === 0 || me % (i + 2) === 0) {
|
|
128
|
-
result = false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
result = true;
|
|
132
|
-
break;
|
|
133
|
-
case 'is_odd':
|
|
134
|
-
result = (me % 2) === 1
|
|
135
|
-
break
|
|
136
|
-
case 'is_even':
|
|
137
|
-
result = (me % 2) === 0
|
|
138
|
-
break
|
|
139
|
-
case 'log':
|
|
140
|
-
if (!other || (other === 10))
|
|
141
|
-
result = Math.log10(me)
|
|
142
|
-
else if (other === Math.E){
|
|
143
|
-
result = Math.log(me)
|
|
144
|
-
}else result = Math.log(me) / Math.log(other)
|
|
145
|
-
break;
|
|
146
|
-
case 'factorial':
|
|
147
|
-
result = this.factorial(me)
|
|
148
|
-
break;
|
|
149
|
-
case 'is_perfect_square':
|
|
150
|
-
if (me < 0) result = false;
|
|
151
|
-
|
|
152
|
-
let sqrt = Math.sqrt(me);
|
|
153
|
-
result = sqrt === Math.floor(sqrt);
|
|
154
|
-
break
|
|
155
|
-
case 'to_degrees':
|
|
156
|
-
result = me * (180 / Math.PI)
|
|
157
|
-
break;
|
|
158
|
-
case 'to_radians':
|
|
159
|
-
result = me * (Math.PI / 180)
|
|
160
|
-
break;
|
|
158
|
+
is_prime = ()=>{
|
|
159
|
+
let result = true;
|
|
160
|
+
if (this.value <= 1) result = false;
|
|
161
|
+
if (this.value <= 3) result = true;
|
|
162
|
+
|
|
163
|
+
if (this.value % 2 === 0 || this.value % 3 === 0) result = false;
|
|
164
|
+
|
|
165
|
+
for (let i = 5; i * i <= this.value; i += 6) {
|
|
166
|
+
if (this.value % i === 0 || this.value % (i + 2) === 0) {
|
|
167
|
+
result = false;
|
|
168
|
+
}
|
|
161
169
|
}
|
|
170
|
+
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
is_perfect_square = ()=>{
|
|
175
|
+
let result;
|
|
176
|
+
if (this.value < 0) result = false;
|
|
177
|
+
|
|
178
|
+
let sqrt = Math.sqrt(this.value);
|
|
179
|
+
result = sqrt === Math.floor(sqrt);
|
|
162
180
|
|
|
163
181
|
return result;
|
|
164
182
|
}
|
|
165
183
|
|
|
184
|
+
log = (other)=>{
|
|
185
|
+
let result;
|
|
186
|
+
if (!other || other === 10) result = Math.log10(this.value);
|
|
187
|
+
else if (other === Math.E) {
|
|
188
|
+
result = Math.log(this.value);
|
|
189
|
+
} else result = Math.log(this.value) / Math.log(other);
|
|
190
|
+
|
|
191
|
+
return result
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
is_even = ()=>{
|
|
195
|
+
return this.value % 2 === 0
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
is_odd = ()=>!this.is_even()
|
|
199
|
+
|
|
200
|
+
literal = async()=>{
|
|
201
|
+
return Number(this.config.value)
|
|
202
|
+
}
|
|
203
|
+
|
|
166
204
|
factorial = (value)=>{
|
|
205
|
+
if (value == null) value = this.value;
|
|
167
206
|
if (value === 0)
|
|
168
207
|
return 1
|
|
169
208
|
return value * this.factorial(value - 1)
|