@sskmy1024y/react-native-hash
Version:
A hashing library for react-native
51 lines (45 loc) • 1.05 kB
JavaScript
/* eslint linebreak-style: ["error", "windows"] */
/* eslint-disable no-use-before-define */
import Latin1 from './Latin1.js';
/**
* UTF-8 encoding strategy.
*/
const Utf8 = {
/**
* Converts a word array to a UTF-8 string.
*
* @param {WordArray} wordArray The word array.
*
* @return {string} The UTF-8 string.
*
* @static
*
* @example
*
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
*/
stringify(wordArray) {
try {
return decodeURIComponent(escape(Latin1.stringify(wordArray)));
} catch (e) {
throw new Error('Malformed UTF-8 data');
}
},
/**
* Converts a UTF-8 string to a word array.
*
* @param {string} utf8Str The UTF-8 string.
*
* @return {WordArray} The word array.
*
* @static
*
* @example
*
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
*/
parse(utf8Str) {
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
},
};
export default Utf8;