Skip to content

πŸ—Ί Zero-dependency Map and RegExp based string replacer with Unicode support. 🍁

License

Notifications You must be signed in to change notification settings

igorskyflyer/npm-mapped-replacer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

97 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—Ί Mapped Replacer 🍁


πŸ—Ί Zero-dependency Map and RegExp based string replacer with Unicode support. 🍁



πŸ’– Support further development

I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. β˜•
Thank you for supporting my efforts! πŸ™πŸ˜Š


Donate to igorskyflyer

@igorskyflyer


πŸ•΅πŸΌ Usage

Install it by executing:

npm i "@igor.dvlpr/mapped-replacer"

🀹🏼 API

addRule(key: string, value: string): boolean

Adds a new rule or updates the existing rule for character replacing.

import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'

const mapper: MappedReplacer = new MappedReplacer()

mapper.addRule(':smile:', 'πŸ˜€')

console.log(mapper.replace('Hello world :smile:')) // outputs 'Hello world πŸ˜€'

addRules(rules: Object): boolean

Adds rules or updates the existing rules for character replacing. Passed object is a simple key-value object, i.e. { '<': '&#60;', '>': '&#62;'}

import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'

const mapper: MappedReplacer = new MappedReplacer()

mapper.addRules({
  '𝕋': '&#120139;',
  'β‰ˆ': '&#8776;',
  '𝔱': '&#120113;',
})

console.log(mapper.replace('𝕋 β‰ˆ 𝔱')) // outputs '&#120139; &#8776; &#120113;'

removeRule(key: string): boolean

Removes the rule that matches the provided key.

import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'

const mapper: MappedReplacer = new MappedReplacer()

mapper.addRule('𝕋', '&#120139;')
mapper.addRule('β‰ˆ', '&#8776;')

mapper.removeRule('𝕋')

console.log(mapper.replace('𝕋 β‰ˆ 𝔱')) // outputs '𝕋 &#8776; 𝔱'

rulesCount(): number

Gets the number of rules for character replacing.

import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'

const mapper: MappedReplacer = new MappedReplacer()

mapper.addRule('𝕋', '&#120139;')

console.log(mapper.rulesCount()) // outputs 1

clearRules(): void

Clears all the rules.

import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'

const mapper: MappedReplacer = new MappedReplacer()

mapper.addRule('𝕋', '&#120139;')
mapper.clearRules()

console.log(mapper.rulesCount()) // outputs 0

replace(input: string): string

Replaces the values in the input that match the keys in the Map object.

import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'

const mapper: MappedReplacer = new MappedReplacer()

mapper.addRule('β†’', '&#8594;')

console.log(mapper.replace('a β†’ b')) // outputs 'a &#8594; b'

πŸͺͺ License

Licensed under the MIT license which is available here, MIT license.


🧬 Related

@igor.dvlpr/zep

🧠 Zep is a zero-dependency, efficient debounce module. ⏰

@igor.dvlpr/strip-html

πŸ₯ž Removes HTML code from the given string. Can even extract text-only from the given an HTML string. ✨

@igor.dvlpr/registry-apppaths

πŸͺ€ A Node.js module for reading the AppPaths registry key on Windows. Useful for retrieving applications that can be launched from the command prompt. πŸ—ƒ

@igor.dvlpr/adblock-filter-counter

🐲 A dead simple npm module that counts Adblock filter rules.🦘

@igor.dvlpr/unc-path

πŸ₯½ Provides ways of parsing UNC paths and checking whether they are valid. 🎱



Provided by Igor Dimitrijević (@igorskyflyer).