npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tendency

v1.2.1

Published

Conditional string generation

Downloads

205

Readme

tendency v1.2.1

Conditional string generation.

npm npm

import tendency, { not } from 'tendency/lib/esm';

tendency(true, 'a', 'b', [ false, not.every('c') ]);
// returns: 'a b c'

Installation

Install using NPM (or yarn):

$ npm i -g npm
$ npm i --save tendency

As module:

import tendency from 'tendency/lib/esm';

In Node.js:

const tendency = require('tendency/lib/cjs');

Configuration

Passing a Config object overwrites the current configuration. Configuration are inherited by underlying groups/arrays by default.

tendency({ separator: '-' }, 'a', 'b', 'c');
// returns: 'a-b-c'

Members

Functions

not

Provides inversions of all given functions.

Kind: global variable

not.every(...parameters) ⇒ Array.<Parameter>

Appends parameters if all conditions are false. This always refers to the current environment. Inversion of the function every().

Kind: static method of not
Returns: Array.<Parameter> - - Specified parameters

| Param | Type | Description | | --- | --- | --- | | ...parameters | Parameter | Multiple parameters |

Example

tendency(false, false, true, not.every('a', 'b'))
// returns: ''

tendency(false, false, not.every('a', 'b'))
// returns: 'a b'

not.match(count, ...parameters) ⇒ Flag

Appends parameters if the given count of conditions are false. Inversion of the function match().

Kind: static method of not
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | count | number | Exact number of invalid conditions | | ...parameters | Parameter | Multiple parameters |

Example

tendency(true, false, not.match(2, 'a', 'b'))
// returns: ''

tendency(false, false, not.match(2, 'a', 'b'))
// returns: 'a b'

not.max(count, ...parameters) ⇒ Flag

Appends parameters if the given maximum count of false conditions is not exceeded. Parameters are also appended if count is exactly equal to the number of conditions. Inversion of the function max().

Kind: static method of not
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | count | number | Maximum number of false conditions | | ...parameters | Parameter | Multiple parameters |

Example

tendency(not.max(1, 'a', 'b'))
// returns: 'a b'

tendency(false, not.max(1, 'a', 'b'))
// returns: 'a b'

tendency(false, false, not.max(1, 'a', 'b'))
// returns: ''

not.min(count, ...parameters) ⇒ Flag

Appends the parameters if the given minimum count of false conditions is met. Parameters are also appended if count is exactly equal to the number of conditions. Inversion of the function min().

Kind: static method of not
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | count | number | Minimum number of false conditions | | ...parameters | Parameter | Multiple parameters |

Example

tendency(not.min(1, 'a', 'b'))
// returns: ''

tendency(false, not.min(1, 'a', 'b'))
// returns: 'a b'

tendency(false, false, not.min(1, 'a', 'b'))
// returns: 'a b'

not.some(...parameters) ⇒ Flag

Appends parameters if at least one condition is false. This always refers to the current environment. Inversion of the function some().

Kind: static method of not
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | ...parameters | Parameter | Multiple parameters |

Example

tendency(not.some('a', 'b'))
// returns: ''

tendency(false, not.some('a', 'b'))
// returns: 'a b'

tendency(true, false, not.some('a', 'b'))
// returns: 'a b'

tendency(...parameters) ⇒ string

Transforms specified parameters into joined string based on conditions. If no conditions are given, the given environment is both true and false.

If no flags are given, the flag returned from every() is assumed. Thus all conditions of the current environment must be true.

Kind: global function
Returns: string - - Generated string

| Param | Type | Description | | --- | --- | --- | | ...parameters | Parameter | Multiple parameters |

Example

tendency(true, 'a', 'b')
// returns: 'a b'

any(...parameters) ⇒ Flag

Appends parameters independently of the conditions. These parameters are always appended.

Kind: global function
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | ...parameters | Parameter | Multiple parameters |

Example

tendency(true, any('a', 'b'))
// returns: 'a b'

tendency(false, any('a', 'b'))
// returns: ''

tendency(true, false, any('a', 'b'))
// returns: 'a b'

every(...parameters) ⇒ Array.<Parameter>

Appends parameters if all conditions are true. This always refers to the current environment.

Kind: global function
Returns: Array.<Parameter> - - Specified parameters

| Param | Type | Description | | --- | --- | --- | | ...parameters | Parameter | Multiple parameters |

Example

tendency(true, false, every('a', 'b'))
// returns: ''

tendency(true, true, every('a', 'b'))
// returns: 'a b'

group(...parameters) ⇒ Array.<Parameter>

Groups parameters into independent environment. All previously set conditions will be reset as a result. Alternatively, parameters can be moved into a separate array.

Kind: global function
Returns: Array.<Parameter> - - Specified parameters

| Param | Type | Description | | --- | --- | --- | | ...parameters | Parameter | Multiple parameters |

Example

tendency(true, group(false, 'a', 'b'))
// returns: ''

tendency(false, group(true, 'a', 'b'))
// returns: ''

tendency(true, group('a', 'b'))
// returns: 'a b'

tendency(true, group(true, 'a', 'b'))
// returns: 'a b'


// Alternatively:
tendency(true, [false, 'a', 'b'])
// returns: ''

match(count, ...parameters) ⇒ Flag

Appends parameters if the given count of conditions are true.

Kind: global function
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | count | number | Exact number of true conditions | | ...parameters | Parameter | Multiple parameters |

Example

tendency(true, false, match(2, 'a', 'b'))
// returns: ''

tendency(true, true, match(2, 'a', 'b'))
// returns: 'a b'

max(count, ...parameters) ⇒ Flag

Appends parameters if the given maximum count of true conditions is not exceeded. Parameters are also appended if count is exactly equal to the number of conditions.

Kind: global function
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | count | number | Maximum number of true conditions | | ...parameters | Parameter | Multiple parameters |

Example

tendency(max(1, 'a', 'b'))
// returns: 'a b'

tendency(true, max(1, 'a', 'b'))
// returns: 'a b'

tendency(true, true, max(1, 'a', 'b'))
// returns: ''

min(count, ...parameters) ⇒ Flag

Appends the parameters if the given minimum count of true conditions is met. Parameters are also appended if count is exactly equal to the number of conditions.

Kind: global function
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | count | number | Minimum number of true conditions | | ...parameters | Parameter | Multiple parameters |

Example

tendency(min(1, 'a', 'b'))
// returns: ''

tendency(true, min(1, 'a', 'b'))
// returns: 'a b'

tendency(true, true, min(1, 'a', 'b'))
// returns: 'a b'

some(...parameters) ⇒ Flag

Appends parameters if at least one condition is true. This always refers to the current environment.

Kind: global function
Returns: Flag - - Corresponding flag

| Param | Type | Description | | --- | --- | --- | | ...parameters | Parameter | Multiple parameters |

Example

tendency(some('a', 'b'))
// returns: ''

tendency(true, some('a', 'b'))
// returns: 'a b'

tendency(true, false, some('a', 'b'))
// returns: 'a b'