Wondering what’s next for npm?Check out our public roadmap! »

    filtered-array-to-sentence

    1.0.0 • Public • Published

    filtered-array-to-sentence

    NPM version Bower version Build Status Coverage Status Dependency Status devDependency Status

    Filter an array and produce a human-readable result as a string

    const isString = v => typeof v === 'string';
     
    filteredArrayToSentence([null, 'apple', 999, 'orange'], isString);
    //=> 'apple (index: 1) and orange (index: 3)'

    Installation

    Package managers

    npm

    npm install filtered-array-to-sentence
    

    bower

    bower install filtered-array-to-sentence
    

    API

    filteredArrayToSentence(array [, options], filterFn)

    array: Array of any values
    options: Object (directly passed to array-to-sentence)
    filterFn: Function
    Return: String

    It filters array with filterFn function, and returns a string that shows a filtered values and those original array indexes with a human-readable format.

    filteredArrayToSentence([45, -1, 0, Infinity, 2], v => v > 0);
    //=> '45 (index: 0), Infinity (index: 3) and 2 (index: 4)'
     
    filteredArrayToSentence(['ramen', 'udon', 'soba'], {lastSeparator: '&'}, s => s.length < 5);
    //=> 'udon (index: 1) & soba (index: 2)'
     
    arrayToSentence([], () => true);
    //=> ''

    License

    Copyright (c) 2015 Shinnosuke Watanabe

    Licensed under the MIT License.

    Install

    npm i filtered-array-to-sentence

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • avatar