• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jaubourg / wires / 3624033844

pending completion
3624033844

push

github

GitHub
build(deps-dev): bump eslint from 8.16.0 to 8.29.0

289 of 306 branches covered (94.44%)

526 of 537 relevant lines covered (97.95%)

1805.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.84
/lib/serialize-javascript/index.js
1
/*
2
copyright (c) 2014, Yahoo! Inc. All rights reserved
3
copyrights licensed under the New BSD License
4
see the accompanying LICENSE file for terms
5
copyright (c) 2022, Julian Aubourg All rights reserved
6
copyrights licensed under the MIT License
7
see the accompanying LICENSE file for terms
8
*/
9

10
'use strict';
11

12
const { deleteFunctions, escapeUnsafeChars } = require( `./utils` );
28✔
13
const Placeholders = require( `./Placeholders` );
28✔
14

15
// eslint-disable-next-line complexity
16
const serialize = ( input, options ) => {
28✔
17

18
    // eslint-disable-next-line no-param-reassign
19
    options = options || {};
16,363✔
20

21
    // backwards-compatibility for `space` as the second argument.
22
    if ( ( typeof options === `number` ) || ( typeof options === `string` ) ) {
16,363✔
23
        // eslint-disable-next-line no-param-reassign
24
        options = {
3✔
25
            "space": options,
26
        };
27
    }
28

29
    let placeholders;
30

31
    // eslint-disable-next-line prefer-const
32
    let internal;
33

34
    // returns placeholders for functions and regexps (identified by index)
35
    // which are later replaced by their string representation.
36
    // eslint-disable-next-line func-style
37
    const replacer = function( key, value ) {
16,363✔
38

39
        // for nested function
40
        if ( options.ignoreFunction ) {
58,932✔
41
            // eslint-disable-next-line no-param-reassign
42
            value = deleteFunctions( value );
8,000✔
43
        }
44

45
        return (
58,932✔
46
            placeholders || ( placeholders = new Placeholders( internal, options ) )
71,275✔
47
        // eslint-disable-next-line no-invalid-this
48
        ).get( this[ key ] ) || value;
49
    };
50

51
    internal = data => {
16,363✔
52

53
        // check if the parameter is function
54
        if ( options.ignoreFunction && ( typeof data === `function` ) ) {
16,372!
55
            // eslint-disable-next-line no-param-reassign
56
            data = undefined;
×
57
        }
58
        // protects against `JSON.stringify()` returning `undefined`, by serializing
59
        // to the literal string: "undefined".
60
        if ( data === undefined ) {
16,372✔
61
            return `undefined`;
20✔
62
        }
63

64
        let str = JSON.stringify( data, options.isJSON ? null : replacer, options.space );
16,352✔
65

66
        // protects against `JSON.stringify()` returning `undefined`, by serializing
67
        // to the literal string: "undefined".
68
        if ( str === undefined ) {
16,352!
69
            return `undefined`;
×
70
        }
71

72
        // replace unsafe HTML and invalid JavaScript line terminator chars with
73
        // their safe Unicode char counterpart. This _must_ happen before the
74
        // regexps and functions are serialized and added back to the string.
75
        if ( options.unsafe !== true ) {
16,352✔
76
            str = escapeUnsafeChars( str );
15,284✔
77
        }
78

79
        return placeholders ? placeholders.restore( str ) : str;
16,352✔
80
    };
81

82
    return internal( input );
16,363✔
83
};
84

85
module.exports = serialize;
28✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc