1.0.1 • Published 6 years ago

dat-palindrome-doe v1.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

dat-palindrome-doe

determine if given string is a palindrome or not

configure the algorithm with custom options. the default configuration is this (merged with custom configs when provided)

const defaultConfig = {

  // first deal with special cases (assessed before validation of input)
  specialIs: value => value === 0 || value === '',
  specialIsNot: value => !value || value === true,

  // then validate input
  validateInput: value => typeof value === "string" || typeof value === "number",

  // algorithm functions
  filter: char => /^[a-z0-9]+$/i.test(char), // isAlphaNumeric
  compare: (a, b) => !!a && !!b && a.toLowerCase() === b.toLowerCase(), // leftEqualsRightWhenBothLowercase
  
}

usage with default configs

const isPalidrome = require('dat-palindrome-doe')()
console.log(isPalindrome('abcd_DCBA')) // true

usage with custom configs

const isPalidrome = require('dat-palindrome-doe')({
  compare: (a, b) => !!a && !!b && a === b // case-senstitive comparator
})
console.log(isPalindrome('abcd_DCBA')) // false