-
Notifications
You must be signed in to change notification settings - Fork 3
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
0 parents
commit 8fbf483
Showing
22 changed files
with
1,038 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,12 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: process.env.NODE_ENV === 'test' && 'commonjs', | ||
targets: {node: '4'}, | ||
}, | ||
], | ||
'@babel/preset-flow', | ||
], | ||
}; |
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,88 @@ | ||
jobs: | ||
|
||
lint: | ||
docker: | ||
- image: circleci/node:8 | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
- v1-dependencies- | ||
- run: yarn install | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
- run: yarn lint | ||
working_directory: ~/repo | ||
|
||
release: | ||
docker: | ||
- image: circleci/node:8 | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
- v1-dependencies- | ||
- run: yarn install | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
- run: yarn build | ||
- run: npx semantic-release | ||
|
||
test: | ||
docker: | ||
- image: circleci/node:8 | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
- v1-dependencies- | ||
- run: yarn install | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
- run: yarn test:src | ||
working_directory: ~/repo | ||
|
||
test-dist: | ||
docker: | ||
- image: circleci/node:8 | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
- v1-dependencies- | ||
- run: yarn install | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
- run: yarn build | ||
- run: yarn test:dist | ||
working_directory: ~/repo | ||
|
||
version: 2 | ||
|
||
workflows: | ||
test_and_release: | ||
jobs: | ||
- lint | ||
- test | ||
- test-dist | ||
- release: | ||
filters: | ||
branches: | ||
only: master | ||
requires: | ||
- lint | ||
- test | ||
- test-dist | ||
version: 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,2 @@ | ||
extends: | ||
- '@commitlint/config-conventional' |
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 @@ | ||
coverage/* | ||
dist/* | ||
flow-typed/* | ||
node_modules/* |
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,19 @@ | ||
env: | ||
jest: true | ||
|
||
extends: | ||
- airbnb-base | ||
- plugin:flowtype/recommended | ||
- prettier | ||
- prettier/flowtype | ||
|
||
parser: babel-eslint | ||
|
||
plugins: | ||
- flowtype | ||
|
||
rules: | ||
import/no-extraneous-dependencies: | ||
- error | ||
- devDependencies: | ||
- scripts/** |
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,11 @@ | ||
[ignore] | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[lints] | ||
|
||
[options] | ||
|
||
[strict] |
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,6 @@ | ||
coverage | ||
dist | ||
node_modules | ||
yarn.lock | ||
yarn-debug.log* | ||
yarn-error.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,3 @@ | ||
hooks: | ||
commit-msg: commitlint -e $HUSKY_GIT_PARAMS | ||
pre-commit: flow && lint-staged |
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 @@ | ||
linters: | ||
"*.{json,md}": ["prettier --write", "git add"] | ||
"*.{js}": ["prettier --write", "eslint --fix", "git add", "jest --config ./scripts/jest/config.source.js --bail --findRelatedTests"] |
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 @@ | ||
package.json |
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 @@ | ||
bracketSpacing: false | ||
singleQuote: true | ||
trailingComma: all |
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,9 @@ | ||
MIT License | ||
|
||
Copyright (c) Matthew Fernando Garcia <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,58 @@ | ||
# sole-entry | ||
|
||
> Assert a Map has a given key and return the value for it. | ||
Pretty much just `map.get(key)`, but throws if `key` isn't there. | ||
|
||
## Install | ||
|
||
``` | ||
$ yarn add get-certain | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
const getCertain = require('get-certain'); | ||
|
||
const map = new Map(); | ||
|
||
map.set('foo', 1); | ||
|
||
// Returns 1. | ||
getCertain(map, 'foo'); | ||
|
||
// This throws. | ||
getCertain(map, 'bar'); | ||
|
||
// This throws with a custom message. | ||
getCertain(map, 'bar', 'This map is barless.'); | ||
``` | ||
|
||
## API | ||
|
||
### getCertain(map, key, [message]) | ||
|
||
Returns the value from `map` for `key`, or throws if it is not there. | ||
|
||
#### map | ||
|
||
* Type: `Map` | ||
|
||
A Map. I hope you know what you're putting in there. | ||
|
||
#### key | ||
|
||
* Type: `any` | ||
|
||
A key that is hopefully in `map`. | ||
|
||
#### message | ||
|
||
* Type: `string` | ||
|
||
An optional message to throw. Defaults to '"map" does not have an entry for "key".', which isn't terribly descriptive. | ||
|
||
## License | ||
|
||
MIT © Matthew Fernando Garcia |
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,39 @@ | ||
// flow | ||
import getCertain from '../src'; | ||
|
||
describe('getCertain', () => { | ||
describe('invariants', () => { | ||
it('throws if "map" is undefined.', () => { | ||
expect(() => getCertain()).toThrow('"map" must be a Map.'); | ||
}); | ||
it('throws if "map" is not a Map-like object.', () => { | ||
expect(() => getCertain({has: 3})).toThrow('"map" must be a Map.'); | ||
}); | ||
it('throws if "message" is not a string or undefined.', () => { | ||
expect(() => getCertain(new Map(), 1, 1)).toThrow( | ||
'"message" must be a string or undefined.', | ||
); | ||
}); | ||
}); | ||
|
||
it('returns the value for the given key.', () => { | ||
const map = new Map(); | ||
const key = 'Some key.'; | ||
const value = 'Some value.'; | ||
map.set(key, value); | ||
expect(getCertain(map, key)).toEqual(value); | ||
}); | ||
|
||
it('throws with the default message if no "message" is provided and "key" is not present.', () => { | ||
const map = new Map(); | ||
expect(() => getCertain(map, 'Some key.')).toThrow( | ||
'"map" does not have an entry for "key".', | ||
); | ||
}); | ||
|
||
it('throws with "message" if provided and "key" is not present.', () => { | ||
const map = new Map(); | ||
const message = 'Some custom message.'; | ||
expect(() => getCertain(map, 'Some key.', message)).toThrow(message); | ||
}); | ||
}); |
Oops, something went wrong.