-
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
10 changed files
with
168 additions
and
1 deletion.
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,21 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
|
||
[*] | ||
|
||
# Change these settings to your own preference | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
# We recommend you to keep these unchanged | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = false | ||
|
||
[*.md] | ||
trim_trailing_whitespace = 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,3 @@ | ||
{ | ||
"extends": "noamokman" | ||
} |
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,4 @@ | ||
.idea | ||
node_modules | ||
coverage | ||
npm-debug.log |
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,7 @@ | ||
language: node_js | ||
node_js: | ||
- '4' | ||
- '5' | ||
- '6' | ||
after_script: | ||
- npm run coveralls |
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 |
---|---|---|
@@ -1,2 +1,21 @@ | ||
# http-reject-empty | ||
# http-reject-empty [![Build Status](https://travis-ci.org/noamokman/http-reject-empty.svg?branch=master)](https://travis-ci.org/noamokman/http-reject-empty) [![Coverage Status](https://coveralls.io/repos/github/noamokman/http-reject-empty/badge.svg?branch=master)](https://coveralls.io/github/noamokman/http-reject-empty?branch=master) | ||
A function to reject empty values with an http exception | ||
|
||
## Install | ||
|
||
``` | ||
$ npm install --save http-reject-empty | ||
``` | ||
|
||
## Usage | ||
```js | ||
const empty = require('http-reject-empty'); | ||
|
||
const promise = User.find({}) // find a user in the db | ||
.then(empty); | ||
``` | ||
If the promise returns a [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) value, the promise is rejected with a 404 [http error](https://github.com/jshttp/http-errors) | ||
|
||
## License | ||
|
||
[MIT](LICENSE) © [Noam Okman](https://github.com/noamokman) |
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,25 @@ | ||
|
||
# Test against these versions of Io.js and Node.js. | ||
environment: | ||
matrix: | ||
- nodejs_version: "4" | ||
- nodejs_version: "5" | ||
- nodejs_version: "6" | ||
|
||
# Install scripts. (runs after repo cloning) | ||
install: | ||
# Get the latest stable version of Node.js or io.js | ||
- ps: Install-Product node $env:nodejs_version | ||
# install modules | ||
- npm install | ||
|
||
# Post-install test scripts. | ||
test_script: | ||
# Output useful info for debugging. | ||
- node --version | ||
- npm --version | ||
# run tests | ||
- npm test | ||
|
||
# Don't actually build. | ||
build: off |
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,3 @@ | ||
const createError = require('http-errors'); | ||
|
||
module.exports = result => result || Promise.reject(createError(404)); |
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,53 @@ | ||
{ | ||
"name": "http-reject-empty", | ||
"version": "0.0.1", | ||
"description": "A function to reject empty values with an http exception", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"lint": "npm run lint-lib && npm run lint-test", | ||
"lint-lib": "eslint lib --fix", | ||
"lint-test": "eslint test --fix", | ||
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
"test": "npm run lint && istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly --report text --report html -- test", | ||
"posttest": "istanbul check-coverage --statements 100 --functions 100 --branches 100 --lines 100" | ||
}, | ||
"config": { | ||
"ghooks": { | ||
"pre-commit": "npm run lint" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/noamokman/http-reject-empty" | ||
}, | ||
"keywords": [ | ||
"empty", | ||
"promise", | ||
"reject", | ||
"http", | ||
"404" | ||
], | ||
"author": { | ||
"name": "Noam Okman", | ||
"email": "noamokman@gmail.com", | ||
"url": "https://github.com/noamokman" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/noamokman/http-reject-empty/issues" | ||
}, | ||
"homepage": "https://github.com/noamokman/http-reject-empty", | ||
"dependencies": { | ||
"http-errors": "^1.5.0" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^6.1.2", | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.3.0", | ||
"coveralls": "^2.11.9", | ||
"eslint": "^3.0.1", | ||
"eslint-config-noamokman": "^2.1.1", | ||
"istanbul": "^0.4.4", | ||
"mocha": "^2.5.3" | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"extends": "noamokman/test" | ||
} |
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,29 @@ | ||
const chai = require('chai'); | ||
const chaiAsPromised = require('chai-as-promised'); | ||
const expect = chai.expect; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe('http-reject-empty', () => { | ||
const empty = require('../lib'); | ||
|
||
describe('exports', () => { | ||
it('should expose a function', () => { | ||
expect(empty).to.be.a('function'); | ||
}); | ||
}); | ||
|
||
describe('with empty input', () => { | ||
it('should return a rejected promise', () => { | ||
expect(empty()).to.eventually.be.rejectedWith(Error); | ||
}); | ||
}); | ||
|
||
describe('with valid input', () => { | ||
it('should return given value', () => { | ||
const x = Math.random(); | ||
|
||
expect(empty(x)).to.equal(x); | ||
}); | ||
}); | ||
}); |