1.0.28 • Published 1 month ago

anyone v1.0.28

Weekly downloads
3
License
MIT
Repository
github
Last release
1 month ago

anyone

Anyone contains a small group of functions that check whether a number of given expressions evaluate to be truthy based on the number of times a truthy value appears.

Anyone has four functions:

  • any - Checks that at least one of the supplied expressions evaluates to true.
  • one - Checks that only one of the supplied expressions evaluates to true (Mutual exclusion).
  • all - Checks that all of the supplied expressions evaluate to true.
  • none - Checks that none of the supplied expressions evaluates to true.

They all accept any amount of arguments, or no arguments at all. If a function is passed, it will be run and its value will be evaluated. Return value is always a boolean.

All functions other than one will short circuit when realizing the condition is not met.

Why use it

In most cases (other than one) you can do just fine using Array.prototype.some and Array.prototype.every, but I do this often enough that I thought I'd share it.

  • You can use these functions as conditionals:
if (one( var1, var2, var3 )) {
    // will reach here if ONLY ONE of the arguments is true
}
  • You can use these functions to pause execution of some code after a condition is met
all(
    validateInput1, // returns true
    validateInput2, // returns false
    validateInput3  // no need to run this, we already know our validation failed
);

Installation

npm i anyone
yarn add anyone

Usage Examples

import { any, all, none, one } from 'anyone';

any(
    someFunction, // evaluates to false
    1,
    someVar // truthy
);
// true

// --------

any(
    someFunction, // evaluates to false
    0,
    someVar // falsy
);
// false

// --------

one(
    someFunction, // evaluates to false
    0,
    someVar // truthy
);
// true

// --------

none(
    someFunction, // evaluates to false
    1,
    someVar // truthy
);
// false

// --------

none(
    someFunction, // evaluates to false
    0,
    someVar // falsy
);
// true

// --------

all(
    someFunction, // evaluates to false
    0,
    someVar // truthy
);
// false

// --------

all(
    someFunction, // evaluates to true
    1,
    someVar // truthy
);
// true

You can also import any of the functions directly. If you use more than one, you should opt import them together, as they share most of their code.

import any from 'anyone/any';
import one from 'anyone/one';
import all from 'anyone/all';
import none from 'anyone/none';
1.0.28

1 month ago

1.0.27

2 months ago

1.0.26

2 months ago

1.0.25

3 months ago

1.0.24

3 months ago

1.0.23

4 months ago

1.0.22

4 months ago

1.0.21

5 months ago

1.0.20

5 months ago

1.0.19

5 months ago

1.0.18

5 months ago

1.0.17

5 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

8 months ago

1.0.8-next-a084e9

11 months ago

1.0.8-next-979ab9

11 months ago

1.0.8-next-04eea9

11 months ago

1.0.8-next-83f17b

11 months ago

1.0.8-next-2cf993

11 months ago

1.0.8-next-ed535b

12 months ago

1.0.8-dev-ec989a

12 months ago

1.0.8-next-470211

12 months ago

1.0.8-dev-ae6b14

12 months ago

1.0.8-next-70dac5

12 months ago

1.0.8-next-1b0637

12 months ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.3-dev-b07a89

2 years ago

1.0.2-dev-c786f7

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.1.0-dev-c4ba9b

2 years ago

1.0.3-dev-310818

2 years ago

1.0.3-dev-fcaa09

2 years ago

1.0.3-dev-b9b126

2 years ago

1.0.2-dev-ae93bf

2 years ago

1.0.2-dev-d13b14

2 years ago

1.1.0-dev-f30a30

2 years ago

1.0.2-dev-9b46fb

2 years ago

1.0.2-dev-afe5de

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

2.0.0-dev-031d95

2 years ago

2.0.0

2 years ago

2.0.0-dev-1aae50

2 years ago

2.0.0-dev-cc2a13

2 years ago

2.0.0-dev-e266d9

2 years ago

2.0.0-dev-fc2efe

2 years ago

0.1.1-dev-c9788a

3 years ago

0.1.1

3 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.6-rc.1

4 years ago

0.0.6-rc

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago