# quick-format

> Solves a problem with util.format

Latest version **2.1.0** (published 2017-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install quick-format
pnpm add quick-format
yarn add quick-format
bun add quick-format
```

## 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.1.0 |
| Published | 2017-03-13 |
| First published | 2016-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | David Mark Clements |
| Maintainers | davidmarkclements |

## Links

- npm: https://www.npmjs.com/package/quick-format
- Repository: https://github.com/davidmarkclements/quick-format
- Homepage: https://github.com/davidmarkclements/quick-format#readme
- Issues: https://github.com/davidmarkclements/quick-format/issues
- npm.io page: https://npm.io/package/quick-format

## Dependencies (1)

- [fast-safe-stringify](https://npm.io/package/fast-safe-stringify.md) ^1.0.8

## Recent versions

- 2.1.0 (latest) — 2017-03-13
- 2.0.6 — 2016-10-14
- 2.0.5 — 2016-10-14
- 2.0.4 — 2016-04-11
- 2.0.3 — 2016-04-06
- 2.0.2 — 2016-04-05
- 2.0.1 — 2016-04-05
- 2.0.0 — 2016-03-21
- 1.0.1 — 2016-03-19
- 1.0.0 — 2016-03-19

## README

# quick format

Solves a problem with util.format

## usage

```js
var format = require('quick-format')
var options = {lowres: false} // <--default
format(['hello %s %j %d', 'world', {obj: true}, 4, {another: 'obj'}], options)
```

## options

### lowres

Passing an options object with `lowres: true` will cause quick-format any object with a circular as a string with the value '"[Circular]"'. The default behaviour is to label
circular references in an object, instead of abandoning the entire object. Naturally, 
`lowres` is a faster mode, and assumes you have made the decision to ensure the objects
you're passing have no circular references.

## caveats

We use `JSON.stringify` instead of `util.inspect`, this means object
methods (functions) *will not be serialized*.

##  util.format

In `util.format` for Node 5.9, performance is significantly affected
when we pass in more arguments than interpolation characters, e.g

```js
util.format('hello %s %j %d', 'world', {obj: true}, 4, {another: 'obj'})
```

This is mostly due to the use of `util.inspect`. Use `JSON.stringify`
(safely) instead which is significantly faster. 

It also takes an array instead of arguments, which helps us 
avoid the use of `apply` in some cases.

Also - for speed purposes, we ignore symbol.

## Benchmarks

Whilst exact matching of objects to interpolation characters is slower,
the case of additional objects is 3x faster. Further, using `lowres` mode
brings us closer to `util.inspect` speeds.

```
util*100000: 205.978ms
quickLowres*100000: 236.337ms
quick*100000: 292.018ms
utilWithTailObj*100000: 1054.592ms
quickWithTailObjLowres*100000: 267.992ms
quickWithTailObj*100000: 343.048ms
util*100000: 212.011ms
quickLowres*100000: 226.441ms
quick*100000: 296.600ms
utilWithTailObj*100000: 1020.195ms
quickWithTailObjLowres*100000: 267.331ms
quickWithTailObj*100000: 343.867ms
```

## Acknowledgements

Sponsored by nearForm

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