包详细信息

strind

metonym2.4kMIT0.3.1

Partition strings based on character indices

string, string manipulation, partition, char

自述文件

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

更新日志

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.3.1 - 2019-10-13

  • Upgrade development dependencies (@commitlint/cli, pretty-quick, lodash.template, ts-jest, tslint, typescript)

0.3.0 - 2019-09-05

  • Change build target from es6 to es5

0.2.1 - 2019-07-13

0.2.0 - 2019-07-13

  • Return object containing matched and unmatched values (2fc5387)

0.1.1 - 2019-07-10

  • Set floor and ceiling for matching character once (5eebcdd)

  • Update nonmatched characters if index is 0 (3b86e81)

0.1.0 - 2019-07-09

  • Initial release