# stringify-object-es5

> Stringify an object/array like JSON.stringify just without all the double-quotes (ES5 compatible)

Latest version **2.5.0** (published 2017-03-12) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install stringify-object-es5
pnpm add stringify-object-es5
yarn add stringify-object-es5
bun add stringify-object-es5
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.5.0 |
| Published | 2017-03-12 |
| First published | 2017-03-12 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Justin Searls |
| Maintainers | searls |
| Keywords | object, stringify, pretty, print, dump, format, type, json |

## Links

- npm: https://www.npmjs.com/package/stringify-object-es5
- Repository: https://github.com/searls/stringify-object
- Homepage: https://github.com/searls/stringify-object#readme
- Issues: https://github.com/searls/stringify-object/issues
- npm.io page: https://npm.io/package/stringify-object-es5

## Dependencies (2)

- [is-regexp](https://npm.io/package/is-regexp.md) ^1.0.0
- [is-plain-obj](https://npm.io/package/is-plain-obj.md) ^1.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.5.0 (latest) — 2017-03-12

## README

# stringify-object [![Build Status](https://secure.travis-ci.org/searls/stringify-object.svg?branch=master)](http://travis-ci.org/searls/stringify-object)

**This fork of [yeoman/stringify-object](https://github.com/yeoman/stringify-object) is ES5 compatible**

> 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.

It also handles circular references and lets you specify quote type.


## Install

```
$ npm install --save stringify-object
```


## Usage

```js
var obj = {
	foo: 'bar',
	'arr': [1, 2, 3],
	nested: { hello: "world" }
};

var pretty = stringifyObject(obj, {
	indent: '  ',
	singleQuotes: false
});

console.log(pretty);
/*
{
	foo: "bar",
	arr: [
		1,
		2,
		3
	],
	nested: {
		hello: "world"
	}
}
*/
```


## API

### stringifyObject(input, [options])

Circular references will be replaced with `"[Circular]"`.

#### input

*Required*  
Type: `object`, `array`

#### options

##### indent

Type: `string`  
Default: `'\t'`

Choose the indentation you prefer.

##### singleQuotes

Type: `boolean`  
Default: `true`

Set to false to get double-quoted strings.

##### filter(obj, prop)

Type: `function`

Expected to return a boolean of whether to keep the object.

##### transform(obj, prop, originalResult)

Type: `Function`<br>
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: function (obj, prop, originalResult) {
		if (prop === 'password') {
			return originalResult.replace(/\w/g,'*');
		} else {
			return originalResult;
		}
	}
});

console.log(pretty);
/*
{
	user: 'becky',
	password: '******'
}
*/
```


##### inlineCharacterLimit

Type: `number`
Default: undefined

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 = {
	foo: 'bar',
	'arr': [1, 2, 3],
	nested: { hello: "world" }
};

var pretty = stringifyObject(obj, {
	indent: '  ',
	singleQuotes: false,
	inlineCharacterLimit: 12
});

console.log(pretty);
/*
{
	foo: "bar",
	arr: [1, 2, 3],
	nested: {
		hello: "world"
	}
}
*/
```

As you can see, `arr` was printed as a one-liner because its string was shorter
than 12 characters.

## License

[BSD license](http://opensource.org/licenses/bsd-license.php) © Yeoman Team

---
_Source: https://npm.io/package/stringify-object-es5 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
