Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
gluons committed Dec 3, 2016
1 parent be38dcf commit 19e9caa
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
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
35 changes: 35 additions & 0 deletions .eslintrc.json
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"
}
74 changes: 74 additions & 0 deletions .gitignore
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

26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# NVL
[![license](https://img.shields.io/github/license/gluons/NVL.svg?style=flat-square)](https://github.com/gluons/NVL/blob/master/LICENSE)
[![npm](https://img.shields.io/npm/v/nvl.svg?style=flat-square)](https://www.npmjs.com/package/nvl)
[![npm](https://img.shields.io/npm/dt/nvl.svg?style=flat-square)](https://www.npmjs.com/package/nvl)
[![Travis](https://img.shields.io/travis/gluons/NVL.svg?style=flat-square)](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
```
5 changes: 5 additions & 0 deletions index.js
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;
};
27 changes: 27 additions & 0 deletions package.json
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": "*"
}
}
26 changes: 26 additions & 0 deletions test/tests.js
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);
});
});
Loading

0 comments on commit 19e9caa

Please # to comment.