Skip to content

Commit e9e89a6

Browse files
author
caian-gums
authored
Merge pull request #1 from codevor/build
Build 0.1.0
2 parents e5eb088 + 5b43228 commit e9e89a6

19 files changed

+260
-38
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Codevor - js-library-boilerplate
3+
Copyright (c) 2019 Codevor - js-is-type
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+31-16
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,49 @@
1-
# js-library-boilerplate
1+
# 🎯Type-checking for 'Primitive' JS Types
22

33
[![License][license-badge]][license-url] [![Travis CI][travis-badge]][travis-url] [![Coverage Status][coverage-badge]][coverage-url] [![Commitizen][commitizen-badge]][commitizen-url]
44

5-
> js-library-boilerplate-description.
5+
Type-check for 'Primitive' types in JavaScript are always something to take care when receiving/sending a payload from/to Server/Client application. If you ever wonder how to do this you can sure use `typeof` and make the check by yourself. Or you can user 🎯`js-is-type`!
6+
7+
The usage is simple and verbose. The tests has full coverage and you can use without a doubt.
8+
9+
## Available Types
10+
11+
- `isArray()`
12+
- `isBoolean()`
13+
- `isFunction()`
14+
- `isObject()` (_Remember: in JS, Arrays are Objects!_)
15+
- `isString()`
16+
- `isUndefined()`
617

718
## Installation
819

9-
js-library-boilerplate is available on npm/yarn:
20+
`js-is-type` is available on npm/yarn:
1021

1122
```bash
12-
$ npm install js-library-boilerplate --save
13-
$ yarn add js-library-boilerplate
23+
$ npm install @codevor/js-is-type --save
24+
$ yarn add @codevor/js-is-type
1425
```
1526

1627
## Usage
1728

1829
### With ES6/import
1930

2031
```js
21-
import { sum } from 'js-library-boilerplate';
32+
import { isArray } from '@codevor/js-is-type';
2233

23-
sum(2, 2); // => 4
34+
const names = ['Alice', 'Bob'];
35+
36+
isArray(names); // => true
2437
```
2538

2639
### With require
2740

2841
```js
29-
const sum = require('js-library-boilerplate').sum;
42+
const isArray = require('@codevor/js-is-type').isArray;
43+
44+
const names = ['Alice', 'Bob'];
3045

31-
sum(2, 2); // => 4
46+
isArray(names); // => true
3247
```
3348

3449
## Contributing
@@ -37,21 +52,21 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
3752

3853
## Changelog
3954

