Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,71 @@ console.log(functionThatReturnsArgument('foo'));
// 'foo'
```

## `empty.boolean` or `empty['boolean']`

```js
var booleanValue = empty.boolean; // or empty['boolean']

// or

var booleanValue = require('empty/boolean');

console.log(booleanValue);
// false
```

## `empty.null` or `empty['null']`

```js
var nullValue = empty.null; // or empty['null']

// or

var nullValue = require('empty/null');

console.log(nullValue);
// null
```

## `empty.number`

```js
var num = empty.number;

// or

var num = require('empty/number');

console.log(num);
// 0
```

## `empty.string`

```js
var str = empty.string;

// or

var str = require('empty/string');

console.log(str);
// ''
```

## `empty.undefined`

```js
var undef = empty.undefined;

// or

var undef = require('empty/undefined');

console.log(undef);
// undefined
```

# Credits

Many thanks to [Arturo](https://github.com/acstll) for the name on [NPM](https://www.npmjs.com/package/empty). The original package repository can be found at [here](https://github.com/acstll/empty).
3 changes: 3 additions & 0 deletions boolean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = false;
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ exports.functionThatReturnsFalse = require('./functionThatReturnsFalse');
exports.functionThatReturnsNull = require('./functionThatReturnsNull');
exports.functionThatReturnsThis = require('./functionThatReturnsThis');
exports.functionThatReturnsArgument = require('./functionThatReturnsArgument');
exports['boolean'] = require('./boolean');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use bracket notation for these?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean is probably a reserved word.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but reserved words can still be used as key in ES5 and up.
Also, importing/requiring these will cause a bit of a nuisance since you can’t do import {null} from 'empty'.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import {null as nullValue} from 'empty'

exports['null'] = require('./null');
exports.number = require('./number');
exports.string = require('./string');
exports.undefined = require('./undefined');

if ('production' != process.env.NODE_ENV) {
Object.freeze(exports);
Expand Down
3 changes: 3 additions & 0 deletions null.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = null;
3 changes: 3 additions & 0 deletions number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = 0;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "empty",
"version": "0.10.1",
"version": "0.11.0",
"description": "Utility that provides different types of empty objects.",
"keywords": [
"empty",
Expand Down
3 changes: 3 additions & 0 deletions string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = '';
3 changes: 3 additions & 0 deletions undefined.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = void 0;