-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
395 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
indent_size = 4 | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[{*.{coffee,cson,yml,yaml,jade,pug},package.json,bower.json}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"parserOptions": { | ||
"ecmaVersion": 6 | ||
}, | ||
"rules": { | ||
"indent": [ | ||
"warn", | ||
"tab", | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"linebreak-style": "off", | ||
"semi": [ | ||
"error", | ||
"always" | ||
], | ||
"no-unused-vars": "warn", | ||
"no-console": "off", | ||
"no-redeclare": "warn", | ||
"space-before-function-paren": "off", | ||
"space-infix-ops": [ | ||
"error", | ||
{ | ||
"int32Hint": false | ||
} | ||
] | ||
}, | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"extends": "eslint:recommended" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
# Created by https://www.gitignore.io/api/node,windows | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
|
||
|
||
### Windows ### | ||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# NVL | ||
[](https://github.com/gluons/NVL/blob/master/LICENSE) | ||
[](https://www.npmjs.com/package/nvl) | ||
[](https://www.npmjs.com/package/nvl) | ||
[](https://travis-ci.org/gluons/NVL) | ||
|
||
🚮 Replace a blank value with your value. | ||
|
||
## Installation | ||
``` | ||
npm install nvl | ||
``` | ||
|
||
## Usage | ||
```javascript | ||
const nvl = require('nvl'); | ||
|
||
let notYet = void 0; // undefined | ||
let nil = null; | ||
|
||
nvl(notYet, true); // -> true | ||
nvl(nil, 1); // -> 1 | ||
nvl([], [1]); // -> [] | ||
nvl({}, { a: 1, b: 2}); // -> {} | ||
nvl(false, true); // -> false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = function nvl(value, replaceWith) { | ||
return (typeof value !== 'undefined') && (value != null) ? value : replaceWith; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "nvl", | ||
"version": "1.0.0", | ||
"description": "Replace a blank value with your value.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/gluons/NVL.git" | ||
}, | ||
"keywords": [ | ||
"nvl", | ||
"null", | ||
"undefined" | ||
], | ||
"author": "Saran Tanpituckpong <sarunta@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/gluons/NVL/issues" | ||
}, | ||
"homepage": "https://github.com/gluons/NVL", | ||
"devDependencies": { | ||
"mocha": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const nvl = require('../'); | ||
|
||
describe('NVL', () => { | ||
it('shoud return `value` when `value` is not blank value', () => { | ||
let now = new Date(); | ||
let emptyArr = []; | ||
let emptyObj = {}; | ||
assert.strictEqual(nvl(now, new Date(0)), now); | ||
assert.strictEqual(nvl(emptyArr, [1]), emptyArr); | ||
assert.strictEqual(nvl(emptyObj, { a: 1, b: 2}), emptyObj); | ||
assert.strictEqual(nvl(false, true), false); | ||
}); | ||
it('shoud return `replaceWith` when `value` is undefined.', () => { | ||
let notYet = void 0; | ||
let now = new Date(); | ||
assert.strictEqual(nvl(notYet, now), now); | ||
}); | ||
it('shoud return `replaceWith` when `value` is null.', () => { | ||
let nil = null; | ||
let now = new Date(); | ||
assert.strictEqual(nvl(nil, now), now); | ||
}); | ||
}); |
Oops, something went wrong.