Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
47 changes: 31 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
# js-library-boilerplate
# 🎯Type-checking for 'Primitive' JS Types

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

> js-library-boilerplate-description.
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`!

The usage is simple and verbose. The tests has full coverage and you can use without a doubt.

## Available Types

- `isArray()`
- `isBoolean()`
- `isFunction()`
- `isObject()` (_Remember: in JS, Arrays are Objects!_)
- `isString()`
- `isUndefined()`

## Installation

js-library-boilerplate is available on npm/yarn:
`js-is-type` is available on npm/yarn:

```bash
$ npm install js-library-boilerplate --save
$ yarn add js-library-boilerplate
$ npm install @codevor/js-is-type --save
$ yarn add @codevor/js-is-type
```

## Usage

### With ES6/import

```js
import { sum } from 'js-library-boilerplate';
import { isArray } from '@codevor/js-is-type';

sum(2, 2); // => 4
const names = ['Alice', 'Bob'];

isArray(names); // => true
```

### With require

```js
const sum = require('js-library-boilerplate').sum;
const isArray = require('@codevor/js-is-type').isArray;

const names = ['Alice', 'Bob'];

sum(2, 2); // => 4
isArray(names); // => true
```

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

## Changelog

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.
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.

## Bugs and Sugestions

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

## License

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

[license-badge]: https://img.shields.io/github/license/codevor/js-library-boilerplate.svg
[license-badge]: https://img.shields.io/github/license/codevor/js-is-type.svg
[license-url]: https://opensource.org/licenses/MIT
[coverage-badge]: https://coveralls.io/repos/github/codevor/js-library-boilerplate/badge.svg?branch=master
[coverage-url]: https://coveralls.io/github/codevor/js-library-boilerplate?branch=master
[travis-badge]: https://travis-ci.org/codevor/js-library-boilerplate.svg?branch=master
[travis-url]: https://travis-ci.org/codevor/js-library-boilerplate
[coverage-badge]: https://coveralls.io/repos/github/codevor/js-is-type/badge.svg?branch=master
[coverage-url]: https://coveralls.io/github/codevor/js-is-type?branch=master
[travis-badge]: https://travis-ci.org/codevor/js-is-type.svg?branch=master
[travis-url]: https://travis-ci.org/codevor/js-is-type
[commitizen-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
[commitizen-url]: http://commitizen.github.io/cz-cli/
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
{
"name": "js-library-boilerplate",
"name": "@codevor/js-is-type",
"version": "0.1.0",
"description": "js-library-boilerplate-description",
"main": "dist/js-library-boilerplate.js",
"unpkg": "dist/js-library-boilerplate.min.js",
"description": "🎯Type-checking for 'Primitive' JS Types made easy!",
"main": "dist/js-is-type.js",
"unpkg": "dist/js-is-type.min.js",
"scripts": {
"clean": "rimraf dist",
"dev": "NODE_ENV=dev webpack --progress --colors --watch",
"build:umd": "NODE_ENV=production webpack",
"lint": "eslint src tests",
"test": "jest --coverage --expand",
"test": "jest --coverage",
"test:watch": "jest --watch",
"coveralls": "cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
"prepublish": "yarn lint && yarn test && yarn clean && yarn build:umd",
"commit": "git-cz"
},
"keywords": [],
"author": "Helder Burato Berto <helder.burato@gmail.com> (https://helder.dev/)",
"keywords": [
"Utils",
"Typechecking"
],
"author": "Ilê Caian <ile.caian@gmail.com> (https://ile.pink/)",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/codevor/js-library-boilerplate.git"
"url": "git+https://github.com/codevor/js-is-type.git"
},
"bugs": {
"url": "https://github.com/codevor/js-library-boilerplate/issues"
"url": "https://github.com/codevor/js-is-type/issues"
},
"homepage": "https://github.com/codevor/js-library-boilerplate#readme",
"homepage": "https://github.com/codevor/js-is-type#readme",
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
Expand Down
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export function sum(x, y) {
return x + y;
}
export * from './validators';
6 changes: 6 additions & 0 deletions src/validators/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { default as isArray } from './is-array';
export { default as isBoolean } from './is-boolean';
export { default as isFunction } from './is-function';
export { default as isObject } from './is-object';
export { default as isString } from './is-string';
export { default as isUndefined } from './is-undefined';
3 changes: 3 additions & 0 deletions src/validators/is-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isArray = value => Array.isArray(value);

export default isArray;
3 changes: 3 additions & 0 deletions src/validators/is-boolean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isBoolean = value => typeof value === 'boolean';

export default isBoolean;
3 changes: 3 additions & 0 deletions src/validators/is-function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isFunction = value => typeof value === "function";

export default isFunction;
3 changes: 3 additions & 0 deletions src/validators/is-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isObject = value => typeof value === "object";

export default isObject;
3 changes: 3 additions & 0 deletions src/validators/is-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isString = value => typeof value === "string";

export default isString;
3 changes: 3 additions & 0 deletions src/validators/is-undefined.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isUndefined = value => typeof value === "undefined";

export default isUndefined;
34 changes: 34 additions & 0 deletions tests/is-array.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { isArray } from '../src';

describe('isArray()', () => {
const anonymousFunction = () => {};
function namedFunction() {}
const emptyArrayValue = [];
const arrayValue = [2, 8, 'test'];
const stringValue = 'This is a string';
const booleanValue = true;

test('empty array should be valid', () => {
expect(isArray(emptyArrayValue)).toBeTruthy();
});

test('correct array, not empty should be valid', () => {
expect(isArray(arrayValue)).toBeTruthy();
});

test('anonymous function should be invalid', () => {
expect(isArray(anonymousFunction)).toBeFalsy();
});

test('named function should be invalid', () => {
expect(isArray(namedFunction)).toBeFalsy();
});

test('non array (string value) should be invalid', () => {
expect(isArray(stringValue)).toBeFalsy();
});

test('non array (boolean value) should be invalid', () => {
expect(isArray(booleanValue)).toBeFalsy();
});
});
34 changes: 34 additions & 0 deletions tests/is-boolean.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { isBoolean } from '../src';

describe('isBoolean()', () => {
const anonymousFunction = () => {};
function namedFunction() {};
const booleanValue = true;
const arrayValue = [4, true, 'test'];
const stringValue = 'This is a string';
const numberValue = 3;

test('boolean value should be valid', () => {
expect(isBoolean(booleanValue)).toBeTruthy();
});

test('anonymous function value should be invalid', () => {
expect(isBoolean(anonymousFunction)).toBeFalsy();
});

test('named function value should be invalid', () => {
expect(isBoolean(namedFunction)).toBeFalsy();
});

test('array value should be invalid', () => {
expect(isBoolean(arrayValue)).toBeFalsy();
});

test('string value should be invalid', () => {
expect(isBoolean(stringValue)).toBeFalsy();
});

test('number value should be invalid', () => {
expect(isBoolean(numberValue)).toBeFalsy();
});
});
34 changes: 34 additions & 0 deletions tests/is-function.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { isFunction } from '../src';

describe('isFunction()', () => {
const anonymousFunction = () => {};
function namedFunction() {}
const booleanValue = true;
const arrayValue = [4, true, 'test'];
const stringValue = 'This is a string';
const numberValue = 3;

test('anonymous function should be valid', () => {
expect(isFunction(anonymousFunction)).toBeTruthy();
});

test('named function should be valid', () => {
expect(isFunction(namedFunction)).toBeTruthy();
});

test('boolean value should be invalid', () => {
expect(isFunction(booleanValue)).toBeFalsy();
});

test('array value should be invalid', () => {
expect(isFunction(arrayValue)).toBeFalsy();
});

test('string value should be invalid', () => {
expect(isFunction(stringValue)).toBeFalsy();
});

test('number value should be invalid', () => {
expect(isFunction(numberValue)).toBeFalsy();
});
});
34 changes: 34 additions & 0 deletions tests/is-object.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { isObject } from '../src';

describe('isObject()', () => {
const anonymousFunction = () => {};
function namedFunction() {}
const objectValue = { test: 1 };
const arrayValue = [];
const numberValue = 3;
const booleanValue = true;

test('object value should be valid', () => {
expect(isObject(objectValue)).toBeTruthy();
});

test('array value should be valid(arrays are objects!!)', () => {
expect(isObject(arrayValue)).toBeTruthy();
});

test('anonymous function value should be invalid', () => {
expect(isObject(anonymousFunction)).toBeFalsy();
});

test('named function value should be invalid', () => {
expect(isObject(namedFunction)).toBeFalsy();
});

test('number value should be invalid', () => {
expect(isObject(numberValue)).toBeFalsy();
});

test('boolean value should be invalid', () => {
expect(isObject(booleanValue)).toBeFalsy();
});
});
39 changes: 39 additions & 0 deletions tests/is-string.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { isString } from '../src';

describe('isString()', () => {
const anonymousFunction = () => {};
function namedFunction() {}
const objectValue = { test: 1 };
const arrayValue = [];
const stringValue = 'defined';
const numberValue = 3;
const booleanValue = true;

test('string value should be valid', () => {
expect(isString(stringValue)).toBeTruthy();
});

test('anonymous function should be invalid', () => {
expect(isString(anonymousFunction)).toBeFalsy();
});

test('named function should be invalid', () => {
expect(isString(namedFunction)).toBeFalsy();
});

test('object value should be invalid', () => {
expect(isString(objectValue)).toBeFalsy();
});

test('array value should be invalid', () => {
expect(isString(arrayValue)).toBeFalsy();
});

test('number value should be invalid', () => {
expect(isString(numberValue)).toBeFalsy();
});

test('boolean value should be invalid', () => {
expect(isString(booleanValue)).toBeFalsy();
});
});
14 changes: 14 additions & 0 deletions tests/is-undefined.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { isUndefined } from '../src';

describe('isUndefined()', () => {
const definedValue = 2;
const notDefinedValue = undefined;

test('defined value should be invalid', () => {
expect(isUndefined(definedValue)).toBeFalsy();
});

test('non defined should be valid', () => {
expect(isUndefined(notDefinedValue)).toBeTruthy();
});
});
7 changes: 0 additions & 7 deletions tests/sum.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const mode = isProduction ? 'production' : 'development';

const libraryName = 'js-library-boilerplate';
const libraryName = 'js-is-type';

module.exports = {
mode,
Expand Down