UNPKG

3.12 kBMarkdownView Raw
1# Display Value
2
3> Converts values to a readable display string
4>
5> [![npm][npm]][npm-url]
6[![build][build]][build-url]
7[![deps][deps]][deps-url]
8[![size][size]][size-url]
9[![vulnerabilities][vulnerabilities]][vulnerabilities-url]
10[![license][license]][license-url]
11
12
13<br><a name="displayValue"></a>
14
15## displayValue(value, [settings]) ⇒ <code>string</code>
16> Designed for use in test messages, displayValue takes a javascript value and returns a human readable string representation of that value. > > Notes: > - finite numbers are passed through number.toLocaleString() > - -0 is rendered as -0 > - 1300 is rendered as 1,300 (depending on locale) > - strings are wrapped in double quotes > - Arrays and Objects are passed through a function similar to JSON.stringify, but values are individually run through displayValue > - Array-like values such as arguments are handled like Arrays > - Object-like values such as ClientRect and DOMRect are handled like Objects > - Constructors will return the constructor's name > - Instances of non-native constructors: > - will return the result of .toString() if other than '[object Object]' > - otherwise returns '[object Name]' where Name is the constructor's name
17
18
19| Param | Type | Default | Description |
20| --- | --- | --- | --- |
21| value | <code>\*</code> | | |
22| [settings] | <code>Object</code> | | |
23| [settings.beautify] | <code>Boolean</code> | <code>false</code> | If true and value is an Array or Object then the output is rendered in multiple lines with indentation |
24
25**Example**
26``` javascript import displayValue from 'display-value'; displayValue(-0); // '-0' displayValue(1300000); // '1,300,000' displayValue('foo'); // '"foo"' displayValue({x: 1}); // '{"x": 1}' displayValue(() => {}); // '() => {…}' displayValue(function(param) {}); // 'ƒ (param) {…}' displayValue(function name() {}); // 'ƒ name() {…}' displayValue(Symbol()); // 'Symbol()' displayValue(Symbol('name')); // 'Symbol(name)' displayValue(new CustomClass()); // '[object CustomClass]' displayValue([{x: 1}, {x: 2000}], {beautify: true}); // '[ // { // "x": 1 // }, { // "x": 2,000 // } // ]' ```
27
28[npm]: https://img.shields.io/npm/v/display-value.svg
29[npm-url]: https://npmjs.com/package/display-value
30[build]: https://travis-ci.org/DarrenPaulWright/display-value.svg?branch&#x3D;master
31[build-url]: https://travis-ci.org/DarrenPaulWright/display-value
32[deps]: https://david-dm.org/darrenpaulwright/display-value.svg
33[deps-url]: https://david-dm.org/darrenpaulwright/display-value
34[size]: https://packagephobia.now.sh/badge?p&#x3D;display-value
35[size-url]: https://packagephobia.now.sh/result?p&#x3D;display-value
36[vulnerabilities]: https://snyk.io/test/github/DarrenPaulWright/display-value/badge.svg?targetFile&#x3D;package.json
37[vulnerabilities-url]: https://snyk.io/test/github/DarrenPaulWright/display-value?targetFile&#x3D;package.json
38[license]: https://img.shields.io/github/license/DarrenPaulWright/display-value.svg
39[license-url]: https://npmjs.com/package/display-value/LICENSE.md