# object-plain-string

> Convert javascript objects into strings

Latest version **1.0.4** (published 2017-10-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install object-plain-string
pnpm add object-plain-string
yarn add object-plain-string
bun add object-plain-string
```

## 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 | 1.0.4 |
| Published | 2017-10-06 |
| First published | 2017-09-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Alexandru Cambose |
| Maintainers | alexcambose |
| Keywords | object, string, convert, JSON |

## Links

- npm: https://www.npmjs.com/package/object-plain-string
- Repository: https://github.com/alexcambose/object-plain-string
- Homepage: https://github.com/alexcambose/object-plain-string#readme
- Issues: https://github.com/alexcambose/object-plain-string/issues
- npm.io page: https://npm.io/package/object-plain-string

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

- 1.0.4 (latest) — 2017-10-06
- 1.0.3 — 2017-10-01
- 1.0.2 — 2017-09-29
- 1.0.1 — 2017-09-29
- 1.0.0 — 2017-09-29

## README

[![Build Status via Travis CI](https://travis-ci.org/alexcambose/object-plain-string.svg?branch=master)](https://travis-ci.org/alexcambose/object-plain-string)

# object-plain-string
Convert javascript objects into strings

## Installation
```
npm i -S object-plain-string
```
[npm](https://www.npmjs.com/package/object-plain-string)

## Usage

```js
const convert = require('object-plain-string');

const obj = {
  key1: "Value for key1",
  key2: "Value for key2",
  key3: {
      key31: "Value for key31",
      key32: "Value for key32",
  }
};

const result = convert(obj);
console.log(result);
/*
"{
    key1: 'Value for key1',
    key2: 'Value for key2',
    key3: {
        key31: 'Value for key31',
        key32: 'Value for key32',
    },
},"
*/
```

```js
const convert = require('object-plain-string');
const obj = {
    key1: 'This is key1',
    key2: 'This is key2',
    integer: 123,
    boolean: true,
    array: [1,2,3,4],
    func: function (){
        //comment
        console.log('this is a function');
    },
    object: {
        deep1: 'This is deep1',
        deep2: 'This is deep2'
    },
    regex: /.css$/,
    _undefined: undefined,
    _null: null,
}

const result = convert(obj);
console.log(result);
/*
"{
    key1: 'This is key1',
    key2: 'This is key2',
    integer: 123,
    boolean: true,
    array: [1,2,3,4,],
    func: function (){
        //comment
        console.log('this is a function');
    },
    object: {
        deep1: 'This is deep1',
        deep2: 'This is deep2',
    },
    regex: /.css$/,
    _null: null,
}"
*/
```

`undefined` object key values will be ignored and `null` will be kept

```js
const obj = {
  undefinedValue: undefined,
  nullValue: null
};

const result = convert(obj);
console.log(result);
/*
"{
  nullValue: null,
}"
*/
```


### Why would you use `object-plain-string` instead of `JSON.stringify`?
Well, it depends on what you want to achieve, for example if you want to write javascript config files you may want to use `object-plain-string` instead of `JSON.stringify`.

#### `JSON.stringify` vs `object-plain-string`
```js
const convert = require('object-plain-string');

const obj = {
    a: 'Some text',
    b: ()=>{
        console.log('something');
    },
    c: [1,2,{a:'Something'},3,4]
};

console.log(JSON.stringify(obj));
/*
{
    "a":"Some text",
    "c":[1,2,{"key":"Something"},3,4]
}.

*/

console.log(convert(obj));
/*
"{
    a: 'Some text',
    b: ()=>{
        console.log('something');
    }
    c: [1,2,{
        key: 'Something',
    },3,4,],
},"

*/

```

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