1.0.0 • Published 10 months ago

word-postfixes v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

word-postfixes

This package returns all the postfixes of a given word.

Installation

npm install word-postfixes

Usage

const getPostfixes = require('word-postfixes');

console.log(getPostfixes('postfix')); 
// Output: ['postfix', 'ostfix', 'stfix', 'tfix', 'fix', 'ix', 'x']

console.log(getPostfixes('a')); 
// Output: ['a']

console.log(getPostfixes('')); 
// Output: []

console.log(getPostfixes(123)); 
// Output: ['123', '23', '3']

// If a non-string or non-number is passed, an error will be thrown
try {
  console.log(getPostfixes({}));
} catch (error) {
  console.error(error.message); 
  // Output: Expected a string or a number
}

Sample Results

Input: 'postfix'

['postfix', 'ostfix', 'stfix', 'tfix', 'fix', 'ix', 'x']

Input: 'a'

['a']

Input: '' (empty string)

[]

Input: 123 (number)

['123', '23', '3']

Input: {} (non-string/number)

TypeError: Expected a string or a number

License

MIT