@gf-ui/core
Version:
1,883 lines (1,624 loc) • 346 kB
JavaScript
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
var toString$1 = Object.prototype.toString;
var is = function is(type) {
var primitive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return function (obj) {
return primitive ? typeof obj === type.toLowerCase() : toString$1.call(obj) === "[object ".concat(type, "]");
};
};
var match = (item, pattern, flags) => {
var regex = new RegExp(pattern, flags);
return regex.test(String(item));
};
/**
* @constant 非对称加密算法类型
*/
var ASYMMETRIC_CRYPTO_TYPE = {
md5: {
name: "MD5"
},
sha1: {
name: "SHA1"
},
sha3: {
name: "SHA3"
},
sha224: {
name: "SHA224"
},
sha256: {
name: "SHA256"
},
sha384: {
name: "SHA384"
},
sha512: {
name: "SHA512"
},
hmacmd5: {
name: "HmacMD5",
hmac: true
},
hmacsha1: {
name: "HmacSHA1",
hmac: true
},
hmacsha3: {
name: "HmacSHA3",
hmac: true
},
hmacsha224: {
name: "HmacSHA224",
hmac: true
},
hmacsha256: {
name: "HmacSHA256",
hmac: true
},
hmacsha384: {
name: "HmacSHA384",
hmac: true
},
hmacsha512: {
name: "HmacSHA512",
hmac: true
},
pbkdf2: {
name: "PBKDF2",
params: {
keySize: 128 / 32,
iterations: 10
}
},
evpkdf: {
name: "EvpKDF",
params: {
keySize: 128 / 32,
iterations: 10
}
},
ripemd160: {
name: "RIPEMD160",
params: {
keySize: 128 / 32,
iterations: 10
}
},
none: {
name: ""
}
};
/**
* @constant 对称加密算法类型
*/
var SYMMETRIC_CRYPTO_TYPE = {
base64: {
name: "Base64",
encoding: true
},
aes: {
name: "AES"
},
des: {
name: "DES"
},
rc4: {
name: "RC4",
iv: false
},
rabbit: {
name: "Rabbit"
},
rabbitlegacy: {
name: "RabbitLegacy"
},
none: {
name: ""
}
};
/**
* @constant 正则表达式常量
*/
var DATA_REGEX_PATTERN = {
guid: "^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$",
mobile: "^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}$",
tel: "^(\\d{3,4}-\\d{7,8}-\\d{1,5})|(^\\d{3,4}-\\d{7,8})$",
email: "^[0-9a-z][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}[0-9a-z]\\.){1,4}[a-z]{2,4}$",
idcard: "^\\d{18,18}|\\d{15,15}|\\d{17,17}x|\\d{17,17}X$",
secure: "^(.{before})(?:\\w+)(.{after})$",
letterNumber: "^(?=.*[0-9])(?=.*[a-zA-Z]).{min,max}$",
letterNumberChar: "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{min,max}$",
letterNumberCharCase: "^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9]).{min,max}$",
encode: /(["'<>]|&(?:(amp|lt|gt|#39|nbsp|quot|#\d+);)?)/g,
decode: /&(amp|lt|gt|#39|nbsp|quot);/g,
highlight: /[.[*?+^$|()/]|\\]|\\/g,
trim: /^[\s\uFEFF]+|[\s\uFEFF]+$/g,
kebab: /([^-])([A-Z])/g,
camel: /([\\:\-\\_]+(.))/g,
uncamel: /([a-z\d])([A-Z])/g,
html: /<\/?.+?\/?>/g
};
/**
* @constant 存储类型常量
*/
var STORAGE_TYPE = {
local: "local",
session: "session"
};
/**
* @constant 存储配置常量
*/
var DEFAULT_STORAGE_OPTIONS = {
storageType: STORAGE_TYPE.local,
cryptoType: SYMMETRIC_CRYPTO_TYPE.none,
cryptoKey: "gf-key",
cryptoIv: "gf-iv"
};
/*
* @constant 请求方法常量
*/
var REQUEST_METHOD = {
get: 'get',
post: 'post',
put: 'put',
patch: 'patch',
del: 'delete'
};
/*
* @constant 请求数据格式
*/
var CONTENT_TYPE = {
encoded: 'application/x-www-form-urlencoded',
json: 'application/json',
form: 'multipart/form-data'
};
/*
* @constant 请求默认配置
*/
var DEFAULT_REQUEST_OPTIONS = {
origin: false,
timeout: 30000,
retry: 0,
method: REQUEST_METHOD.get,
headers: EMPTY_OBJECT,
request: EMPTY_FUNC,
response: EMPTY_FUNC,
reject: EMPTY_FUNC,
loading: EMPTY_FUNC,
result: {
code: 'code',
success: 'success',
data: 'data',
message: 'message'
}
};
/*
* @constant 空类型默认
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
var EMPTY_FUNC = function EMPTY_FUNC() {};
var EMPTY_ARRAY = [];
var EMPTY_OBJECT = {};
class Type {
/**
* @method 检测当前类型是否是对象
* @param item 检测当前类型
* @returns { Boolean } 如果是对象则返回true、否则返回false
*/
static isObject(item) {
return is('Object')(item);
}
/**
* @method 检测当前类型是否为纯粹对象(非window或者系统对象)
* @param item 检测当前类型
* @returns { Boolean } 如果是普通对象则返回true、否则返回false
*/
static isPlainObject(item) {
if (typeof item !== 'object' || item === null) return false;
var proto = item;
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto);
}
return Object.getPrototypeOf(item) === proto;
}
/**
* @method 检测当前类型是否是空对象
* @param item 检测当前类型
* @returns { Boolean } 如果为空的对象则返回true、否则返回false
*/
static isEmptyObject(item) {
return Type.isObject(item) && Object.keys(item).length === 0;
}
/**
* @method 检测当前类型是否是数组
* @param item 检测当前类型
* @returns { Boolean } 如果是数组则返回true、否则返回false
*/
static isArray(item) {
return Array.isArray(item) || is('Array')(item);
}
/**
* @method 检测当前类型是否是空数组
* @param item 检测当前类型
* @returns { Boolean } 如果为空数组则返回true、否则返回false
*/
static isEmptyArray(item) {
return Type.isArray(item) && item.length === 0;
}
/**
* @method 检测当前类型是否为函数
* @param item 检测当前类型
* @returns { Boolean } 如果是函数则返回true、否则返回false
*/
static isFunction(item) {
return is('Function')(item);
}
/**
* @method 检测当前类型是否为空函数
* @param item 检测当前类型
* @returns { Boolean } 如果是空函数则返回true、否则返回false
*/
static isEmptyFunction(item) {
if (!item) return true;
var str = item.toString().replace(/\s/g, '');
return Type.isFunction(item) && (str === 'functionEMPTY_FUNC(){}' || str === 'function(){}' || str === '()=>{}');
}
/**
* @method 检测当前类型是否为字符串
* @param item 检测当前类型
* @returns { Boolean } 如果是字符串则返回true、否则返回false
*/
static isString(item) {
return is('String', true)(item);
}
/**
* @method 检测当前类型是否为空字符串
* @param item 检测当前类型
* @returns { Boolean } 如果是空字符串则返回true、否则返回false
*/
static isEmptyString(item) {
return is('String', true)(item) && item.trim().length === 0;
}
/**
* @method 检测当前类型是否为JSON字符串
* @param item 检测当前类型
* @returns { Boolean } 如果是JSON字符串则返回true、否则返回false
*/
static isJsonString(item) {
try {
if (typeof JSON.parse(item) === 'object') return true;
} catch (_unused) {
return false;
}
}
/**
* @method 检测当前类型是否为数字
* @param item 检测当前类型
* @returns { Boolean } 如果是数字则返回true、否则返回false
*/
static isNumber(item) {
return is('Number', true)(item);
}
/**
* @method 检测当前类型是否为布尔
* @param item 检测当前类型
* @returns { Boolean } 如果是布尔则返回true、否则返回false
*/
static isBoolean(item) {
return is('Boolean', true)(item);
}
/**
* @method 检测当前类型是否为Guid对象
* @param item 检测当前类型
* @param pattern 当前检测的正则匹配表达式(默认值:DATA_REGEX_PATTERN.guid)
* @returns { Boolean } 如果是Guid对象返回true、否则返回false
*/
static isGuid(item) {
var pattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DATA_REGEX_PATTERN.guid;
return match(item, pattern, 'i');
}
/**
* @method 检测当前类型是否为正确的手机号
* @param item 检测当前类型
* @param pattern 当前检测的正则匹配表达式(默认值:DATA_REGEX_PATTERN.mobile)
* @returns { Boolean } 如果是为正确的手机号返回true、否则返回false
*/
static isMobilePhone(item) {
var pattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DATA_REGEX_PATTERN.mobile;
return match(item, pattern);
}
/**
* @method 检测当前类型是否为座机号
* @param item 检测当前类型
* @param pattern 当前检测的正则匹配表达式(默认值:DATA_REGEX_PATTERN.Tel
* @returns { Boolean } 如果是座机号返回true、否则返回false
*/
static isTelPhone(item) {
var pattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DATA_REGEX_PATTERN.tel;
return match(item, pattern);
}
/**
* @method 检测当前类型是否为电话号码(手机或者座机)
* @param item 检测当前类型
* @param {Object} {mobile,tel} 当前检测手机和座机的正则匹配表达式(默认值:DATA_REGEX_PATTERN.mobile和DATA_REGEX_PATTERN.tel)
* @returns { Boolean } 如果是座机号返回true、否则返回false
*/
static isPhone(item) {
var {
mobile = DATA_REGEX_PATTERN.mobile,
tel = DATA_REGEX_PATTERN.tel
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return Type.isMobilePhone(item, mobile) || Type.isTelPhone(item, tel);
}
/**
* @method 检测当前类型是否正确邮箱
* @param item 检测当前类型
* @param pattern 当前检测的正则匹配表达式(默认值:DATA_REGEX_PATTERN.email)
* @returns { Boolean } 如果是正确邮箱返回true、否则返回false
*/
static isEmail(item) {
var pattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DATA_REGEX_PATTERN.email;
return match(item, pattern);
}
/**
* @method 检测当前类型是否正确身份证(支持15位或18位)
* @param item 检测当前类型
* @param pattern 当前检测的正则匹配表达式(默认值:DATA_REGEX_PATTERN.idcard)
* @returns { Boolean } 如果是正确身份证返回true、否则返回false
*/
static isIdCard(item) {
var pattern = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DATA_REGEX_PATTERN.idcard;
return match(item, pattern);
}
/**
* @method 检测密码复杂度规则
* @param item 检测当前类型
* @param options 当前检测密码复杂度的配置选项(默认值:{ pattern: DATA_REGEX_PATTERN.letterNumberChar, min: 8, max: 30 })
* @returns { Boolean } 如果是正确复杂度规则返回true、否则返回false
*/
static isValidPassword(item) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _default = {
pattern: DATA_REGEX_PATTERN.letterNumber,
min: 8,
max: 30
};
var _options = _objectSpread2(_objectSpread2({}, _default), options);
return match(item, _options.pattern.replace("{min,max}", "{".concat(_options.min, ",").concat(_options.max, "}")));
}
/**
* @method 检测日期是否合法
* @param item 检测当前类型
* @returns { Boolean } 如果是合法日期返回true、否则返回false
*/
static isValidDate(item) {
return item instanceof Date && !isNaN(item.getTime());
}
/**
* @method 检测当前值是0或者true条件
* @param item 检测当前类型
* @returns { Boolean } 如果是0或者true条件返回true、否则返回false
*/
static isTrueOrZero(item) {
return !!item || item === 0 || item === '0';
}
/**
* @method 检测当前值是0或者true条件
* @param item 检测当前类型
* @returns { Boolean } 如果是0或者true条件返回true、否则返回false
*/
static def(item, defs) {
return item === undefined || item === null ? defs : item;
}
/**
* @method 将当前的JSON转化为相应的对象
* @param item 当前的JSON
* @param defs 默认值
* @returns {Object|Array} 如果当前数据可以转化成功则转化,否则将返回默认值
*/
static json(item, defs) {
try {
return JSON.parse(item);
} catch (e) {
return defs;
}
}
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function getAugmentedNamespace(n) {
if (n.__esModule) return n;
var a = Object.defineProperty({}, '__esModule', {value: true});
Object.keys(n).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(n, k);
Object.defineProperty(a, k, d.get ? d : {
enumerable: true,
get: function () {
return n[k];
}
});
});
return a;
}
function commonjsRequire (path) {
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
}
var cryptoJs = {exports: {}};
var core = {exports: {}};
(function (module, exports) {
(function (root, factory) {
{
// CommonJS
module.exports = factory();
}
})(commonjsGlobal, function () {
/*globals window, global, require*/
/**
* CryptoJS core components.
*/
var CryptoJS = CryptoJS || function (Math, undefined$1) {
var crypto; // Native crypto from window (Browser)
if (typeof window !== 'undefined' && window.crypto) {
crypto = window.crypto;
} // Native crypto in web worker (Browser)
if (typeof self !== 'undefined' && self.crypto) {
crypto = self.crypto;
} // Native crypto from worker
if (typeof globalThis !== 'undefined' && globalThis.crypto) {
crypto = globalThis.crypto;
} // Native (experimental IE 11) crypto from window (Browser)
if (!crypto && typeof window !== 'undefined' && window.msCrypto) {
crypto = window.msCrypto;
} // Native crypto from global (NodeJS)
if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) {
crypto = commonjsGlobal.crypto;
} // Native crypto import via require (NodeJS)
if (!crypto && typeof commonjsRequire === 'function') {
try {
crypto = require('crypto');
} catch (err) {}
}
/*
* Cryptographically secure pseudorandom number generator
*
* As Math.random() is cryptographically not safe to use
*/
var cryptoSecureRandomInt = function cryptoSecureRandomInt() {
if (crypto) {
// Use getRandomValues method (Browser)
if (typeof crypto.getRandomValues === 'function') {
try {
return crypto.getRandomValues(new Uint32Array(1))[0];
} catch (err) {}
} // Use randomBytes method (NodeJS)
if (typeof crypto.randomBytes === 'function') {
try {
return crypto.randomBytes(4).readInt32LE();
} catch (err) {}
}
}
throw new Error('Native crypto module could not be used to get secure random number.');
};
/*
* Local polyfill of Object.create
*/
var create = Object.create || function () {
function F() {}
return function (obj) {
var subtype;
F.prototype = obj;
subtype = new F();
F.prototype = null;
return subtype;
};
}();
/**
* CryptoJS namespace.
*/
var C = {};
/**
* Library namespace.
*/
var C_lib = C.lib = {};
/**
* Base object for prototypal inheritance.
*/
var Base = C_lib.Base = function () {
return {
/**
* Creates a new object that inherits from this object.
*
* @param {Object} overrides Properties to copy into the new object.
*
* @return {Object} The new object.
*
* @static
*
* @example
*
* var MyType = CryptoJS.lib.Base.extend({
* field: 'value',
*
* method: function () {
* }
* });
*/
extend: function extend(overrides) {
// Spawn
var subtype = create(this); // Augment
if (overrides) {
subtype.mixIn(overrides);
} // Create default initializer
if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
subtype.init = function () {
subtype.$super.init.apply(this, arguments);
};
} // Initializer's prototype is the subtype object
subtype.init.prototype = subtype; // Reference supertype
subtype.$super = this;
return subtype;
},
/**
* Extends this object and runs the init method.
* Arguments to create() will be passed to init().
*
* @return {Object} The new object.
*
* @static
*
* @example
*
* var instance = MyType.create();
*/
create: function create() {
var instance = this.extend();
instance.init.apply(instance, arguments);
return instance;
},
/**
* Initializes a newly created object.
* Override this method to add some logic when your objects are created.
*
* @example
*
* var MyType = CryptoJS.lib.Base.extend({
* init: function () {
* // ...
* }
* });
*/
init: function init() {},
/**
* Copies properties into this object.
*
* @param {Object} properties The properties to mix in.
*
* @example
*
* MyType.mixIn({
* field: 'value'
* });
*/
mixIn: function mixIn(properties) {
for (var propertyName in properties) {
if (properties.hasOwnProperty(propertyName)) {
this[propertyName] = properties[propertyName];
}
} // IE won't copy toString using the loop above
if (properties.hasOwnProperty('toString')) {
this.toString = properties.toString;
}
},
/**
* Creates a copy of this object.
*
* @return {Object} The clone.
*
* @example
*
* var clone = instance.clone();
*/
clone: function clone() {
return this.init.prototype.extend(this);
}
};
}();
/**
* An array of 32-bit words.
*
* @property {Array} words The array of 32-bit words.
* @property {number} sigBytes The number of significant bytes in this word array.
*/
var WordArray = C_lib.WordArray = Base.extend({
/**
* Initializes a newly created word array.
*
* @param {Array} words (Optional) An array of 32-bit words.
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
*
* @example
*
* var wordArray = CryptoJS.lib.WordArray.create();
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
*/
init: function init(words, sigBytes) {
words = this.words = words || [];
if (sigBytes != undefined$1) {
this.sigBytes = sigBytes;
} else {
this.sigBytes = words.length * 4;
}
},
/**
* Converts this word array to a string.
*
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
*
* @return {string} The stringified word array.
*
* @example
*
* var string = wordArray + '';
* var string = wordArray.toString();
* var string = wordArray.toString(CryptoJS.enc.Utf8);
*/
toString: function toString(encoder) {
return (encoder || Hex).stringify(this);
},
/**
* Concatenates a word array to this word array.
*
* @param {WordArray} wordArray The word array to append.
*
* @return {WordArray} This word array.
*
* @example
*
* wordArray1.concat(wordArray2);
*/
concat: function concat(wordArray) {
// Shortcuts
var thisWords = this.words;
var thatWords = wordArray.words;
var thisSigBytes = this.sigBytes;
var thatSigBytes = wordArray.sigBytes; // Clamp excess bits
this.clamp(); // Concat
if (thisSigBytes % 4) {
// Copy one byte at a time
for (var i = 0; i < thatSigBytes; i++) {
var thatByte = thatWords[i >>> 2] >>> 24 - i % 4 * 8 & 0xff;
thisWords[thisSigBytes + i >>> 2] |= thatByte << 24 - (thisSigBytes + i) % 4 * 8;
}
} else {
// Copy one word at a time
for (var j = 0; j < thatSigBytes; j += 4) {
thisWords[thisSigBytes + j >>> 2] = thatWords[j >>> 2];
}
}
this.sigBytes += thatSigBytes; // Chainable
return this;
},
/**
* Removes insignificant bits.
*
* @example
*
* wordArray.clamp();
*/
clamp: function clamp() {
// Shortcuts
var words = this.words;
var sigBytes = this.sigBytes; // Clamp
words[sigBytes >>> 2] &= 0xffffffff << 32 - sigBytes % 4 * 8;
words.length = Math.ceil(sigBytes / 4);
},
/**
* Creates a copy of this word array.
*
* @return {WordArray} The clone.
*
* @example
*
* var clone = wordArray.clone();
*/
clone: function clone() {
var clone = Base.clone.call(this);
clone.words = this.words.slice(0);
return clone;
},
/**
* Creates a word array filled with random bytes.
*
* @param {number} nBytes The number of random bytes to generate.
*
* @return {WordArray} The random word array.
*
* @static
*
* @example
*
* var wordArray = CryptoJS.lib.WordArray.random(16);
*/
random: function random(nBytes) {
var words = [];
for (var i = 0; i < nBytes; i += 4) {
words.push(cryptoSecureRandomInt());
}
return new WordArray.init(words, nBytes);
}
});
/**
* Encoder namespace.
*/
var C_enc = C.enc = {};
/**
* Hex encoding strategy.
*/
var Hex = C_enc.Hex = {
/**
* Converts a word array to a hex string.
*
* @param {WordArray} wordArray The word array.
*
* @return {string} The hex string.
*
* @static
*
* @example
*
* var hexString = CryptoJS.enc.Hex.stringify(wordArray);
*/
stringify: function stringify(wordArray) {
// Shortcuts
var words = wordArray.words;
var sigBytes = wordArray.sigBytes; // Convert
var hexChars = [];
for (var i = 0; i < sigBytes; i++) {
var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 0xff;
hexChars.push((bite >>> 4).toString(16));
hexChars.push((bite & 0x0f).toString(16));
}
return hexChars.join('');
},
/**
* Converts a hex string to a word array.
*
* @param {string} hexStr The hex string.
*
* @return {WordArray} The word array.
*
* @static
*
* @example
*
* var wordArray = CryptoJS.enc.Hex.parse(hexString);
*/
parse: function parse(hexStr) {
// Shortcut
var hexStrLength = hexStr.length; // Convert
var words = [];
for (var i = 0; i < hexStrLength; i += 2) {
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << 24 - i % 8 * 4;
}
return new WordArray.init(words, hexStrLength / 2);
}
};
/**
* Latin1 encoding strategy.
*/
var Latin1 = C_enc.Latin1 = {
/**
* Converts a word array to a Latin1 string.
*
* @param {WordArray} wordArray The word array.
*
* @return {string} The Latin1 string.
*
* @static
*
* @example
*
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
*/
stringify: function stringify(wordArray) {
// Shortcuts
var words = wordArray.words;
var sigBytes = wordArray.sigBytes; // Convert
var latin1Chars = [];
for (var i = 0; i < sigBytes; i++) {
var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 0xff;
latin1Chars.push(String.fromCharCode(bite));
}
return latin1Chars.join('');
},
/**
* Converts a Latin1 string to a word array.
*
* @param {string} latin1Str The Latin1 string.
*
* @return {WordArray} The word array.
*
* @static
*
* @example
*
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
*/
parse: function parse(latin1Str) {
// Shortcut
var latin1StrLength = latin1Str.length; // Convert
var words = [];
for (var i = 0; i < latin1StrLength; i++) {
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << 24 - i % 4 * 8;
}
return new WordArray.init(words, latin1StrLength);
}
};
/**
* UTF-8 encoding strategy.
*/
var Utf8 = C_enc.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: function 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: function parse(utf8Str) {
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
}
};
/**
* Abstract buffered block algorithm template.
*
* The property blockSize must be implemented in a concrete subtype.
*
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
*/
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
/**
* Resets this block algorithm's data buffer to its initial state.
*
* @example
*
* bufferedBlockAlgorithm.reset();
*/
reset: function reset() {
// Initial values
this._data = new WordArray.init();
this._nDataBytes = 0;
},
/**
* Adds new data to this block algorithm's buffer.
*
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
*
* @example
*
* bufferedBlockAlgorithm._append('data');
* bufferedBlockAlgorithm._append(wordArray);
*/
_append: function _append(data) {
// Convert string to WordArray, else assume WordArray already
if (typeof data == 'string') {
data = Utf8.parse(data);
} // Append
this._data.concat(data);
this._nDataBytes += data.sigBytes;
},
/**
* Processes available data blocks.
*
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
*
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
*
* @return {WordArray} The processed data.
*
* @example
*
* var processedData = bufferedBlockAlgorithm._process();
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
*/
_process: function _process(doFlush) {
var processedWords; // Shortcuts
var data = this._data;
var dataWords = data.words;
var dataSigBytes = data.sigBytes;
var blockSize = this.blockSize;
var blockSizeBytes = blockSize * 4; // Count blocks ready
var nBlocksReady = dataSigBytes / blockSizeBytes;
if (doFlush) {
// Round up to include partial blocks
nBlocksReady = Math.ceil(nBlocksReady);
} else {
// Round down to include only full blocks,
// less the number of blocks that must remain in the buffer
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
} // Count words ready
var nWordsReady = nBlocksReady * blockSize; // Count bytes ready
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); // Process blocks
if (nWordsReady) {
for (var offset = 0; offset < nWordsReady; offset += blockSize) {
// Perform concrete-algorithm logic
this._doProcessBlock(dataWords, offset);
} // Remove processed words
processedWords = dataWords.splice(0, nWordsReady);
data.sigBytes -= nBytesReady;
} // Return processed words
return new WordArray.init(processedWords, nBytesReady);
},
/**
* Creates a copy of this object.
*
* @return {Object} The clone.
*
* @example
*
* var clone = bufferedBlockAlgorithm.clone();
*/
clone: function clone() {
var clone = Base.clone.call(this);
clone._data = this._data.clone();
return clone;
},
_minBufferSize: 0
});
/**
* Abstract hasher template.
*
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
*/
C_lib.Hasher = BufferedBlockAlgorithm.extend({
/**
* Configuration options.
*/
cfg: Base.extend(),
/**
* Initializes a newly created hasher.
*
* @param {Object} cfg (Optional) The configuration options to use for this hash computation.
*
* @example
*
* var hasher = CryptoJS.algo.SHA256.create();
*/
init: function init(cfg) {
// Apply config defaults
this.cfg = this.cfg.extend(cfg); // Set initial values
this.reset();
},
/**
* Resets this hasher to its initial state.
*
* @example
*
* hasher.reset();
*/
reset: function reset() {
// Reset data buffer
BufferedBlockAlgorithm.reset.call(this); // Perform concrete-hasher logic
this._doReset();
},
/**
* Updates this hasher with a message.
*
* @param {WordArray|string} messageUpdate The message to append.
*
* @return {Hasher} This hasher.
*
* @example
*
* hasher.update('message');
* hasher.update(wordArray);
*/
update: function update(messageUpdate) {
// Append
this._append(messageUpdate); // Update the hash
this._process(); // Chainable
return this;
},
/**
* Finalizes the hash computation.
* Note that the finalize operation is effectively a destructive, read-once operation.
*
* @param {WordArray|string} messageUpdate (Optional) A final message update.
*
* @return {WordArray} The hash.
*
* @example
*
* var hash = hasher.finalize();
* var hash = hasher.finalize('message');
* var hash = hasher.finalize(wordArray);
*/
finalize: function finalize(messageUpdate) {
// Final message update
if (messageUpdate) {
this._append(messageUpdate);
} // Perform concrete-hasher logic
var hash = this._doFinalize();
return hash;
},
blockSize: 512 / 32,
/**
* Creates a shortcut function to a hasher's object interface.
*
* @param {Hasher} hasher The hasher to create a helper for.
*
* @return {Function} The shortcut function.
*
* @static
*
* @example
*
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
*/
_createHelper: function _createHelper(hasher) {
return function (message, cfg) {
return new hasher.init(cfg).finalize(message);
};
},
/**
* Creates a shortcut function to the HMAC's object interface.
*
* @param {Hasher} hasher The hasher to use in this HMAC helper.
*
* @return {Function} The shortcut function.
*
* @static
*
* @example
*
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
*/
_createHmacHelper: function _createHmacHelper(hasher) {
return function (message, key) {
return new C_algo.HMAC.init(hasher, key).finalize(message);
};
}
});
/**
* Algorithm namespace.
*/
var C_algo = C.algo = {};
return C;
}(Math);
return CryptoJS;
});
})(core);
var x64Core = {exports: {}};
(function (module, exports) {
(function (root, factory) {
{
// CommonJS
module.exports = factory(core.exports);
}
})(commonjsGlobal, function (CryptoJS) {
(function (undefined$1) {
// Shortcuts
var C = CryptoJS;
var C_lib = C.lib;
var Base = C_lib.Base;
var X32WordArray = C_lib.WordArray;
/**
* x64 namespace.
*/
var C_x64 = C.x64 = {};
/**
* A 64-bit word.
*/
C_x64.Word = Base.extend({
/**
* Initializes a newly created 64-bit word.
*
* @param {number} high The high 32 bits.
* @param {number} low The low 32 bits.
*
* @example
*
* var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
*/
init: function init(high, low) {
this.high = high;
this.low = low;
}
/**
* Bitwise NOTs this word.
*
* @return {X64Word} A new x64-Word object after negating.
*
* @example
*
* var negated = x64Word.not();
*/
// not: function () {
// var high = ~this.high;
// var low = ~this.low;
// return X64Word.create(high, low);
// },
/**
* Bitwise ANDs this word with the passed word.
*
* @param {X64Word} word The x64-Word to AND with this word.
*
* @return {X64Word} A new x64-Word object after ANDing.
*
* @example
*
* var anded = x64Word.and(anotherX64Word);
*/
// and: function (word) {
// var high = this.high & word.high;
// var low = this.low & word.low;
// return X64Word.create(high, low);
// },
/**
* Bitwise ORs this word with the passed word.
*
* @param {X64Word} word The x64-Word to OR with this word.
*
* @return {X64Word} A new x64-Word object after ORing.
*
* @example
*
* var ored = x64Word.or(anotherX64Word);
*/
// or: function (word) {
// var high = this.high | word.high;
// var low = this.low | word.low;
// return X64Word.create(high, low);
// },
/**
* Bitwise XORs this word with the passed word.
*
* @param {X64Word} word The x64-Word to XOR with this word.
*
* @return {X64Word} A new x64-Word object after XORing.
*
* @example
*
* var xored = x64Word.xor(anotherX64Word);
*/
// xor: function (word) {
// var high = this.high ^ word.high;
// var low = this.low ^ word.low;
// return X64Word.create(high, low);
// },
/**
* Shifts this word n bits to the left.
*
* @param {number} n The number of bits to shift.
*
* @return {X64Word} A new x64-Word object after shifting.
*
* @example
*
* var shifted = x64Word.shiftL(25);
*/
// shiftL: function (n) {
// if (n < 32) {
// var high = (this.high << n) | (this.low >>> (32 - n));
// var low = this.low << n;
// } else {
// var high = this.low << (n - 32);
// var low = 0;
// }
// return X64Word.create(high, low);
// },
/**
* Shifts this word n bits to the right.
*
* @param {number} n The number of bits to shift.
*
* @return {X64Word} A new x64-Word object after shifting.
*
* @example
*
* var shifted = x64Word.shiftR(7);
*/
// shiftR: function (n) {
// if (n < 32) {
// var low = (this.low >>> n) | (this.high << (32 - n));
// var high = this.high >>> n;
// } else {
// var low = this.high >>> (n - 32);
// var high = 0;
// }
// return X64Word.create(high, low);
// },
/**
* Rotates this word n bits to the left.
*
* @param {number} n The number of bits to rotate.
*
* @return {X64Word} A new x64-Word object after rotating.
*
* @example
*
* var rotated = x64Word.rotL(25);
*/
// rotL: function (n) {
// return this.shiftL(n).or(this.shiftR(64 - n));
// },
/**
* Rotates this word n bits to the right.
*
* @param {number} n The number of bits to rotate.
*
* @return {X64Word} A new x64-Word object after rotating.
*
* @example
*
* var rotated = x64Word.rotR(7);
*/
// rotR: function (n) {
// return this.shiftR(n).or(this.shiftL(64 - n));
// },
/**
* Adds this word with the passed word.
*
* @param {X64Word} word The x64-Word to add with this word.
*
* @return {X64Word} A new x64-Word object after adding.
*
* @example
*
* var added = x64Word.add(anotherX64Word);
*/
// add: function (word) {
// var low = (this.low + word.low) | 0;
// var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
// var high = (this.high + word.high + carry) | 0;
// return X64Word.create(high, low);
// }
});
/**
* An array of 64-bit words.
*
* @property {Array} words The array of CryptoJS.x64.Word objects.
* @property {number} sigBytes The number of significant bytes in this word array.
*/
C_x64.WordArray = Base.extend({
/**
* Initializes a newly created word array.
*
* @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
*
* @example
*
* var wordArray = CryptoJS.x64.WordArray.create();
*
* var wordArray = CryptoJS.x64.WordArray.create([
* CryptoJS.x64.Word.create(0x00010203, 0x04050607),
* CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
* ]);
*
* var wordArray = CryptoJS.x64.WordArray.create([
* CryptoJS.x64.Word.create(0x00010203, 0x04050607),
* CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
* ], 10);
*/
init: function init(words, sigBytes) {
words = this.words = words || [];
if (sigBytes != undefined$1) {
this.sigBytes = sigBytes;
} else {
this.sigBytes = words.length * 8;
}
},
/**
* Converts this 64-bit word array to a 32-bit word array.
*
* @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
*
* @example
*
* var x32WordArray = x64WordArray.toX32();
*/
toX32: function toX32() {
// Shortcuts
var x64Words = this.words;
var x64WordsLength = x64Words.length; // Convert
var x32Words = [];
for (var i = 0; i < x64WordsLength; i++) {
var x64Word = x64Words[i];
x32Words.push(x64Word.high);
x32Words.push(x64Word.low);
}
return X32WordArray.create(x32Words, this.sigBytes);
},
/**
* Creates a copy of this word array.
*
* @return {X64WordArray} The clone.
*
* @example
*
* var clone = x64WordArray.clone();
*/
clone: function clone() {
var clone = Base.clone.call(this); // Clone "words" array
var words = clone.words = this.words.slice(0); // Clone each X64Word object
var wordsLength = words.length;
for (var i = 0; i < wordsLength; i++) {
words[i] = words[i].clone();
}
return clone;
}
});
})();
return CryptoJS;
});
})(x64Core);
var libTypedarrays = {exports: {}};
(function (module, exports) {
(function (root, factory) {
{
// CommonJS
module.exports = factory(core.exports);
}
})(commonjsGlobal, function (CryptoJS) {
(function () {
// Check if typed arrays are supported
if (typeof ArrayBuffer != 'function') {
return;
} // Shortcuts
var C = CryptoJS;
var C_lib = C.lib;
var WordArray = C_lib.WordArray; // Reference original init
var superInit = WordArray.init; // Augment WordArray.init to handle typed arrays
var subInit = WordArray.init = function (typedArray) {
// Convert buffers to uint8
if (typedArray instanceof ArrayBuffer) {
typedArray = new Uint8Array(typedArray);
} // Convert other array views to uint8
if (typedArray instanceof Int8Array || typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray || typedArray instanceof Int16Array || typedArray instanceof Uint16Array || typedArray instanceof Int32Array || typedArray instanceof Uint32Array || typedArray instanceof Float32Array || typedArray instanceof Float64Array) {
typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
} // Handle Uint8Array
if (typedArray instanceof Uint8Array) {
// Shortcut
var typedArrayByteLength = typedArray.byteLength; // Extract bytes
var words = [];
for (var i = 0; i < typedArrayByteLength; i++) {
words[i >>> 2] |= typedArray[i] << 24 - i % 4 * 8;
} // Initialize this word array
superInit.call(this, words, typedArrayByteLength);
} else {
// Else call normal init
superInit.apply(this, arguments);
}
};
subInit.prototype = WordArray;
})();
return CryptoJS.lib.WordArray;
});
})(libTypedarrays);
var encUtf16 = {exports: {}};
(function (module, exports) {
(function (root, factory) {
{
// CommonJS
module.exports = factory(core.exports);
}
})(commonjsGlobal, function (CryptoJS) {
(function () {
// Shortcuts
var C = CryptoJS;
var C_lib = C.lib;
var WordArray = C_lib.WordArray;
var C_enc = C.enc;
/**
* UTF-16 BE encoding strategy.
*/
C_enc.Utf16 = C_enc.Utf16BE = {
/**
* Converts a word array to a UTF-16 BE string.
*
* @param {WordArray} wordArray The word array.
*
* @return {string} The UTF-16 BE string.
*
* @static
*
* @example
*
* var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
*/
stringify: function stringify(wordArray) {
// Shortcuts
var words = wordArray.words;
var sigBytes = wordArray.sigBytes; // Convert
var utf16Chars = [];
for (var i = 0; i < sigBytes; i += 2) {
var codePoint = words[i >>> 2] >>> 16 - i % 4 * 8 & 0xffff;
utf16Chars.push(String.fromCharCode(codePoint));
}
return utf16Chars.join('');
},
/**
* Converts a UTF-16 BE string to a word array.
*
* @param {string} utf16Str The UTF-16 BE string.
*
* @return {WordArray} The word array.
*
* @static
*
* @example
*
* var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
*/
parse: function parse(utf16Str) {
// Shortcut
var utf16StrLength = utf16Str.length; // Convert
var words = [];
for (var i = 0; i < utf16StrLength; i++) {
words[i >>> 1] |= utf16Str.charCodeAt(i) << 16 - i % 2 * 16;
}
return WordArray.create(words, utf16StrLength * 2);
}
};
/**
* UTF-16 LE encoding strategy.
*/
C_enc.Utf16LE = {
/**
* Converts a word array to a UTF-16 LE string.
*
* @param {WordArray} wordArray The word array.
*
* @return {string} The UTF-16 LE string.
*
* @static
*
* @example
*
* var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
*/
stringify: function stringify(wordArray) {
// Shortcuts
var words = wordArray.words;
var sigBytes = wordArray.sigBytes; // Convert
var utf16Chars = [];
for (var i = 0; i < sigBytes; i += 2) {
var codePoint = swapEndian(words[i >>> 2] >>> 16 - i % 4 * 8 & 0xffff);
utf16Chars.push(String.fromCharCode(codePoint));
}
return utf16Chars.join('');
},
/**
* Converts a UTF-16 LE string to a word array.
*
* @param {string} utf16Str The UTF-16 LE string.
*
* @return {WordArray} The word array.
*
* @static
*
* @example
*
* var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
*/
parse: function parse(utf16Str) {
// Shortcut
var utf16StrLength = utf16Str.length; // Convert
var words = [];
for (var i = 0; i < utf16StrLength; i++) {
words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << 16 - i % 2 * 16);
}
return WordArray.create(words, utf16StrLength * 2);
}
};
function swapEndian(word) {
return word << 8 & 0xff00ff00 | word >>> 8 & 0x00ff00ff;
}
})();
return CryptoJS.enc.Utf16;
});
})(encUtf16);
var encBase64 = {exports: {}};
(function (module, exports) {
(function (root, factory) {
{
// CommonJS
module.exports = factory(core.exports);
}
})(commonjsGlobal, function (CryptoJS) {
(function () {
// Shortcuts
var C = CryptoJS;
var C_lib = C.lib;
var WordArray = C_lib.WordArray;
var C_enc = C.enc;
/**
* Base64 encoding strategy.
*/