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

clear cache

parent 45e2b519
......@@ -27,7 +27,7 @@
.LSOverride
# Icon must end with two \r
Icon
Icon
# Thumbnails
._*
......@@ -152,5 +152,6 @@ dist/
# Temporary folders
tmp/
temp/
pkg/
# End of https://www.gitignore.io/api/linux,macos,dotenv,node
Copyright (c) 2020, Daniel Sieradski
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
<h1 align="center">Welcome to utfu 👋</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-0.2.3-blue.svg?cacheSeconds=2592000" />
<a href="#" target="_blank">
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
</a>
<a href="https://twitter.com/selfagency_llc" target="_blank">
<img alt="Twitter: selfagency\_llc" src="https://img.shields.io/twitter/follow/selfagency_llc.svg?style=social" />
</a>
</p>
> Replaces busted characters carried over from legacy text encodings with the proper UTF-8 characters.
## Install
```sh
yarn add utfu || npm install utfu
```
## Usage
Say you've got a string that looks like this:
`There’s no way I’m paying €30 for that!`
Pass it to either method, `hex`, `txt`, or `htx` and you'll hopefully get back:
`There’s no way I’m paying €30 for that!`
`hex` substitutes unicode hex values (ie., `\u20ac`), which is useful in some contexts. `txt` substitutes the actual character (ie., `€`). And `htx` substitutes the HTML escape sequence (ie., `&#x20AC;`). See chart [here](https://www.i18nqa.com/debug/utf8-debug.html) for mappings.
```javascript
import { hex, txt, htx } from 'utfu'
const dirtyText = 'On a certain level, it�s like shouting �fire� in a crowded theater.'
const cleanText = hex(dirtyText) || txt(dirtyText)
// --> 'On a certain level, it’s like shouting “fire” in a crowded theater.'
const cleanHTML = htx(dirtyText)
// --> 'On a certain level, it&#x2019;s like shouting &#x201C;fire&#x201D; in a crowded theater.'
```
## Run tests
```sh
yarn run test
```
## Author
👤 **Daniel Sieradski <[email protected]>**
- Website: [self.agency](https://self.agency)
- Twitter: [@selfagency_llc](https://twitter.com/selfagency_llc)
- GitLab: [@selfagency](https://gitlab.com/selfagency)
- LinkedIn: [@selfagency](https://linkedin.com/in/selfagency)
## Acknowledgements
Gracious thanks to [Mathias Bynens](https://mathiasbynens.be/), upon whose [he](https://github.com/mathiasbynens/he) and [windows-1252](https://github.com/mathiasbynens/windows-1252) packages this project depends.
## 🤝 Contributing
Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://gitlab.com/selfagency/utfu/issues).
## Show your support
Give a ⭐️ if this project helped you!
---
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
import he from 'he';
import win from 'windows-1252';
import mappings from './mappings.js';
const hex = str => {
if (typeof str !== 'string') throw new Error('utfu requires a string to process');
str = win.decode(win.encode(str));
mappings.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');
str = win.decode(win.encode(str));
mappings.forEach(mapping => {
str = str.replace(mapping.misrender.regex, mapping.utf8.chars);
});
return str;
};
const htx = str => {
if (typeof str !== 'string') throw new Error('utfu requires a string to process');
str = win.decode(win.encode(str));
mappings.forEach(mapping => {
str = str.replace(mapping.misrender.regex, he.encode(mapping.utf8.chars));
});
return str;
};
export { hex, txt, htx };
\ No newline at end of file
This diff is collapsed.
export function hex(str: any): any;
export function txt(str: any): any;
export function htx(str: any): any;
declare var _default: {
misrender: {
chars: string;
hex: string;
regex: RegExp;
};
utf8: {
chars: string;
hex: string;
regex: RegExp;
};
}[];
export default _default;
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
{
"name": "utfu",
"description": "Replaces busted characters carried over from legacy text encodings with the proper UTF-8 characters.",
"version": "0.2.3",
"license": "MIT",
"files": [
"dist-*/",
"bin/"
],
"pika": true,
"sideEffects": false,
"keywords": [
"utf",
"utf-8",
"unicode",
"windows-1252",
"fix",
"replace",
"convert",
"characters"
],
"repository": "https://gitlab.com/selfagency/utfu.git",
"dependencies": {
"he": "^1.2.0",
"windows-1252": "^1.0.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.6",
"@pika/pack": "^0.5.0",
"@pika/plugin-build-node": "^0.9.2",
"@pika/plugin-build-types": "^0.9.2",
"@pika/plugin-build-web": "^0.9.2",
"@pika/plugin-bundle-node": "^0.9.2",
"@pika/plugin-bundle-web": "^0.9.2",
"@pika/plugin-standard-pkg": "^0.9.2",
"babel-eslint": "^10.1.0",
"babel-jest": "^25.4.0",
"babel-loader": "^8.1.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^4.0.1",
"jest": "^25.4.0",
"pika-plugin-minify": "^0.1.0",
"prettier": "^2.0.5",
"typescript": "^3.8.3"
},
"private": false,
"esnext": "dist-src/index.js",
"main": "dist-node/index.js",
"module": "dist-web/index.js",
"browser": "dist-web/index.bundled.js",
"types": "dist-types/index.d.ts"
}
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