FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mathjs/examples/serialization.js at feature/comments · JavaScriptIOT/mathjs · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
JavaScriptIOT
/
mathjs
Public
forked from
josdejong/mathjs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mathjs
/
examples
/
serialization.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
15 lines (13 loc) · 530 Bytes
Breadcrumbs
mathjs
/
examples
/
serialization.js
Copy path
File metadata and controls
15 lines (13 loc) · 530 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// load math.js (using node.js)
var
math
=
require
(
'../index'
)
;
// serialize a math.js data type into a JSON string
var
x
=
math
.
complex
(
'2+3i'
)
;
var
str1
=
JSON
.
stringify
(
x
)
;
console
.
log
(
str1
)
;
// outputs {"mathjs":"Complex","re":2,"im":3}
// deserialize a JSON string into a math.js data type
// note that the reviver of math.js is needed for this:
var
str2
=
'{"mathjs":"Unit","value":5,"unit":"cm"}'
;
var
y
=
JSON
.
parse
(
str2
,
math
.
json
.
reviver
)
;
console
.
log
(
math
.
typeof
(
y
)
)
;
// 'Unit'
console
.
log
(
y
.
toString
(
)
)
;
// 5 cm
Back
|
FazBrowse Home
|
New Git URL