aboutsummaryrefslogtreecommitdiff
path: root/node_modules/clean-yaml-object
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/clean-yaml-object')
-rw-r--r--node_modules/clean-yaml-object/index.js92
-rw-r--r--node_modules/clean-yaml-object/license23
-rw-r--r--node_modules/clean-yaml-object/package.json37
-rw-r--r--node_modules/clean-yaml-object/readme.md52
4 files changed, 204 insertions, 0 deletions
diff --git a/node_modules/clean-yaml-object/index.js b/node_modules/clean-yaml-object/index.js
new file mode 100644
index 000000000..77b08168e
--- /dev/null
+++ b/node_modules/clean-yaml-object/index.js
@@ -0,0 +1,92 @@
+'use strict';
+module.exports = function (object, filterFn) {
+ return cleanYamlObj(object, filterFn || defaultFilter, true, []);
+};
+
+function cleanYamlObj(object, filter, isRoot, seen) {
+ if (object === undefined) {
+ return null;
+ }
+
+ if (typeof object === 'function') {
+ return object.toString();
+ }
+
+ if (Buffer.isBuffer(object)) {
+ return 'Buffer\n' + object.toString('hex').split('')
+ .reduce(function (set, c) {
+ if (set.length && set[set.length - 1].length === 1) {
+ set[set.length - 1] += c;
+ if (set.length && set.length % 20 === 0) {
+ set[set.length - 1] += '\n';
+ } else {
+ set[set.length - 1] += ' ';
+ }
+ } else {
+ set.push(c);
+ }
+ return set;
+ }, []).join('').trim();
+ }
+
+ if (object && typeof object === 'object') {
+ if (object instanceof RegExp) {
+ return object.toString();
+ }
+
+ seen = seen.concat([object]);
+
+ var isArray = Array.isArray(object);
+
+ // Fill in any holes. This means we lose expandos,
+ // but we were gonna lose those anyway.
+ if (isArray) {
+ object = Array.apply(null, object);
+ }
+
+ var isError = object && typeof object === 'object' && object instanceof Error;
+
+ var set = isArray ? [] : {};
+
+ // name is typically not an ownProperty on an Error
+ if (isError && object.name && !object.hasOwnProperty('name') && filter('name', isRoot, object, set)) {
+ setProp('name', object, set, seen, filter);
+ }
+
+ var keys = Object.getOwnPropertyNames(object);
+ return keys.reduce(function (set, k) {
+ // magic property!
+ if (isArray && k === 'length') {
+ return set;
+ }
+
+ // Don't dump massive EventEmitter and Domain
+ // objects onto the output, that's never friendly.
+ if (isError && /^domain/.test(k)) {
+ return set;
+ }
+
+ if (!filter(k, isRoot, object, set)) {
+ return set;
+ }
+
+ setProp(k, object, set, seen, filter);
+
+ return set;
+ }, set);
+ }
+
+ return object;
+}
+
+function setProp(propName, source, target, seen, filter) {
+ if (seen.indexOf(source[propName]) === -1) {
+ target[propName] = cleanYamlObj(source[propName], filter, false, seen);
+ } else {
+ target[propName] = '[Circular]';
+ }
+}
+
+function defaultFilter() {
+ return true;
+}
diff --git a/node_modules/clean-yaml-object/license b/node_modules/clean-yaml-object/license
new file mode 100644
index 000000000..8dc0833d1
--- /dev/null
+++ b/node_modules/clean-yaml-object/license
@@ -0,0 +1,23 @@
+The MIT License (MIT)
+
+Copyright (c) Isaac Z. Schlueter <i@izs.me>, James Talmage <james@talmage.io> (github.com/jamestalmage), and Contributors
+
+Extracted from code in node-tap http://www.node-tap.org/
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/node_modules/clean-yaml-object/package.json b/node_modules/clean-yaml-object/package.json
new file mode 100644
index 000000000..98305ac56
--- /dev/null
+++ b/node_modules/clean-yaml-object/package.json
@@ -0,0 +1,37 @@
+{
+ "name": "clean-yaml-object",
+ "version": "0.1.0",
+ "description": "Clean up an object prior to serialization",
+ "license": "MIT",
+ "repository": "tapjs/clean-yaml-object",
+ "author": {
+ "name": "James Talmage",
+ "email": "james@talmage.io",
+ "url": "github.com/jamestalmage"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "xo && nyc --cache --reporter=lcov --reporter=text ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "serialize",
+ "clean",
+ "dedupe",
+ "circular",
+ "yaml",
+ "json",
+ "error"
+ ],
+ "dependencies": {},
+ "devDependencies": {
+ "ava": "^0.10.0",
+ "coveralls": "^2.11.6",
+ "nyc": "^5.3.0",
+ "xo": "^0.12.1"
+ }
+}
diff --git a/node_modules/clean-yaml-object/readme.md b/node_modules/clean-yaml-object/readme.md
new file mode 100644
index 000000000..4e4e5a67b
--- /dev/null
+++ b/node_modules/clean-yaml-object/readme.md
@@ -0,0 +1,52 @@
+# clean-yaml-object [![Build Status](https://travis-ci.org/tapjs/clean-yaml-object.svg?branch=master)](https://travis-ci.org/tapjs/clean-yaml-object) [![Coverage Status](https://coveralls.io/repos/tapjs/clean-yaml-object/badge.svg?branch=master&service=github)](https://coveralls.io/github/tapjs/clean-yaml-object?branch=master)
+
+> Clean up an object prior to serialization.
+
+Replaces circular references, pretty prints Buffers, and numerous other enhancements. Primarily designed to prepare Errors for serialization to JSON/YAML.
+
+Extracted from [`node-tap`](https://github.com/tapjs/node-tap)
+
+## Install
+
+```
+$ npm install --save clean-yaml-object
+```
+
+
+## Usage
+
+```js
+const cleanYamlObject = require('clean-yaml-object');
+
+cleanYamlObject(new Error('foo'));
+//=> {name: 'Error', message: 'foo', stack: ...}
+```
+
+
+## API
+
+### cleanYamlObject(input, [filterFn])
+
+Returns a deep copy of `input` that is suitable for serialization.
+
+#### input
+
+Type: `*`
+
+Any object.
+
+#### filterFn
+
+Type: `callback(propertyName, isRoot, source, target)`
+
+Optional filter callback. Returning `true` will cause the property to be copied. Otherwise it will be skipped
+
+- `propertyName`: The property being copied.
+- `isRoot`: `true` only if `source` is the top level object passed to `copyYamlObject`
+- `source`: The source from which `source[propertyName]` will be copied.
+- `target`: The target object.
+
+## License
+
+
+MIT © [Isaac Z. Schlueter](http://github.com/isaacs) [James Talmage](http://github.com/jamestalmage)