abbrev-string-array
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

abbrev-string-array

Abbreviate strings by assigning a distinct minimum value to each element in the array.

Installing

Package manager

Using npm:

$ npm install abbrev-string-array

Using yarn:

$ yarn add abbrev-string-array

Once the package is installed, import the library:

import abbrev from 'abbrev-string-array';

[Since the function is exported using default export, you can use any name instead of 'abbrev' as the name for the imported function.]

Examples

abbrev ([strings], {opts})

Default option values :

   matchAlikeLen = false, 
   matchAll = false, 
   suffix = null, 
   minLen = null, 
   caseSensitive = false
const arr = ['Monday', 'Tuesday', 'Wednesday', 'Thursday']
abbrev (arr) 
// ['M', 'T', 'W', 'Th']
const arr = ['Monday', 'Tuesday', 'Wednesday', 'Thursday']
abbrev (arr, {matchAlikeLen: true}) 
// ['M', 'Tu', 'W', 'Th']
const arr = ['Monday', 'Tuesday', 'Wednesday', 'Thursday']
abbrev (arr, {matchAll: true}) 
// ['Mo', 'Tu', 'We', 'Th']
const arr = ['Cata', 'Catalyst', 'catabolism']
abbrev (arr, {suffix:  '.'}) 
// ['C.', 'Ca.', 'cat.']
const arr = ['January', 'February', 'June', 'July']
abbrev (arr) 
// ['J', 'F', 'Ju', 'Jul',]

abbrev (arr, {minLen:  2}) 
// ['Ja', 'Fe', 'Ju', 'Jul']
const arr = ['None', 'novice', 'All']
abbrev (arr) 
// ['N', 'no', 'A']

abbrev (arr, {caseSensitive:  true}) 
// ['N', 'n', 'A']

Test

npm test

Future work

  • Provide support for acronyms when the word is delimited by a space or some other characters. eg: ['Science Fiction', 'Action Comedy', 'Romantic Drama'] ===> ['SF', 'AC', 'RD']

  • Enable the addition of a unique value, such as a number, when there are distinct strings eg: ['mon', 'mon', 'tue'] ===> ['m.1', 'm.2', 't']

Resources

License

abbrev-string-array is freely distributable under the terms of the MIT license.

Package Sidebar

Install

npm i abbrev-string-array

Weekly Downloads

2

Version

1.0.1

License

ISC

Unpacked Size

8.74 kB

Total Files

5

Last publish

Collaborators

  • eyob.samuel