An open API service indexing awesome lists of open source software.

https://github.com/corocoto/conversify

npm-package that represents an advanced implementation of JSON.stringify method
https://github.com/corocoto/conversify

convert json string stringify

Last synced: about 1 month ago
JSON representation

npm-package that represents an advanced implementation of JSON.stringify method

Awesome Lists containing this project

README

          

# [conversify](https://www.npmjs.com/package/conversify)

[![Tests CI](https://github.com/corocoto/conversify/workflows/Test/badge.svg)](https://github.com/corocoto/conversify/actions)
![NPM bundle size](https://img.shields.io/bundlephobia/min/conversify?style=flat-square)
![NPM bundle size (minzip)](https://img.shields.io/bundlephobia/minzip/conversify?style=flat-square)
![GitHub repo size](https://img.shields.io/github/repo-size/corocoto/conversify?style=flat-square)
![GitHub package.json version](https://img.shields.io/github/package-json/v/corocoto/conversify?style=flat-square)
![npm downloads](https://img.shields.io/npm/dt/conversify?style=flat-square)
![License](https://img.shields.io/npm/l/conversify?style=flat-square)

## Description

**conversify** is a package that represents an advanced implementation of `JSON.stringify` method.

It allows you to convert JSON unsupported values to string correctly.

Such as `Date` value, `+/-Infinity`, `undefined`, `NaN` and function realization in `Array` or `Object`.

## Installation

```
npm install conversify
```

## Example of using

```js
const conversify = require('conversify');

const stringifiedObj = conversify({
name: 'Ivan',
surname: 'Ivanov',
fullname() {
return `${this.name} ${this.surname}`
},
birthday: new Date('1999-05-02')
}, 4); //Second argument is optional. It used to insert white space into the output JSON string for readability purposes.
console.log(stringifiedObj);

/*
* Output:
* {
* "name": "Ivan",
* "surname": "Ivanov",
* "fullname": function () {
* return `${this.name} ${this.surname}`;
* },
* "birthday": new Date('1999-05-02T00:00:00.000Z')
* }
*/
```

## Comparison

Array that will be used for comparison two methods (`JSON.strinigfy` and `conversify`):

```js
const testArr = [
NaN,
undefined,
null,
new Date(),
Date(),
new Date('2020-02-01'),
new Date('abcd'),
'some text',
3.14,
15845,
-Infinity,
Infinity,
() => console.log(`It's function body`),
{
name: 'Ivan',
surname: 'Ivanov',
fullname () {
return `${this.name} ${this.surname}`;
},
birthday: new Date('1999-05-02'),
},
];
```

**Result**:

| `JSON.stringify` | `conversify` |
|------------------|--------------|
| convert array using JSON.stringify | convert array using conversify package |

## License

**conversify** package is open-sourced software licensed under the MIT License (MIT). Please see [License File](LICENSE) for more information.

## Changelog

Detailed changes for each release are documented in the [release notes](CHANGELOG.md).

## Contributing

I'm thanks all the people who contributed or who want to contribute to **conversify**.

If you want to contribute, make sure that read the [Contributing Guide](CONTRIBUTING.md) before making a pull request, thanks.

## Conclusion

If you still have questions about the work of this package :grey_question: or you have cool ideas for it improvement :boom:, please write to me :email:.

If you find a bug :bug:, please create an appropriate issue with detailed information about it :speech_balloon:.

Thanks!