Sha256: 952ffb7fc912b6168d6b9afb92cd12d4a01a4c55fe2eb82a9abce4def0a207c5

Contents?: true

Size: 907 Bytes

Versions: 141

Compression:

Stored size: 907 Bytes

Contents

exports = module.exports = stringify
exports.getSerialize = serializer

function stringify(obj, replacer, spaces, cycleReplacer) {
  return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces)
}

function serializer(replacer, cycleReplacer) {
  var stack = [], keys = []

  if (cycleReplacer == null) cycleReplacer = function(key, value) {
    if (stack[0] === value) return "[Circular ~]"
    return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]"
  }

  return function(key, value) {
    if (stack.length > 0) {
      var thisPos = stack.indexOf(this)
      ~thisPos ? stack.splice(thisPos + 1) : stack.push(this)
      ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
      if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value)
    }
    else stack.push(value)

    return replacer == null ? value : replacer.call(this, key, value)
  }
}

Version data entries

141 entries across 132 versions & 25 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/json-stringify-safe/stringify.js
disco_app-0.18.0 test/dummy/node_modules/json-stringify-safe/stringify.js
disco_app-0.18.2 test/dummy/node_modules/json-stringify-safe/stringify.js
tang-0.2.1 spec/tang_app/node_modules/json-stringify-safe/stringify.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/json-stringify-safe/stringify.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/json-stringify-safe/stringify.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/json-stringify-safe/stringify.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/json-stringify-safe/stringify.js
tang-0.2.0 spec/tang_app/node_modules/json-stringify-safe/stringify.js
tang-0.1.0 spec/tang_app/node_modules/json-stringify-safe/stringify.js
tang-0.0.9 spec/tang_app/node_modules/json-stringify-safe/stringify.js
enju_library-0.3.8 spec/dummy/node_modules/json-stringify-safe/stringify.js
ilog-0.4.1 node_modules/json-stringify-safe/stringify.js
ilog-0.4.0 node_modules/json-stringify-safe/stringify.js
ilog-0.3.3 node_modules/json-stringify-safe/stringify.js
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/json-stringify-safe/stringify.js
jester-data-8.0.0 node_modules/json-stringify-safe/stringify.js
ezii-os-5.2.1 node_modules/json-stringify-safe/stringify.js
ezii-os-2.0.1 node_modules/json-stringify-safe/stringify.js
ezii-os-1.1.0 node_modules/json-stringify-safe/stringify.js