Skip to content

Commit

Permalink
Adding test coverage, adding readme, bug fix with testing arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Mendenhall authored and Samuel Mendenhall committed Aug 11, 2021
1 parent 0d242f4 commit 48f5a32
Show file tree
Hide file tree
Showing 12 changed files with 2,886 additions and 97 deletions.
46 changes: 46 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint'
],
extends: [
'airbnb-typescript/base'
],
overrides: [
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: ['./tsconfig.lint.json']
}
}
],
rules: {
"max-len": ["error", { "code": 180, "tabWidth": 2 }],
"comma-dangle": "off",
"prefer-destructuring": "off",
"object-curly-newline": "off",
"no-restricted-syntax": "off",
"no-console": "off",
"no-plusplus": "off",
"no-nested_ternary": "off",
"arrow-body-style": "off",
"import/order": "off",
"no-nested-ternary": "off",
"@typescript-eslint/lines-between-class-members": "off",
"@typescript-eslint/comma-dangle": "off",
"react/prop-types": "off",
"react/jsx-boolean-value": "off",
"react/jsx-props-no-spreading": "off",
"react/destructuring-assignment": "off",
"import/no-extraneous-dependencies": "off",
"import/prefer-default-export": "off"
},
ignorePatterns: [
'.eslintrc.js',
'craco.config.js',
'node_modules',
'dist'
]
};

103 changes: 102 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,102 @@
# isTruthy
<div align="center">
<h1>
<br/>
⚖️
<br />
Truthiness with options!
<br />
<br />
</h1>
<sup>
<br />
<a href="https://www.npmjs.com/package/@engineersamuel/istruthy">
<img src="https://img.shields.io/npm/v/@engineersamuel/istruthy.svg" alt="npm package" />
</a>
<a href="https://github.com/engineersamuel/isTruthy/issues">
<img src="https://img.shields.io/github/issues/engineersamuel/isTruthy" alt="github issues" />
</a>
<a href="https://www.npmjs.com/package/@engineersamuel/istruthy">
<img src="https://img.shields.io/npm/dm/@engineersamuel/istruthy.svg" alt="npm downloads" />
</a>
</sup>
<br />
<pre>npm i <a href="https://www.npmjs.com/package/@engineersamuel/istruthy">@engineersamuel/istruthy</a></pre>
<br />
</div>

# Table of Contents

- [Table of Contents](#table-of-contents)
- [Why](#why)
- [Install](#install)
- [Usage](#usage)
- [Config](#config)
- [Testing](#testing)
- [Contributing](#contributing)
- [Publishing](#publishing)

## Why

Most truthiness libraries are either extremely basic or simply adhere to the standard defnition of [Truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) in JavaScript.

However, what happens when you want to consider `''`, `[]`, `{}`, `0`, or `[null]` false? This is where `@engineersamuel/istruthy` comes in.

## Install

`$ npm i -D @engineersamuel/istruthy`

## Usage

```javascript
import { isTruthy, isFalsy } from '@engineersamuel/istruthy';

console.log(isTruthy('abc')); // prints true
console.log(isTruthy('', { isEmptyStringFalse: true })); // prints false

console.log(isFalse('abc')); // prints false
console.log(isFalsy('', { isEmptyStringFalse: true })); // prints true
```

## Config

| Option | Default | Description |
|---|---|---|
| isZeroFalse | false | When set to `true` then `0` will be will be evaluated to false. Ex. `isTruthy(0, { isZeroFalse: true}); // returns false` |
| isInfinityFalse | false | When set to `true` then `Infinity` and `-Infinity` will be will be evaluated to false. Ex. `isTruthy(Infinity, { isInfinityFalse: true}); // returns false` |
| isEmptyStringFalse | false | When set to `true` then `''` will be will be evaluated to false. Ex. `isTruthy('', { isEmptyStringFalse: true}); // returns false` |
| isEmptyObjectFalse | false | When set to `true` then `{}` will be will be evaluated to false. Ex. `isTruthy({}, { isEmptyObjectFalse: true}); // returns false` |
| isEmptyArrayFalse | false | When set to `true` then `[]` will be will be evaluated to false. Ex. `isTruthy([], { isEmptyArrayFalse: true}); // returns false` |
| isFilteredArrayFalse | false | When set to `true` then `[null, undefined]` will be will be evaluated to false. Ex. `isTruthy([null, undefined], { isFilteredArrayFalse: true }); // returns false` Note: This specific flag will recursively check each value, so passing options to isTruthy are recursively respected. |
| isFalsyArrayFalse | false | When set to `true` then `[null, undefined]` will be will be evaluated to false. Ex. `isTruthy([null, undefined], { isFalsyArrayFalse: true})/ // returns false` Ex. `isTruthy([0, ''], { isFalsyArrayFalse: true, isZeroFalse: true, isEmptyStringFalse: true }); // returns false` Note: This specific flag will recursively check each value, so passing options to isTruthy are recursively respected. |

## Testing

See the `*.spec.ts` files in the [./test](https://github.com/engineersamuel/isTruthy/tree/master/test) directory for a great reference on using `isTruthy`.

`npm run test`

```text
63 passing (38ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.ts | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
```

## Contributing

- `npm i`
- _make code changes_
- `npm run test`
- `npm run lint`
- `npm run build`

## Publishing

- Bump the [package.json](package.json) version
- `npm publish --access public`
- `git tag vx.y.z`
- `git push origin --tags`
Loading

0 comments on commit 48f5a32

Please sign in to comment.