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
tck-lambdas-0.3.4 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.3 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.2 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.1 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.0 lib/tck/lambdas/chistacojs/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.0 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.2.0 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.2.0 lib/tck/lambdas/chistacojs/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.1.6 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.1.6 lib/tck/lambdas/chistacojs/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
brwy_rails-0.0.6 test/dummy/node_modules/fsevents/node_modules/json-stringify-safe/stringify.js
brwy_rails-0.0.5 test/dummy/node_modules/fsevents/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.5 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js