1.2.1 • Published 2 years ago

tendency v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

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

ParamTypeDescription
countnumberExact number of invalid conditions
...parametersParameterMultiple 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

ParamTypeDescription
countnumberMaximum number of false conditions
...parametersParameterMultiple 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

ParamTypeDescription
countnumberMinimum number of false conditions
...parametersParameterMultiple 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

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

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

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

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

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

ParamTypeDescription
countnumberExact number of true conditions
...parametersParameterMultiple 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

ParamTypeDescription
countnumberMaximum number of true conditions
...parametersParameterMultiple 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

ParamTypeDescription
countnumberMinimum number of true conditions
...parametersParameterMultiple 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

ParamTypeDescription
...parametersParameterMultiple parameters

Example

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

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

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

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago