-
-
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
0 parents
commit 6e5a2b8
Showing
7 changed files
with
369 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,108 @@ | ||
<h1 align="center"> | ||
That is | ||
</br></br> | ||
<a href='./LICENSE' title='MIT License'><img src='https://img.shields.io/badge/license-MIT-purple.svg?style=for-the-badge'></a> | ||
<img src='https://img.shields.io/badge/Maintained-yes-green.svg?style=for-the-badge'> | ||
</h1> | ||
|
||
> `That-is` is a utility javascript library for type checking, the purpose of the project is to help with flexibility and code optimization | ||
# Installation | ||
|
||
The project is designed to support both `Node` and `Web` environments, follow the instructions below to install: | ||
|
||
- ## Web Version | ||
|
||
- Download the [latest version](https://github.com/KivixEletric/That-is/releases) for the web distribution | ||
- Place the `.js` or `.min.js` file from the `.zip` inside your project | ||
- After you have placed the file, place the following code in your `.html` file: | ||
|
||
```html | ||
<script src="path/to/That-is.js"></script> | ||
``` | ||
|
||
- Note: all tools will be present in `window.is`. | ||
|
||
- ## Node Version | ||
|
||
- Use the platform [npm](https://www.npmjs.com) to install the library: | ||
|
||
``` | ||
npm install @kivixeletric/that-is | ||
``` | ||
|
||
- After installation, you can use the library with `require` as in the example below: | ||
|
||
```js | ||
const is = require('@kivixeletric/that-is') | ||
``` | ||
|
||
# How to use | ||
|
||
To use the library in your project is very simple, see the example below: | ||
|
||
```js | ||
// Number Type | ||
is.number('0') // will return a False | ||
is.number(0) // will return a True | ||
|
||
// String Type | ||
is.string('boo') // will return a True | ||
is.string(true) // will return a False | ||
``` | ||
|
||
But if you want to do multiple checks of the same type, see the example below: | ||
|
||
```js | ||
is.number(1, '2') // False | ||
is.number(1, 2) // True | ||
is.number(1, '2', 3) // False | ||
is.number(1, 2, 3) // True | ||
``` | ||
|
||
But some functions will not have multiple values, for example `is.divisible` and `is.equal` | ||
|
||
# Type List | ||
|
||
### Logical Types | ||
* `type` or `a` - (type, ...values) -> Checks if value is a selected type | ||
|
||
* `defined` or `def` - (...values) -> Checks if value is defined (is also applied to Object types) | ||
|
||
* `equal` - (value, other) -> Checks if value is equals a other value | ||
|
||
### Numeric Types | ||
* `decimal` - (...values) -> Checks if value is decimal type | ||
|
||
* `bigint` - (...values) -> Checks if value is bigint type | ||
|
||
* `divisible` - (value, number) -> Checks if value is divisible with another number | ||
|
||
* `infinite` - (...values) -> Checks if value is a infinite type | ||
|
||
### Object Types | ||
* `element` or `elem` - (...values) -> Checks if value is node element type | ||
|
||
* `Object` or `Obj` - (...values) -> Checks if value is array or object type | ||
|
||
* `object` or `obj` - (...values) -> Checks if value is object type | ||
|
||
* `array` or `arr` - (...values) -> Checks if value is array type | ||
|
||
### Natural Types | ||
* `number`, `num` or `int` - (...values) -> Checks if value is number type | ||
|
||
* `string` or `str` - (...values) -> Checks if value is string type | ||
|
||
* `boolean` or `bool` - (...values) -> Checks if value is boolean type | ||
|
||
* `function` or `fn` - (...values) -> Checks if value is function type | ||
|
||
* `symbol` - (...values) -> Checks if value is symbol type | ||
|
||
### Special Types | ||
* `regexp` - (...values) -> Checks if value is RegExp type | ||
|
||
# License | ||
|
||
- This project is licensed under [MIT License](../LICENSE) |
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,8 @@ | ||
# Removing test directory | ||
**/__test__ | ||
**/test | ||
**/old | ||
|
||
# Removing npm modules installed | ||
node_modules | ||
package-lock.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,13 @@ | ||
# Removing Unnecessary Files | ||
.gitignore | ||
.github | ||
|
||
# Removing test directory | ||
**/__test__ | ||
**/test | ||
**/old | ||
**/docs | ||
|
||
# Removing npm modules installed | ||
node_modules | ||
package-lock.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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Kivix Eletric | ||
|
||
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,86 @@ | ||
<h1 align="center"> | ||
That is | ||
</br></br> | ||
<a href='./LICENSE' title='MIT License'><img src='https://img.shields.io/badge/license-MIT-purple.svg?style=for-the-badge'></a> | ||
<img src='https://img.shields.io/badge/Maintained-yes-green.svg?style=for-the-badge'> | ||
</h1> | ||
|
||
> `That-is` is a utility javascript library for type checking, the purpose of the project is to help with flexibility and code optimization | ||
# Installation | ||
|
||
You can use the library using a [latest version](https://github.com/KivixEletric/That-is/releases) on github or via [npm](https://www.npmjs.com) (the recommended way): | ||
|
||
``` | ||
npm install @kivixeletric/that-is | ||
``` | ||
|
||
# How to use | ||
|
||
To use the library in your project is very simple, see the example below: | ||
|
||
```js | ||
// Number Type | ||
is.number('0') // will return a False | ||
is.number(0) // will return a True | ||
|
||
// String Type | ||
is.string('boo') // will return a True | ||
is.string(true) // will return a False | ||
``` | ||
|
||
But if you want to do multiple checks of the same type, see the example below: | ||
|
||
```js | ||
is.number(1, '2') // False | ||
is.number(1, 2) // True | ||
is.number(1, '2', 3) // False | ||
is.number(1, 2, 3) // True | ||
``` | ||
|
||
But some functions will not have multiple values, for example `is.divisible` and `is.equal` | ||
|
||
# Type List | ||
|
||
### Logical Types | ||
* `type` or `a` - (type, ...values) -> Checks if value is a selected type | ||
|
||
* `defined` or `def` - (...values) -> Checks if value is defined (is also applied to Object types) | ||
|
||
* `equal` - (value, other) -> Checks if value is equals a other value | ||
|
||
### Numeric Types | ||
* `decimal` - (...values) -> Checks if value is decimal type | ||
|
||
* `bigint` - (...values) -> Checks if value is bigint type | ||
|
||
* `divisible` - (value, number) -> Checks if value is divisible with another number | ||
|
||
* `infinite` - (...values) -> Checks if value is a infinite type | ||
|
||
### Object Types | ||
* `element` or `elem` - (...values) -> Checks if value is node element type | ||
|
||
* `Object` or `Obj` - (...values) -> Checks if value is array or object type | ||
|
||
* `object` or `obj` - (...values) -> Checks if value is object type | ||
|
||
* `array` or `arr` - (...values) -> Checks if value is array type | ||
|
||
### Natural Types | ||
* `number`, `num` or `int` - (...values) -> Checks if value is number type | ||
|
||
* `string` or `str` - (...values) -> Checks if value is string type | ||
|
||
* `boolean` or `bool` - (...values) -> Checks if value is boolean type | ||
|
||
* `function` or `fn` - (...values) -> Checks if value is function type | ||
|
||
* `symbol` - (...values) -> Checks if value is symbol type | ||
|
||
### Special Types | ||
* `regexp` - (...values) -> Checks if value is RegExp type | ||
|
||
# License | ||
|
||
- This project is licensed under [MIT License](./LICENSE) |
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,116 @@ | ||
(function (factory) { | ||
var web = (typeof window != 'undefined') | ||
var node = (typeof module != 'undefined' && module.exports) | ||
var data = factory() | ||
|
||
if (web) window.is = data | ||
if (node) module.exports = data | ||
}) | ||
|
||
(function () { | ||
var is = {} | ||
|
||
function BulkCheck(fn) { | ||
return function (...values) { | ||
if (values.length == 0) return false | ||
return values.every(v => fn(v)) | ||
} | ||
} | ||
|
||
/** | ||
** **is.type | is.a** - Verify if `value` is a type of `type` | ||
* @param {string} type | ||
*/ | ||
is.type = is.a = function (type, ...values) { | ||
return is[type] && is[type](...values) || false | ||
} | ||
|
||
/** | ||
* * **is.divisible** - Verify if `value` is divisible with `number` | ||
* @param {number} value | ||
* @param {number} number | ||
*/ | ||
is.divisible = function (value, number) { | ||
return is.num(value, number) && !is.decimal(value / number) | ||
} | ||
|
||
/** | ||
* * **is.equal** - Verify if `value` is equals to `other` | ||
*/ | ||
is.equal = (value, other) => value === other | ||
|
||
/** | ||
* * **is.number | is.num | is.int** - Verify if `value` is a number | ||
*/ | ||
is.number = is.num = is.int = BulkCheck(value => typeof value == 'number') | ||
|
||
/** | ||
* * **is.string | is.str** - Verify if `value` is a string | ||
*/ | ||
is.string = is.str = BulkCheck(value => typeof value == 'string') | ||
|
||
/** | ||
* * **is.boolean | is.bool** - Verify if `value` is a boolean | ||
*/ | ||
is.boolean = is.bool = BulkCheck(value => typeof value == 'boolean') | ||
|
||
/** | ||
* * **is.function | is.fn** - Verify if `value` is a function | ||
*/ | ||
is.function = is.fn = BulkCheck(value => typeof value == 'function') | ||
|
||
/** | ||
* * **is.bigint** - Verify if `value` is a bigint type | ||
*/ | ||
is.bigint = BulkCheck(value => typeof value == 'bigint') | ||
|
||
/** | ||
* * **is.symbol** - Verify if `value` is a symbol type | ||
*/ | ||
is.symbol = BulkCheck(value => typeof value == 'symbol') | ||
|
||
/** | ||
* * **is.object | is.obj** - Verify if `value` is a non-array object | ||
*/ | ||
is.object = is.obj = BulkCheck(value => value && Object.getPrototypeOf(value).isPrototypeOf({})) | ||
|
||
/** | ||
* * **is.Object | is.Obj** - Verify if `value` is a Object type | ||
*/ | ||
is.Object = is.Obj = BulkCheck(value => typeof value == 'object') | ||
|
||
/** | ||
* * **is.element | is.elem** - Verify if `value` is a Node Element type | ||
*/ | ||
is.element = is.elem = BulkCheck(value => value && value.nodeType) | ||
|
||
/** | ||
* * **is.element | is.elem** - Verify if `value` is a decimal value | ||
*/ | ||
is.decimal = BulkCheck(value => is.num(value) && value % 1 != 0) | ||
|
||
/** | ||
* * **is.array | is.arr** - Verify if `value` is a array | ||
*/ | ||
is.array = is.arr = BulkCheck(Array.isArray || (value => value.toString() === '[object Array]')) | ||
|
||
/** | ||
* * **is.infinite - Verify if `value` is a infinite number | ||
*/ | ||
is.infinite = BulkCheck(value => value === Infinity || value === -Infinity) | ||
|
||
/** | ||
* * **is.regexp - Verify if `value` is a RegExp type | ||
*/ | ||
is.regexp = BulkCheck(value => value.toString().includes('RegExp')) | ||
|
||
/** | ||
* * **is.defined | is.def** - Verify if `value` is defined | ||
*/ | ||
is.defined = is.def = BulkCheck(value => { | ||
if (!is.Obj(value)) return typeof value !== 'undefined'; | ||
return !!Object.entries(value)[0] | ||
}) | ||
|
||
return is | ||
}) |
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,17 @@ | ||
{ | ||
"name": "@kivixeletric/that-is", | ||
"version": "1.0.0", | ||
"description": "A library for checking multiple or single value types", | ||
"main": "./index.js", | ||
"author": "KivixEletric", | ||
"license": "MIT", | ||
"keywords": ["util", "type", "test", "check"], | ||
"homepage": "https://github.com/KivixEletric/That-is#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/KivixEletric/That-is.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/KivixEletric/That-is/issues" | ||
} | ||
} |