Skip to content

Commit

Permalink
Clean up inlined inspect-with-kind implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Dec 4, 2019
1 parent 742e613 commit 516035a
Show file tree
Hide file tree
Showing 7 changed files with 1,300 additions and 279 deletions.
8 changes: 0 additions & 8 deletions lib/inspect-with-kind/.travis.yml

This file was deleted.

28 changes: 12 additions & 16 deletions lib/inspect-with-kind/README.md
@@ -1,13 +1,13 @@
# inspect-with-kind

[![npm version](https://img.shields.io/npm/v/inspect-with-kind.svg)](https://www.npmjs.com/package/inspect-with-kind)
[![Build Status](https://travis-ci.org/shinnn/inspect-with-kind.svg?branch=master)](https://travis-ci.org/shinnn/inspect-with-kind)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/inspect-with-kind.svg)](https://coveralls.io/github/shinnn/inspect-with-kind?branch=master)
> 🚧 Inlined dependency taken from [https://github.com/shinnn/inspect-with-kind](https://github.com/shinnn/inspect-with-kind).
---

[`util.inspect`][util.inspect] with additional type information

```javascript
const {inspect} = require('util');
const { inspect } = require('util');
const inspectWithKind = require('inspect-with-kind');

inspect([1, 2, 3]); //=> '[ 1, 2, 3 ]'
Expand All @@ -18,7 +18,7 @@ inspectWithKind([1, 2, 3]); //=> '[ 1, 2, 3 ] (array)'

[Use npm.](https://docs.npmjs.com/cli/install)

```
```sh
npm install inspect-with-kind
```

Expand All @@ -28,18 +28,18 @@ npm install inspect-with-kind
const inspectWithKind = require('inspect-with-kind');
```

### inspectWithKind(*value* [, *options*])
### inspectWithKind(_value_ [, *options*])

*value*: any type
*options*: `Object` ([`util.inspect`][util.inspect] options)
_value_: any type
_options_: `Object` ([`util.inspect`][util.inspect] options)
Return: `string`

Almost the same as `util.inspect`, but:

* It appends a type information to the string if the first argument is one of `boolean`, `string`, `number`, `bigint`, `Array`, `RegExp`, `Date`, `arguments` or a plain `Object`.
* Error stack trace is omitted.
* `breakLength` option defaults to `Infinity`.
* `maxArrayLength` option defaults to `10`.
- It appends a type information to the string if the first argument is one of `boolean`, `string`, `number`, `bigint`, `Array`, `RegExp`, `Date`, `arguments` or a plain `Object`.
- Error stack trace is omitted.
- `breakLength` option defaults to `Infinity`.
- `maxArrayLength` option defaults to `10`.

```javascript
const util = require('util');
Expand Down Expand Up @@ -82,8 +82,4 @@ const reverse = require('./reverse.js');
reverse(/true/); // TypeError: Expected a Boolean value, but got /true/ (regexp).
```

## License

[ISC License](./LICENSE) © 2017 Shinnosuke Watanabe

[util.inspect]: https://nodejs.org/api/util.html#util_util_inspect_object_options
3 changes: 3 additions & 0 deletions lib/inspect-with-kind/index.js
Expand Up @@ -16,6 +16,9 @@ const appendedKinds = new Set([
'string'
]);

/*
* `util.inspect` with additional type information
*/
module.exports = function inspectWithKind(val, options) {
const kind = kindOf(val);
const stringifiedVal = inspect(val, Object.assign({ // eslint-disable-line prefer-object-spread
Expand Down
43 changes: 0 additions & 43 deletions lib/inspect-with-kind/package.json

This file was deleted.

8 changes: 4 additions & 4 deletions lib/inspect-with-kind/test.js
Expand Up @@ -31,7 +31,7 @@ test('inspectWithKind()', t => {

t.equal(
inspectWithKind(Array.from({length: 30}, (v, k) => k)),
'[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... 20 more items ] (array)',
'[\n 0, 1, 2, 3, 4,\n 5, 6, 7, 8, 9,\n ... 20 more items\n] (array)',
'should append type when it takes an array.'
);

Expand Down Expand Up @@ -87,7 +87,7 @@ test('inspectWithKind()', t => {

t.equal(
inspectWithKind(async () => {}),
'[AsyncFunction]',
'[AsyncFunction (anonymous)]',
'should not append type when it takes an async function.'
);

Expand Down Expand Up @@ -123,13 +123,13 @@ test('inspectWithKind()', t => {

t.equal(
inspectWithKind(Promise.resolve(new WeakMap())),
'Promise { WeakMap { [items unknown] } }',
'Promise { WeakMap { <items unknown> } }',
'should not append type when it takes a Promise.'
);

t.equal(
inspectWithKind(new Observable(() => {})),
'Observable { _subscriber: [Function] }',
'Observable { _subscriber: [Function (anonymous)] }',
'should not append type when it takes an Observable.'
);

Expand Down

0 comments on commit 516035a

Please sign in to comment.