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

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

    0.3.1 • Public • Published

    strind

    NPM Build Coverage

    Partition strings based on character indices.

    Install

    yarn add strind

    Usage

    import strind from 'strind';
     
    const result = strind('abcd', [[1, 1], [2, 6]]);
     
    console.log(result);
    /**
     * {
          matched: ['b', 'cd'],
          unmatched: [
            {
              chars: 'a',
              index: 0
            }
          ]
        }
     *
     */

    Callback

    An optional callback function can be passed as the third argument.

    The function is called with the substring chars and boolean matches if the substring matches the array indices.

    import strind from 'strind';
     
    const result = strind('abcd', [[1, 1], [2, 6]], ({ chars, matches }) => {
      return {
        text: chars,
        isHighlighted: matches
      };
    });
     
    console.log(result);
    /**
     * [
          { isHighlighted: false, text: 'a' },
          { isHighlighted: true, text: 'b' },
          { isHighlighted: true, text: 'cd' }
        ]
     *
     */

    Changelog

    License

    MIT

    Install

    npm i strind

    DownloadsWeekly Downloads

    184

    Version

    0.3.1

    License

    MIT

    Unpacked Size

    7.89 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar