Skip to content

Commit 38d38a2

Browse files
committed
Code formatted & Docs update
1 parent 55df724 commit 38d38a2

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ serialize(obj, {isJSON: true});
101101

102102
This option is to signal `serialize()` that we want to do a straight conversion, without the XSS protection. This options needs to be explicitly set to `true`. HTML characters and JavaScript line terminators will not be escaped. You will have to roll your own.
103103

104+
```js
105+
serialize(obj, {unsafe: true});
106+
```
107+
104108
#### `options.ignoreFunction`
105109

106110
This option is to signal `serialize()` that we do not want serialize JavaScript function.
107111
Just treat function like `JSON.stringify` do, but other features will work as expected.
108112

109113
```js
110-
serialize(obj, {unsafe: true});
114+
serialize(obj, {ignoreFunction: true});
111115
```
112116

113117
## Deserializing

index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ function escapeUnsafeChars(unsafeChar) {
3434
function deleteFunctions(obj){
3535
var functionKeys = [];
3636
for (var key in obj) {
37-
if (typeof obj[key] === "function") {
38-
functionKeys.push(key);
39-
}
37+
if (typeof obj[key] === "function") {
38+
functionKeys.push(key);
39+
}
4040
}
4141
for (var i = 0; i < functionKeys.length; i++) {
42-
delete obj[functionKeys[i]];
42+
delete obj[functionKeys[i]];
4343
}
4444
}
4545

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

145145
// Check if the parameter is function
146146
if (options.ignoreFunction && typeof obj === "function") {
147-
obj = undefined;
147+
obj = undefined;
148148
}
149149
// Protects against `JSON.stringify()` returning `undefined`, by serializing
150150
// to the literal string: "undefined".

test/unit/serialize.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -427,24 +427,24 @@ describe('serialize( obj )', function () {
427427

428428
it("should accept a `ignoreFunction` option", function() {
429429
function fn() { return true; }
430-
const obj = {
431-
fn,
432-
fn_arrow: () => {
433-
return true;
434-
}
430+
var obj = {
431+
fn: fn,
432+
fn_arrow: () => {
433+
return true;
434+
}
435435
};
436-
const obj2 = {
437-
num:123,
438-
str:'str',
439-
fn
436+
var obj2 = {
437+
num: 123,
438+
str: 'str',
439+
fn: fn
440440
}
441441
// case 1. Pass function to serialize
442-
expect(serialize(fn, { ignoreFunction: true })).to.equal(`undefined`);
442+
expect(serialize(fn, { ignoreFunction: true })).to.equal('undefined');
443443
// case 2. Pass function(arrow) in object to serialze
444-
expect(serialize(obj, { ignoreFunction: true })).to.equal("{}");
444+
expect(serialize(obj, { ignoreFunction: true })).to.equal('{}');
445445
// case 3. Other features should work
446446
expect(serialize(obj2, { ignoreFunction: true })).to.equal(
447-
`{"num":123,"str":"str"}`
447+
'{"num":123,"str":"str"}'
448448
);
449449
});
450450
});

0 commit comments

Comments
 (0)