Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: yahoo/serialize-javascript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.0.0
Choose a base ref
...
head repository: yahoo/serialize-javascript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.2
Choose a head ref
Loading
Showing with 1,608 additions and 1,105 deletions.
  1. +6 −6 .github/dependabot.yml
  2. +3 −3 .github/workflows/test.yml
  3. +3 −2 README.md
  4. +2 −2 index.js
  5. +1,582 −1,088 package-lock.json
  6. +2 −2 package.json
  7. +10 −2 test/unit/serialize.js
12 changes: 6 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "13:00"
open-pull-requests-limit: 10
- package-ecosystem: npm
directory: "/"
schedule:
interval: monthly
time: "13:00"
open-pull-requests-limit: 10
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -47,16 +47,17 @@ serialize({
fn : function echo(arg) { return arg; },
re : /([^\s]+)/g,
big : BigInt(10),
url : new URL('https://example.com/'),
});
```

The above will produce the following string output:

```js
'{"str":"string","num":0,"obj":{"foo":"foo"},"arr":[1,2,3],"bool":true,"nil":null,"undef":undefined,"inf":Infinity,"date":new Date("2016-04-28T22:02:17.000Z"),"map":new Map([["hello","world"]]),"set":new Set([123,456]),"fn":function echo(arg) { return arg; },"re":new RegExp("([^\\\\s]+)", "g"),"big":BigInt("10")}'
'{"str":"string","num":0,"obj":{"foo":"foo"},"arr":[1,2,3],"bool":true,"nil":null,"undef":undefined,"inf":Infinity,"date":new Date("2016-04-28T22:02:17.000Z"),"map":new Map([["hello","world"]]),"set":new Set([123,456]),"fn":function echo(arg) { return arg; },"re":new RegExp("([^\\\\s]+)", "g"),"big":BigInt("10"),"url":new URL("https://example.com/")}'
```

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.
Note: to produce a beautified string, you can pass an optional second argument to `serialize()` to define the number of spaces to be used for the indentation.

### Automatic Escaping of HTML Characters

4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ module.exports = function serialize(obj, options) {
deleteFunctions(value);
}

if (!value && value !== undefined) {
if (!value && value !== undefined && value !== BigInt(0)) {
return value;
}

@@ -258,7 +258,7 @@ module.exports = function serialize(obj, options) {
}

if (type === 'L') {
return "new URL(\"" + urls[valueIndex].toString() + "\")";
return "new URL(" + serialize(urls[valueIndex].toString(), options) + ")";
}

var fn = functions[valueIndex];
Loading