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
node-compiler-0.9.0 vendor/node-v7.2.1/deps/npm/node_modules/request/node_modules/json-stringify-safe/stringify.js
select_all-rails-0.3.1 node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
node-compiler-0.8.0 vendor/node-v7.2.0/deps/npm/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
node-compiler-0.7.0 vendor/node-v6.9.1/deps/npm/node_modules/request/node_modules/json-stringify-safe/stringify.js
node-compiler-0.7.0 vendor/node-v7.1.0/deps/npm/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.10 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.9 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.8 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.7 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.6 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/request/node_modules/json-stringify-safe/stringify.js
tck-lambdas-0.3.5 lib/tck/lambdas/chistacojs/source/node_modules/request/node_modules/json-stringify-safe/stringify.js