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! ๐๐
@igorskyflyer
Install it by executing:
npm i "@igor.dvlpr/mapped-replacer"
Creates a new instance of MappedReplacer
.
options
is a variable of type IOptions
defined as:
-
caseSensitive
- A Boolean that indicates whether replacing should be case-sensitive or not. Default istrue
. -
strict
- A Boolean that indicates whether strict mode is enabled. In strict mode, only whole matches are replaced. Default isfalse
.
Adds a new rule or updates an existing rule used in replacing a single string.
replaceWith
- The string to replace the searchFor
with.
searchFor
- The string to be replaced.
Returns true if the rule was added or updated successfully, false otherwise.
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 ๐'
Adds a new rule or updates an existing rule for character replacement with multiple subjects.
replaceWith
- The string to replace the searchFor
with.
searchFor
- The array of strings to be replaced.
Returns true if the rule was added or updated successfully, false otherwise.
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRule('๐', [':smile:', ':D'])
console.log(mapper.replace('Hello world :smile: :D')) // outputs 'Hello world ๐ ๐'
Adds or updates the rules for string replacement.
rules
- A simple key-value object, i.e.:
{
'<' : '<',
'>' : '>'
}
Returns a Boolean whether the rules were added/updated successfully.
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRules({
'𝕋' : '๐',
'≈' : 'โ',
'𝔱' : '๐ฑ'
})
console.log(mapper.replace('๐ โ ๐ฑ')) // outputs '𝕋 ≈ 𝔱'
Adds or updates the rules for string replacement.
rules
- A simple key-value[] object, i.e.:
{
'๐' : [':D', ':-D'],
'๐' : [':P', ':-P']
}
Returns a Boolean whether the rules were added/updated successfully.
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRules({
'๐' : [':D', ':-D'],
'๐' : [':P', ':-P']
})
console.log(mapper.replace('Hello :D world :-D this is a :P test :-P')) // outputs 'Hello ๐ world ๐ this is a ๐ test ๐'
Checks whether a rule is present in the Map.
rule
- The rule to check for.
Returns a Boolean indicating the existence of the given rule.
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRule('𝕋', '๐')
mapper.addRule('≈', 'โ')
console.log(mapper.hasRule('๐')) // true
Removes the rule that matches the provided value.
searchFor
- The rule to remove.
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRule('𝕋', '๐')
mapper.addRule('≈', 'โ')
mapper.removeRule('๐')
console.log(mapper.replace('๐ โ ๐ฑ')) // outputs '๐ ≈ ๐ฑ'
Gets the number of rules for string replacing.
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRule('𝕋', '๐')
console.log(mapper.rulesCount()) // outputs 1
Clears all the rules.
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRule('𝕋', '๐')
mapper.clearRules()
console.log(mapper.rulesCount()) // outputs 0
Replaces the values in the input with the values from the Map.
input
- The input string.
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRule('→', 'โ')
console.log(mapper.replace('a โ b')) // outputs 'a → b'
example.ts
import { MappedReplacer } from '@igor.dvlpr/mapped-replacer'
const mapper: MappedReplacer = new MappedReplacer()
mapper.addRule('→', 'โ')
console.log(mapper.replace('a โ b')) // outputs 'a → b'
๐ The changelog is available here: CHANGELOG.md.
Licensed under the MIT license which is available here, MIT license.
๐งต Provides ways of checking whether a String is present in an Array of Strings using custom Comparators. ๐
โ DรบรถScrรญbรฎ allows you to convert letters with diacritics to regular letters. ๐ค
@igor.dvlpr/strip-yaml-front-matter
๐ฆ Strips YAML front matter from a String or a file. ๐พ
๐โโ๏ธ Fast and simple Map and RegExp based HTML entities encoder. ๐
๐ฅ Removes HTML code from the given string. Can even extract text-only from the given an HTML string. โจ
Created by Igor Dimitrijeviฤ (@igorskyflyer).