You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We detect dates simply by doing an instanceof check on raw value being serialized.
We're also now looking at the typeof the *rawValue* not the toJSON()ed value
when determining whether a value is a function or a RegExp. This should allow
functions and regexs to be serialized properly even if a Function.prototype.toJSON
or a RegExp.prototype.toJSON has been added for some reason.
Finally, for consistency and because util.isRegExp has been deprecated, we also
update our logic for detecting RegExps to use the same strategy as for Dates.
Copy file name to clipboardExpand all lines: README.md
+4-3
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
Serialize JavaScript
2
2
====================
3
3
4
-
Serialize JavaScript to a _superset_ of JSON that includes regular expressions and functions.
4
+
Serialize JavaScript to a _superset_ of JSON that includes regular expressions, dates and functions.
5
5
6
6
[![npm Version][npm-badge]][npm]
7
7
[![Dependency Status][david-badge]][david]
@@ -11,7 +11,7 @@ Serialize JavaScript to a _superset_ of JSON that includes regular expressions a
11
11
12
12
The code in this package began its life as an internal module to [express-state][]. To expand its usefulness, it now lives as `serialize-javascript` — an independent package on npm.
13
13
14
-
You're probably wondering: **What about `JSON.stringify()`!?** We've found that sometimes we need to serialize JavaScript **functions** and **regexps**. A great example is a web app that uses client-side URL routing where the route definitions are regexps that need to be shared from the server to the client.
14
+
You're probably wondering: **What about `JSON.stringify()`!?** We've found that sometimes we need to serialize JavaScript **functions**, **regexps** or **dates**. A great example is a web app that uses client-side URL routing where the route definitions are regexps that need to be shared from the server to the client.
15
15
16
16
The string returned from this package's single export function is literal JavaScript which can be saved to a `.js` file, or be embedded into an HTML document by making the content of a `<script>` element. **HTML charaters and JavaScript line terminators are escaped automatically.**
17
17
@@ -36,6 +36,7 @@ serialize({
36
36
bool :true,
37
37
nil :null,
38
38
undef:undefined,
39
+
date:newDate("Thu, 28 Apr 2016 22:02:17 GMT"),
39
40
40
41
fn:functionecho(arg) { return arg; },
41
42
re:/([^\s]+)/g
@@ -45,7 +46,7 @@ serialize({
45
46
The above will produce the following string output:
Note: to produced a beautified string, you can pass an optional second argument to `serialize()` to define the number of spaces to be used for the indentation.
0 commit comments