Verified Commit ff692c4e authored by Daniel Sieradski's avatar Daniel Sieradski 💬

getting there

parent 77e60653
import mappings from './mappings'
import { solo, duo, trio } from './mappings'
const hex = str => {
if (typeof str !== 'string') throw new Error('utfu requires a string to process')
mappings.forEach(mapping => {
const hex = new RegExp(`${mapping.utf8}`, 'gu')
str = str.replace(hex, mapping.char)
trio.forEach(mapping => {
str = str.replace(mapping.misrender.regex, mapping.utf8.hex)
})
duo.forEach(mapping => {
str = str.replace(mapping.misrender.regex, mapping.utf8.hex)
})
solo.forEach(mapping => {
str = str.replace(mapping.misrender.regex, mapping.utf8.hex)
})
return str
}
const txt = str => {
if (typeof str !== 'string') throw new Error('utfu requires a string to process')
mappings.forEach(mapping => {
const text = new RegExp(`${mapping.misrender}`, 'gu')
str = str.replace(text, mapping.utf8)
trio.forEach(mapping => {
str = str.replace(mapping.misrender.regex, mapping.utf8.char)
})
duo.forEach(mapping => {
str = str.replace(mapping.misrender.regex, mapping.utf8.char)
})
solo.forEach(mapping => {
str = str.replace(mapping.misrender.regex, mapping.utf8.char)
})
return str
}
......
This diff is collapsed.
import utfu from '../src/index.js'
import mappings from '../src/mappings'
import { hex, txt } from '../src/index.js'
import { solo, duo, trio } from '../src/mappings'
mappings.forEach(mapping => {
const str = mapping.misrender
test(`replace ${mapping.misrender} with ${mapping.char}`, () => {
expect(utfu.hex(str)).toBe(mapping.char)
trio.forEach(mapping => {
const str = mapping.misrender.chars
test(`replace ${str} with ${mapping.utf8.char}`, () => {
expect(txt(str)).toBe(mapping.utf8.char)
})
test(`replace ${mapping.misrender} with ${mapping.char}`, () => {
expect(utfu.txt(str)).toBe(mapping.char)
test(`replace ${str} with ${mapping.utf8.hex}`, () => {
expect(hex(str)).toBe(mapping.utf8.hex)
})
})
duo.forEach(mapping => {
const str = mapping.misrender.chars
test(`replace ${str} with ${mapping.utf8.char}`, () => {
expect(txt(str)).toBe(mapping.utf8.char)
})
test(`replace ${str} with ${mapping.utf8.hex}`, () => {
expect(hex(str)).toBe(mapping.utf8.hex)
})
})
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment