| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- function zero2(word) {
- if (word.length === 1) {
- return '0' + word;
- }
- else {
- return word;
- }
- }
- function toArray(msg, enc) {
- if (Array.isArray(msg)) {
- return msg.slice();
- }
- if (!msg) {
- return [];
- }
- const res = [];
- if (typeof msg !== 'string') {
- for (let i = 0; i < msg.length; i++) {
- res[i] = msg[i] | 0;
- }
- return res;
- }
- if (enc === 'hex') {
- msg = msg.replace(/[^a-z0-9]+/ig, '');
- if (msg.length % 2 !== 0) {
- msg = '0' + msg;
- }
- for (let i = 0; i < msg.length; i += 2) {
- res.push(parseInt(msg[i] + msg[i + 1], 16));
- }
- }
- else {
- for (let i = 0; i < msg.length; i++) {
- const c = msg.charCodeAt(i);
- const hi = c >> 8;
- const lo = c & 0xff;
- if (hi) {
- res.push(hi, lo);
- }
- else {
- res.push(lo);
- }
- }
- }
- return res;
- }
- exports.toArray = toArray;
- function encodeHex(msg) {
- let res = '';
- for (let i = 0; i < msg.length; i++) {
- res += zero2(msg[i].toString(16));
- }
- return res;
- }
- exports.encodeHex = encodeHex;
- function uuid() {
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (char) => {
- // tslint:disable-next-line: no-bitwise
- const random = Math.random() * 16 | 0;
- const value = char === "x" ? random : (random % 4 + 8);
- return value.toString(16);
- });
- }
- exports.uuid = uuid;
- function isObject(item) {
- return (item && typeof item === 'object' && !Array.isArray(item));
- }
- exports.isObject = isObject;
- function mergeDeep(target, source) {
- const output = Object.assign({}, target);
- if (isObject(target) && isObject(source)) {
- Object.keys(source).forEach(key => {
- if (isObject(source[key])) {
- if (!(key in target)) {
- Object.assign(output, { [key]: source[key] });
- }
- else {
- output[key] = mergeDeep(target[key], source[key]);
- }
- }
- else {
- Object.assign(output, { [key]: source[key] });
- }
- });
- }
- return output;
- }
- exports.mergeDeep = mergeDeep;
- //# sourceMappingURL=util.js.map
|