40-
This project adheres to [Semantic Versioning](https://semver.org/). Every release, along with the migration instructions, is documented on the Github [Releases](https://github.com/codevor/js-library-boilerplate/releases) page.
55+
This project adheres to [Semantic Versioning](https://semver.org/). Every release, along with the migration instructions, is documented on the Github [Releases](https://github.com/codevor/js-is-type/releases) page.
4156

4257
## Bugs and Sugestions
4358

44-
Report bugs or do suggestions using the [issues](https://github.com/codevor/js-library-boilerplate/issues).
59+
Report bugs or do suggestions using the [issues](https://github.com/codevor/js-is-type/issues).
4560

4661
## License
4762

4863
[MIT License](LICENSE) © [Codevor](https://github.com/codevor)
4964

50-
[license-badge]: https://img.shields.io/github/license/codevor/js-library-boilerplate.svg
65+
[license-badge]: https://img.shields.io/github/license/codevor/js-is-type.svg
5166
[license-url]: https://opensource.org/licenses/MIT
52-
[coverage-badge]: https://coveralls.io/repos/github/codevor/js-library-boilerplate/badge.svg?branch=master
53-
[coverage-url]: https://coveralls.io/github/codevor/js-library-boilerplate?branch=master
54-
[travis-badge]: https://travis-ci.org/codevor/js-library-boilerplate.svg?branch=master
55-
[travis-url]: https://travis-ci.org/codevor/js-library-boilerplate
67+
[coverage-badge]: https://coveralls.io/repos/github/codevor/js-is-type/badge.svg?branch=master
68+
[coverage-url]: https://coveralls.io/github/codevor/js-is-type?branch=master
69+
[travis-badge]: https://travis-ci.org/codevor/js-is-type.svg?branch=master
70+
[travis-url]: https://travis-ci.org/codevor/js-is-type
5671
[commitizen-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
5772
[commitizen-url]: http://commitizen.github.io/cz-cli/

package.json

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
{
2-
"name": "js-library-boilerplate",
2+
"name": "@codevor/js-is-type",
33
"version": "0.1.0",
4-
"description": "js-library-boilerplate-description",
5-
"main": "dist/js-library-boilerplate.js",
6-
"unpkg": "dist/js-library-boilerplate.min.js",
4+
"description": "🎯Type-checking for 'Primitive' JS Types made easy!",
5+
"main": "dist/js-is-type.js",
6+
"unpkg": "dist/js-is-type.min.js",
77
"scripts": {
88
"clean": "rimraf dist",
99
"dev": "NODE_ENV=dev webpack --progress --colors --watch",
1010
"build:umd": "NODE_ENV=production webpack",
1111
"lint": "eslint src tests",
12-
"test": "jest --coverage --expand",
12+
"test": "jest --coverage",
1313
"test:watch": "jest --watch",
1414
"coveralls": "cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
1515
"prepublish": "yarn lint && yarn test && yarn clean && yarn build:umd",
1616
"commit": "git-cz"
1717
},
18-
"keywords": [],
19-
"author": "Helder Burato Berto <[email protected]> (https://helder.dev/)",
18+
"keywords": [
19+
"Utils",
20+
"Typechecking"
21+
],
22+
"author": "Ilê Caian <[email protected]> (https://ile.pink/)",
2023
"license": "MIT",
2124
"repository": {
2225
"type": "git",
23-
"url": "git+https://github.com/codevor/js-library-boilerplate.git"
26+
"url": "git+https://github.com/codevor/js-is-type.git"
2427
},
2528
"bugs": {
26-
"url": "https://github.com/codevor/js-library-boilerplate/issues"
29+
"url": "https://github.com/codevor/js-is-type/issues"
2730
},
28-
"homepage": "https://github.com/codevor/js-library-boilerplate#readme",
31+
"homepage": "https://github.com/codevor/js-is-type#readme",
2932
"devDependencies": {
3033
"@babel/cli": "^7.6.4",
3134
"@babel/core": "^7.6.4",

src/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export function sum(x, y) {
2-
return x + y;
3-
}
1+
export * from './validators';

src/validators/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export { default as isArray } from './is-array';
2+
export { default as isBoolean } from './is-boolean';
3+
export { default as isFunction } from './is-function';
4+
export { default as isObject } from './is-object';
5+
export { default as isString } from './is-string';
6+
export { default as isUndefined } from './is-undefined';

src/validators/is-array.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const isArray = value => Array.isArray(value);
2+
3+
export default isArray;

src/validators/is-boolean.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const isBoolean = value => typeof value === 'boolean';
2+
3+
export default isBoolean;

src/validators/is-function.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const isFunction = value => typeof value === "function";
2+
3+
export default isFunction;

src/validators/is-object.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const isObject = value => typeof value === "object";
2+
3+
export default isObject;

src/validators/is-string.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const isString = value => typeof value === "string";
2+
3+
export default isString;

src/validators/is-undefined.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const isUndefined = value => typeof value === "undefined";
2+
3+
export default isUndefined;

tests/is-array.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { isArray } from '../src';
2+
3+
describe('isArray()', () => {
4+
const anonymousFunction = () => {};
5+
function namedFunction() {}
6+
const emptyArrayValue = [];
7+
const arrayValue = [2, 8, 'test'];
8+
const stringValue = 'This is a string';
9+
const booleanValue = true;
10+
11+
test('empty array should be valid', () => {
12+
expect(isArray(emptyArrayValue)).toBeTruthy();
13+
});
14+
15+
test('correct array, not empty should be valid', () => {
16+
expect(isArray(arrayValue)).toBeTruthy();
17+
});
18+
19+
test('anonymous function should be invalid', () => {
20+
expect(isArray(anonymousFunction)).toBeFalsy();
21+
});
22+
23+
test('named function should be invalid', () => {
24+
expect(isArray(namedFunction)).toBeFalsy();
25+
});
26+
27+
test('non array (string value) should be invalid', () => {
28+
expect(isArray(stringValue)).toBeFalsy();
29+
});
30+
31+
test('non array (boolean value) should be invalid', () => {
32+
expect(isArray(booleanValue)).toBeFalsy();
33+
});
34+
});

tests/is-boolean.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { isBoolean } from '../src';
2+
3+
describe('isBoolean()', () => {
4+
const anonymousFunction = () => {};
5+
function namedFunction() {};
6+
const booleanValue = true;
7+
const arrayValue = [4, true, 'test'];
8+
const stringValue = 'This is a string';
9+
const numberValue = 3;
10+
11+
test('boolean value should be valid', () => {
12+
expect(isBoolean(booleanValue)).toBeTruthy();
13+
});
14+
15+
test('anonymous function value should be invalid', () => {
16+
expect(isBoolean(anonymousFunction)).toBeFalsy();
17+
});
18+
19+
test('named function value should be invalid', () => {
20+
expect(isBoolean(namedFunction)).toBeFalsy();
21+
});
22+
23+
test('array value should be invalid', () => {
24+
expect(isBoolean(arrayValue)).toBeFalsy();
25+
});
26+
27+
test('string value should be invalid', () => {
28+
expect(isBoolean(stringValue)).toBeFalsy();
29+
});
30+
31+
test('number value should be invalid', () => {
32+
expect(isBoolean(numberValue)).toBeFalsy();
33+
});
34+
});

tests/is-function.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { isFunction } from '../src';
2+
3+
describe('isFunction()', () => {
4+
const anonymousFunction = () => {};
5+
function namedFunction() {}
6+
const booleanValue = true;
7+
const arrayValue = [4, true, 'test'];
8+
const stringValue = 'This is a string';
9+
const numberValue = 3;
10+
11+
test('anonymous function should be valid', () => {
12+
expect(isFunction(anonymousFunction)).toBeTruthy();
13+
});
14+
15+
test('named function should be valid', () => {
16+
expect(isFunction(namedFunction)).toBeTruthy();
17+
});
18+
19+
test('boolean value should be invalid', () => {
20+
expect(isFunction(booleanValue)).toBeFalsy();
21+
});
22+
23+
test('array value should be invalid', () => {
24+
expect(isFunction(arrayValue)).toBeFalsy();
25+
});
26+
27+
test('string value should be invalid', () => {
28+
expect(isFunction(stringValue)).toBeFalsy();
29+
});
30+
31+
test('number value should be invalid', () => {
32+
expect(isFunction(numberValue)).toBeFalsy();
33+
});
34+
});

tests/is-object.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { isObject } from '../src';
2+
3+
describe('isObject()', () => {
4+
const anonymousFunction = () => {};
5+
function namedFunction() {}
6+
const objectValue = { test: 1 };
7+
const arrayValue = [];
8+
const numberValue = 3;
9+
const booleanValue = true;
10+
11+
test('object value should be valid', () => {
12+
expect(isObject(objectValue)).toBeTruthy();
13+
});
14+
15+
test('array value should be valid(arrays are objects!!)', () => {
16+
expect(isObject(arrayValue)).toBeTruthy();
17+
});
18+
19+
test('anonymous function value should be invalid', () => {
20+
expect(isObject(anonymousFunction)).toBeFalsy();
21+
});
22+
23+
test('named function value should be invalid', () => {
24+
expect(isObject(namedFunction)).toBeFalsy();
25+
});
26+
27+
test('number value should be invalid', () => {
28+
expect(isObject(numberValue)).toBeFalsy();
29+
});
30+
31+
test('boolean value should be invalid', () => {
32+
expect(isObject(booleanValue)).toBeFalsy();
33+
});
34+
});

tests/is-string.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { isString } from '../src';
2+
3+
describe('isString()', () => {
4+
const anonymousFunction = () => {};
5+
function namedFunction() {}
6+
const objectValue = { test: 1 };
7+
const arrayValue = [];
8+
const stringValue = 'defined';
9+
const numberValue = 3;
10+
const booleanValue = true;
11+
12+
test('string value should be valid', () => {
13+
expect(isString(stringValue)).toBeTruthy();
14+
});
15+
16+
test('anonymous function should be invalid', () => {
17+
expect(isString(anonymousFunction)).toBeFalsy();
18+
});
19+
20+
test('named function should be invalid', () => {
21+
expect(isString(namedFunction)).toBeFalsy();
22+
});
23+
24+
test('object value should be invalid', () => {
25+
expect(isString(objectValue)).toBeFalsy();
26+
});
27+
28+
test('array value should be invalid', () => {
29+
expect(isString(arrayValue)).toBeFalsy();
30+
});
31+
32+
test('number value should be invalid', () => {
33+
expect(isString(numberValue)).toBeFalsy();
34+
});
35+
36+
test('boolean value should be invalid', () => {
37+
expect(isString(booleanValue)).toBeFalsy();
38+
});
39+
});

tests/is-undefined.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isUndefined } from '../src';
2+
3+
describe('isUndefined()', () => {
4+
const definedValue = 2;
5+
const notDefinedValue = undefined;
6+
7+
test('defined value should be invalid', () => {
8+
expect(isUndefined(definedValue)).toBeFalsy();
9+
});
10+
11+
test('non defined should be valid', () => {
12+
expect(isUndefined(notDefinedValue)).toBeTruthy();
13+
});
14+
});

tests/sum.test.js

-7
This file was deleted.

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
55
const isProduction = process.env.NODE_ENV === 'production';
66
const mode = isProduction ? 'production' : 'development';
77

8-
const libraryName = 'js-library-boilerplate';
8+
const libraryName = 'js-is-type';
99

1010
module.exports = {
1111
mode,

0 commit comments

Comments
 (0)