Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
noamokman committed Jul 13, 2016
1 parent 0fd061a commit 50c5d37
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .editorconfig
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
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "noamokman"
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
node_modules
coverage
npm-debug.log
7 changes: 7 additions & 0 deletions .travis.yml
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
21 changes: 20 additions & 1 deletion README.md
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)
25 changes: 25 additions & 0 deletions appveyor.yml
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
3 changes: 3 additions & 0 deletions lib/index.js
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));
53 changes: 53 additions & 0 deletions package.json
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"
}
}
3 changes: 3 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "noamokman/test"
}
29 changes: 29 additions & 0 deletions test/main.spec.js
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);
});
});
});

0 comments on commit 50c5d37

Please sign in to comment.