From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/stringify-object/readme.md | 68 ++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 17 deletions(-) (limited to 'node_modules/stringify-object/readme.md') diff --git a/node_modules/stringify-object/readme.md b/node_modules/stringify-object/readme.md index 57c5bae9e..177f05445 100644 --- a/node_modules/stringify-object/readme.md +++ b/node_modules/stringify-object/readme.md @@ -1,6 +1,6 @@ # stringify-object [![Build Status](https://secure.travis-ci.org/yeoman/stringify-object.svg?branch=master)](http://travis-ci.org/yeoman/stringify-object) -> Stringify an object/array like JSON.stringify just without all the double-quotes. +> Stringify an object/array like JSON.stringify just without all the double-quotes Useful for when you want to get the string representation of an object in a formatted way. @@ -17,13 +17,15 @@ $ npm install --save stringify-object ## Usage ```js -var obj = { +const stringifyObject = require('stringify-object'); + +const obj = { foo: 'bar', 'arr': [1, 2, 3], nested: { hello: "world" } }; -var pretty = stringifyObject(obj, { +const pretty = stringifyObject(obj, { indent: ' ', singleQuotes: false }); @@ -53,49 +55,81 @@ Circular references will be replaced with `"[Circular]"`. #### input -*Required* -Type: `object`, `array` +Type: `Object` `Array` #### options ##### indent -Type: `string` +Type: `string`
Default: `'\t'` -Choose the indentation you prefer. +Preferred indentation. ##### singleQuotes -Type: `boolean` +Type: `boolean`
Default: `true` Set to false to get double-quoted strings. ##### filter(obj, prop) -Type: `function` +Type: `Function` + +Expected to return a `boolean` of whether to include the property `prop` of the object `obj` in the output. + +##### transform(obj, prop, originalResult) + +Type: `Function`
+Default: `undefined` + +Expected to return a `string` that transforms the string that resulted from stringifying `obj[prop]`. This can be used to detect special types of objects that need to be stringified in a particular way. The `transform` function might return an alternate string in this case, otherwise returning the `originalResult`. + +Here's an example that uses the `transform` option to mask fields named "password": + +```js +const obj = { + user: 'becky', + password: 'secret' +} + +const pretty = stringifyObject(obj, { + transform: (obj, prop, originalResult) => { + if (prop === 'password') { + return originalResult.replace(/\w/g, '*'); + } else { + return originalResult; + } + } +}); + +console.log(pretty); +/* +{ + user: 'becky', + password: '******' +} +*/ +``` -Expected to return a boolean of whether to keep the object. ##### inlineCharacterLimit Type: `number` -Default: undefined -When set, will inline values up to `inlineCharacterLimit` length for the sake -of more terse output. +When set, will inline values up to `inlineCharacterLimit` length for the sake of more terse output. For example, given the example at the top of the README: ```js -var obj = { +const obj = { foo: 'bar', 'arr': [1, 2, 3], nested: { hello: "world" } }; -var pretty = stringifyObject(obj, { +const pretty = stringifyObject(obj, { indent: ' ', singleQuotes: false, inlineCharacterLimit: 12 @@ -113,8 +147,8 @@ console.log(pretty); */ ``` -As you can see, `arr` was printed as a one-liner because its string was shorter -than 12 characters. +As you can see, `arr` was printed as a one-liner because its string was shorter than 12 characters. + ## License -- cgit v1.2.3