# utf8safe-js-stringify

> Generate JS(ON) code that re-creates a JS value (object, string, Date, …) as verbatim as possible on the other side of a UTF-8 stream.

Latest version **0.1.4** (published 2016-10-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install utf8safe-js-stringify
pnpm add utf8safe-js-stringify
yarn add utf8safe-js-stringify
bun add utf8safe-js-stringify
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2016-10-07 |
| First published | 2016-10-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | M.K. |
| Maintainers | mk-pmb |
| Keywords | js-stringify, stringify, unicode, UTF-8 |

## Links

- npm: https://www.npmjs.com/package/utf8safe-js-stringify
- Repository: https://github.com/mk-pmb/utf8safe-js-stringify-js
- Homepage: https://github.com/mk-pmb/utf8safe-js-stringify-js#readme
- Issues: https://github.com/mk-pmb/utf8safe-js-stringify-js/issues
- npm.io page: https://npm.io/package/utf8safe-js-stringify

## Dependencies (2)

- [js-stringify](https://npm.io/package/js-stringify.md) ^1.0.2
- [utf8safe-uhex](https://npm.io/package/utf8safe-uhex.md) ^1.0.1

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.1.4 (latest) — 2016-10-07
- 0.1.3 — 2016-10-07
- 0.1.2 — 2016-10-07

## README

<!--#echo json="package.json" key="name" underline="=" -->
utf8safe-js-stringify
=====================
<!--/#echo -->

<!--#echo json="package.json" key="description" -->
Generate JS(ON) code that re-creates a JS value (object, string, Date, …) as
verbatim as possible on the other side of a UTF-8 stream.
<!--/#echo -->


The problem: silent data loss
-----------------------------

Some UCS-2 characters cannot be encoded as UTF-8.
When you try to send them over a stream with UTF-8 encoding,
they will usually [be replaced with U+FFFD](test.js) without warning.
After conversion they all look the same,
so this loss of data is irreversible.

A perfect trap setup for sneaky bugs:
As long as all your data is UTF-8, you won't notice this problem.
When you do, maybe because some `.substr()` has split a surrogate pair,
you'll probably dump the "buggy" data over yet another UTF-8 stream,
see U+FFFD, and think it's really about the data.
(Assuming you forgot above lecture by then.)
After all, your browser (or file or whatever) received exactly
the same bytes that were in your debug dump, so you go examine
your data sources…

### Are your programs at risk?

Popular UTF-8 streams include nodejs's `stdin`, `stdout`, `stderr` and
thus `console` in default config. Also its `fs`, `net`, `http` and `https`
modules by default use UTF-8 for their streams.



Usage
-----
Same as [js-stringify](https://github.com/pugjs/js-stringify).

This module really just escapes UTF-8-incompatible characters
(and verbatim U+FFFD) from `js-stringify`'s output:

```javascript
module.exports = require('utf8safe-uhex').conv(require('js-stringify'));
```




<!--#toc stop="scan" -->


License
-------
<!--#echo json="package.json" key=".license" -->
ISC
<!--/#echo -->

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