No Padding Margin

    tendency
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.1 • Public • Published

    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

    not

    Provides inversions of all given functions.

    Functions

    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.

    any(...parameters)Flag

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

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

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

    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.

    match(count, ...parameters)Flag

    Appends parameters if the given count of conditions are true.

    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.

    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.

    some(...parameters)Flag

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

    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'

    Install

    npm i tendency

    DownloadsWeekly Downloads

    9

    Version

    1.2.1

    License

    MIT

    Unpacked Size

    56.1 kB

    Total Files

    42

    Last publish

    Collaborators

    • lucajoos