feat: 초기 프로젝트 설정 및 룰.md 파일 추가
This commit is contained in:
24
api.hyungi.net/node_modules/pvutils/LICENSE
generated
vendored
Normal file
24
api.hyungi.net/node_modules/pvutils/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016-2019, Peculiar Ventures
|
||||
All rights reserved.
|
||||
|
||||
Author 2016-2019, Yury Strozhevsky
|
||||
|
||||
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.
|
||||
14
api.hyungi.net/node_modules/pvutils/README.md
generated
vendored
Normal file
14
api.hyungi.net/node_modules/pvutils/README.md
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# pvutils
|
||||
|
||||
[](https://github.com/PeculiarVentures/pvutils/actions/workflows/test.yml)
|
||||
[](https://coveralls.io/github/PeculiarVentures/pvutils?branch=master)
|
||||
|
||||
`pvutils` is a set of common utility functions used in various Peculiar Ventures Javascript based projects.
|
||||
|
||||
Some example capabilities included in `pvutils` include:
|
||||
- Converting dates into UTC,
|
||||
- Converting an "ArrayBuffer" into a hexdecimal string,
|
||||
- Converting a number from 2^base to 2^10,
|
||||
- Converting a number from 2^10 to 2^base,
|
||||
- Concatenate two ArrayBuffers,
|
||||
- And more...
|
||||
115
api.hyungi.net/node_modules/pvutils/build/index.d.ts
generated
vendored
Normal file
115
api.hyungi.net/node_modules/pvutils/build/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
/*!
|
||||
Copyright (c) Peculiar Ventures, LLC
|
||||
*/
|
||||
|
||||
/**
|
||||
* Making UTC date from local date
|
||||
* @params date Date to convert from
|
||||
*/
|
||||
declare function getUTCDate(date: Date): Date;
|
||||
/**
|
||||
* Get value for input parameters, or set a default value
|
||||
* @param parameters
|
||||
* @param name
|
||||
* @param defaultValue
|
||||
*/
|
||||
declare function getParametersValue<T = unknown>(parameters: Record<string, any>, name: string, defaultValue: T): T;
|
||||
/**
|
||||
* Converts "ArrayBuffer" into a hexadecimal string
|
||||
* @param inputBuffer
|
||||
* @param inputOffset
|
||||
* @param inputLength
|
||||
* @param insertSpace
|
||||
*/
|
||||
declare function bufferToHexCodes(inputBuffer: ArrayBuffer, inputOffset?: number, inputLength?: number, insertSpace?: boolean): string;
|
||||
interface LocalBaseBlock {
|
||||
error?: string;
|
||||
}
|
||||
/**
|
||||
* Check input "ArrayBuffer" for common functions
|
||||
* @param {LocalBaseBlock} baseBlock
|
||||
* @param {ArrayBuffer} inputBuffer
|
||||
* @param {number} inputOffset
|
||||
* @param {number} inputLength
|
||||
* @returns {boolean}
|
||||
*/
|
||||
declare function checkBufferParams(baseBlock: LocalBaseBlock, inputBuffer: ArrayBuffer, inputOffset: number, inputLength: number): boolean;
|
||||
/**
|
||||
* Convert number from 2^base to 2^10
|
||||
* @param inputBuffer
|
||||
* @param inputBase
|
||||
*/
|
||||
declare function utilFromBase(inputBuffer: Uint8Array, inputBase: number): number;
|
||||
/**
|
||||
* Convert number from 2^10 to 2^base
|
||||
* @param value The number to convert
|
||||
* @param base The base for 2^base
|
||||
* @param reserved Pre-defined number of bytes in output array (-1 = limited by function itself)
|
||||
*/
|
||||
declare function utilToBase(value: number, base: number, reserved?: number): ArrayBuffer;
|
||||
/**
|
||||
* Concatenate two ArrayBuffers
|
||||
* @param buffers Set of ArrayBuffer
|
||||
*/
|
||||
declare function utilConcatBuf(...buffers: ArrayBuffer[]): ArrayBuffer;
|
||||
/**
|
||||
* Concatenate two Uint8Array
|
||||
* @param views Set of Uint8Array
|
||||
*/
|
||||
declare function utilConcatView(...views: Uint8Array[]): Uint8Array;
|
||||
interface HexBlock {
|
||||
valueHex: ArrayBuffer;
|
||||
warnings: string[];
|
||||
}
|
||||
/**
|
||||
* Decoding of "two complement" values
|
||||
* The function must be called in scope of instance of "hexBlock" class ("valueHex" and "warnings" properties must be present)
|
||||
*/
|
||||
declare function utilDecodeTC(this: HexBlock): number;
|
||||
/**
|
||||
* Encode integer value to "two complement" format
|
||||
* @param value Value to encode
|
||||
*/
|
||||
declare function utilEncodeTC(value: number): ArrayBuffer;
|
||||
/**
|
||||
* Compare two array buffers
|
||||
* @param inputBuffer1
|
||||
* @param inputBuffer2
|
||||
*/
|
||||
declare function isEqualBuffer(inputBuffer1: ArrayBuffer, inputBuffer2: ArrayBuffer): boolean;
|
||||
/**
|
||||
* Pad input number with leaded "0" if needed
|
||||
* @param inputNumber
|
||||
* @param fullLength
|
||||
*/
|
||||
declare function padNumber(inputNumber: number, fullLength: number): string;
|
||||
/**
|
||||
* Encode string into BASE64 (or "base64url")
|
||||
* @param input
|
||||
* @param useUrlTemplate If "true" then output would be encoded using "base64url"
|
||||
* @param skipPadding Skip BASE-64 padding or not
|
||||
* @param skipLeadingZeros Skip leading zeros in input data or not
|
||||
*/
|
||||
declare function toBase64(input: string, useUrlTemplate?: boolean, skipPadding?: boolean, skipLeadingZeros?: boolean): string;
|
||||
/**
|
||||
* Decode string from BASE64 (or "base64url")
|
||||
* @param input
|
||||
* @param useUrlTemplate If "true" then output would be encoded using "base64url"
|
||||
* @param cutTailZeros If "true" then cut tailing zeros from function result
|
||||
*/
|
||||
declare function fromBase64(input: string, useUrlTemplate?: boolean, cutTailZeros?: boolean): string;
|
||||
declare function arrayBufferToString(buffer: ArrayBuffer): string;
|
||||
declare function stringToArrayBuffer(str: string): ArrayBuffer;
|
||||
/**
|
||||
* Get nearest to input length power of 2
|
||||
* @param length Current length of existing array
|
||||
*/
|
||||
declare function nearestPowerOf2(length: number): number;
|
||||
/**
|
||||
* Delete properties by name from specified object
|
||||
* @param object Object to delete properties from
|
||||
* @param propsArray Array of properties names
|
||||
*/
|
||||
declare function clearProps(object: Record<string, any>, propsArray: string[]): void;
|
||||
|
||||
export { HexBlock, LocalBaseBlock, arrayBufferToString, bufferToHexCodes, checkBufferParams, clearProps, fromBase64, getParametersValue, getUTCDate, isEqualBuffer, nearestPowerOf2, padNumber, stringToArrayBuffer, toBase64, utilConcatBuf, utilConcatView, utilDecodeTC, utilEncodeTC, utilFromBase, utilToBase };
|
||||
339
api.hyungi.net/node_modules/pvutils/build/utils.es.js
generated
vendored
Normal file
339
api.hyungi.net/node_modules/pvutils/build/utils.es.js
generated
vendored
Normal file
@@ -0,0 +1,339 @@
|
||||
/*!
|
||||
Copyright (c) Peculiar Ventures, LLC
|
||||
*/
|
||||
|
||||
function getUTCDate(date) {
|
||||
return new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
|
||||
}
|
||||
function getParametersValue(parameters, name, defaultValue) {
|
||||
var _a;
|
||||
if ((parameters instanceof Object) === false) {
|
||||
return defaultValue;
|
||||
}
|
||||
return (_a = parameters[name]) !== null && _a !== void 0 ? _a : defaultValue;
|
||||
}
|
||||
function bufferToHexCodes(inputBuffer, inputOffset = 0, inputLength = (inputBuffer.byteLength - inputOffset), insertSpace = false) {
|
||||
let result = "";
|
||||
for (const item of (new Uint8Array(inputBuffer, inputOffset, inputLength))) {
|
||||
const str = item.toString(16).toUpperCase();
|
||||
if (str.length === 1) {
|
||||
result += "0";
|
||||
}
|
||||
result += str;
|
||||
if (insertSpace) {
|
||||
result += " ";
|
||||
}
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) {
|
||||
if (!(inputBuffer instanceof ArrayBuffer)) {
|
||||
baseBlock.error = "Wrong parameter: inputBuffer must be \"ArrayBuffer\"";
|
||||
return false;
|
||||
}
|
||||
if (!inputBuffer.byteLength) {
|
||||
baseBlock.error = "Wrong parameter: inputBuffer has zero length";
|
||||
return false;
|
||||
}
|
||||
if (inputOffset < 0) {
|
||||
baseBlock.error = "Wrong parameter: inputOffset less than zero";
|
||||
return false;
|
||||
}
|
||||
if (inputLength < 0) {
|
||||
baseBlock.error = "Wrong parameter: inputLength less than zero";
|
||||
return false;
|
||||
}
|
||||
if ((inputBuffer.byteLength - inputOffset - inputLength) < 0) {
|
||||
baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function utilFromBase(inputBuffer, inputBase) {
|
||||
let result = 0;
|
||||
if (inputBuffer.length === 1) {
|
||||
return inputBuffer[0];
|
||||
}
|
||||
for (let i = (inputBuffer.length - 1); i >= 0; i--) {
|
||||
result += inputBuffer[(inputBuffer.length - 1) - i] * Math.pow(2, inputBase * i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function utilToBase(value, base, reserved = (-1)) {
|
||||
const internalReserved = reserved;
|
||||
let internalValue = value;
|
||||
let result = 0;
|
||||
let biggest = Math.pow(2, base);
|
||||
for (let i = 1; i < 8; i++) {
|
||||
if (value < biggest) {
|
||||
let retBuf;
|
||||
if (internalReserved < 0) {
|
||||
retBuf = new ArrayBuffer(i);
|
||||
result = i;
|
||||
}
|
||||
else {
|
||||
if (internalReserved < i) {
|
||||
return (new ArrayBuffer(0));
|
||||
}
|
||||
retBuf = new ArrayBuffer(internalReserved);
|
||||
result = internalReserved;
|
||||
}
|
||||
const retView = new Uint8Array(retBuf);
|
||||
for (let j = (i - 1); j >= 0; j--) {
|
||||
const basis = Math.pow(2, j * base);
|
||||
retView[result - j - 1] = Math.floor(internalValue / basis);
|
||||
internalValue -= (retView[result - j - 1]) * basis;
|
||||
}
|
||||
return retBuf;
|
||||
}
|
||||
biggest *= Math.pow(2, base);
|
||||
}
|
||||
return new ArrayBuffer(0);
|
||||
}
|
||||
function utilConcatBuf(...buffers) {
|
||||
let outputLength = 0;
|
||||
let prevLength = 0;
|
||||
for (const buffer of buffers) {
|
||||
outputLength += buffer.byteLength;
|
||||
}
|
||||
const retBuf = new ArrayBuffer(outputLength);
|
||||
const retView = new Uint8Array(retBuf);
|
||||
for (const buffer of buffers) {
|
||||
retView.set(new Uint8Array(buffer), prevLength);
|
||||
prevLength += buffer.byteLength;
|
||||
}
|
||||
return retBuf;
|
||||
}
|
||||
function utilConcatView(...views) {
|
||||
let outputLength = 0;
|
||||
let prevLength = 0;
|
||||
for (const view of views) {
|
||||
outputLength += view.length;
|
||||
}
|
||||
const retBuf = new ArrayBuffer(outputLength);
|
||||
const retView = new Uint8Array(retBuf);
|
||||
for (const view of views) {
|
||||
retView.set(view, prevLength);
|
||||
prevLength += view.length;
|
||||
}
|
||||
return retView;
|
||||
}
|
||||
function utilDecodeTC() {
|
||||
const buf = new Uint8Array(this.valueHex);
|
||||
if (this.valueHex.byteLength >= 2) {
|
||||
const condition1 = (buf[0] === 0xFF) && (buf[1] & 0x80);
|
||||
const condition2 = (buf[0] === 0x00) && ((buf[1] & 0x80) === 0x00);
|
||||
if (condition1 || condition2) {
|
||||
this.warnings.push("Needlessly long format");
|
||||
}
|
||||
}
|
||||
const bigIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
|
||||
const bigIntView = new Uint8Array(bigIntBuffer);
|
||||
for (let i = 0; i < this.valueHex.byteLength; i++) {
|
||||
bigIntView[i] = 0;
|
||||
}
|
||||
bigIntView[0] = (buf[0] & 0x80);
|
||||
const bigInt = utilFromBase(bigIntView, 8);
|
||||
const smallIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
|
||||
const smallIntView = new Uint8Array(smallIntBuffer);
|
||||
for (let j = 0; j < this.valueHex.byteLength; j++) {
|
||||
smallIntView[j] = buf[j];
|
||||
}
|
||||
smallIntView[0] &= 0x7F;
|
||||
const smallInt = utilFromBase(smallIntView, 8);
|
||||
return (smallInt - bigInt);
|
||||
}
|
||||
function utilEncodeTC(value) {
|
||||
const modValue = (value < 0) ? (value * (-1)) : value;
|
||||
let bigInt = 128;
|
||||
for (let i = 1; i < 8; i++) {
|
||||
if (modValue <= bigInt) {
|
||||
if (value < 0) {
|
||||
const smallInt = bigInt - modValue;
|
||||
const retBuf = utilToBase(smallInt, 8, i);
|
||||
const retView = new Uint8Array(retBuf);
|
||||
retView[0] |= 0x80;
|
||||
return retBuf;
|
||||
}
|
||||
let retBuf = utilToBase(modValue, 8, i);
|
||||
let retView = new Uint8Array(retBuf);
|
||||
if (retView[0] & 0x80) {
|
||||
const tempBuf = retBuf.slice(0);
|
||||
const tempView = new Uint8Array(tempBuf);
|
||||
retBuf = new ArrayBuffer(retBuf.byteLength + 1);
|
||||
retView = new Uint8Array(retBuf);
|
||||
for (let k = 0; k < tempBuf.byteLength; k++) {
|
||||
retView[k + 1] = tempView[k];
|
||||
}
|
||||
retView[0] = 0x00;
|
||||
}
|
||||
return retBuf;
|
||||
}
|
||||
bigInt *= Math.pow(2, 8);
|
||||
}
|
||||
return (new ArrayBuffer(0));
|
||||
}
|
||||
function isEqualBuffer(inputBuffer1, inputBuffer2) {
|
||||
if (inputBuffer1.byteLength !== inputBuffer2.byteLength) {
|
||||
return false;
|
||||
}
|
||||
const view1 = new Uint8Array(inputBuffer1);
|
||||
const view2 = new Uint8Array(inputBuffer2);
|
||||
for (let i = 0; i < view1.length; i++) {
|
||||
if (view1[i] !== view2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function padNumber(inputNumber, fullLength) {
|
||||
const str = inputNumber.toString(10);
|
||||
if (fullLength < str.length) {
|
||||
return "";
|
||||
}
|
||||
const dif = fullLength - str.length;
|
||||
const padding = new Array(dif);
|
||||
for (let i = 0; i < dif; i++) {
|
||||
padding[i] = "0";
|
||||
}
|
||||
const paddingString = padding.join("");
|
||||
return paddingString.concat(str);
|
||||
}
|
||||
const base64Template = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
const base64UrlTemplate = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
|
||||
function toBase64(input, useUrlTemplate = false, skipPadding = false, skipLeadingZeros = false) {
|
||||
let i = 0;
|
||||
let flag1 = 0;
|
||||
let flag2 = 0;
|
||||
let output = "";
|
||||
const template = (useUrlTemplate) ? base64UrlTemplate : base64Template;
|
||||
if (skipLeadingZeros) {
|
||||
let nonZeroPosition = 0;
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (input.charCodeAt(i) !== 0) {
|
||||
nonZeroPosition = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
input = input.slice(nonZeroPosition);
|
||||
}
|
||||
while (i < input.length) {
|
||||
const chr1 = input.charCodeAt(i++);
|
||||
if (i >= input.length) {
|
||||
flag1 = 1;
|
||||
}
|
||||
const chr2 = input.charCodeAt(i++);
|
||||
if (i >= input.length) {
|
||||
flag2 = 1;
|
||||
}
|
||||
const chr3 = input.charCodeAt(i++);
|
||||
const enc1 = chr1 >> 2;
|
||||
const enc2 = ((chr1 & 0x03) << 4) | (chr2 >> 4);
|
||||
let enc3 = ((chr2 & 0x0F) << 2) | (chr3 >> 6);
|
||||
let enc4 = chr3 & 0x3F;
|
||||
if (flag1 === 1) {
|
||||
enc3 = enc4 = 64;
|
||||
}
|
||||
else {
|
||||
if (flag2 === 1) {
|
||||
enc4 = 64;
|
||||
}
|
||||
}
|
||||
if (skipPadding) {
|
||||
if (enc3 === 64) {
|
||||
output += `${template.charAt(enc1)}${template.charAt(enc2)}`;
|
||||
}
|
||||
else {
|
||||
if (enc4 === 64) {
|
||||
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}`;
|
||||
}
|
||||
else {
|
||||
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}${template.charAt(enc4)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}${template.charAt(enc4)}`;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
function fromBase64(input, useUrlTemplate = false, cutTailZeros = false) {
|
||||
const template = (useUrlTemplate) ? base64UrlTemplate : base64Template;
|
||||
function indexOf(toSearch) {
|
||||
for (let i = 0; i < 64; i++) {
|
||||
if (template.charAt(i) === toSearch)
|
||||
return i;
|
||||
}
|
||||
return 64;
|
||||
}
|
||||
function test(incoming) {
|
||||
return ((incoming === 64) ? 0x00 : incoming);
|
||||
}
|
||||
let i = 0;
|
||||
let output = "";
|
||||
while (i < input.length) {
|
||||
const enc1 = indexOf(input.charAt(i++));
|
||||
const enc2 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++));
|
||||
const enc3 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++));
|
||||
const enc4 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++));
|
||||
const chr1 = (test(enc1) << 2) | (test(enc2) >> 4);
|
||||
const chr2 = ((test(enc2) & 0x0F) << 4) | (test(enc3) >> 2);
|
||||
const chr3 = ((test(enc3) & 0x03) << 6) | test(enc4);
|
||||
output += String.fromCharCode(chr1);
|
||||
if (enc3 !== 64) {
|
||||
output += String.fromCharCode(chr2);
|
||||
}
|
||||
if (enc4 !== 64) {
|
||||
output += String.fromCharCode(chr3);
|
||||
}
|
||||
}
|
||||
if (cutTailZeros) {
|
||||
const outputLength = output.length;
|
||||
let nonZeroStart = (-1);
|
||||
for (let i = (outputLength - 1); i >= 0; i--) {
|
||||
if (output.charCodeAt(i) !== 0) {
|
||||
nonZeroStart = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nonZeroStart !== (-1)) {
|
||||
output = output.slice(0, nonZeroStart + 1);
|
||||
}
|
||||
else {
|
||||
output = "";
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
function arrayBufferToString(buffer) {
|
||||
let resultString = "";
|
||||
const view = new Uint8Array(buffer);
|
||||
for (const element of view) {
|
||||
resultString += String.fromCharCode(element);
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
function stringToArrayBuffer(str) {
|
||||
const stringLength = str.length;
|
||||
const resultBuffer = new ArrayBuffer(stringLength);
|
||||
const resultView = new Uint8Array(resultBuffer);
|
||||
for (let i = 0; i < stringLength; i++) {
|
||||
resultView[i] = str.charCodeAt(i);
|
||||
}
|
||||
return resultBuffer;
|
||||
}
|
||||
const log2 = Math.log(2);
|
||||
function nearestPowerOf2(length) {
|
||||
const base = (Math.log(length) / log2);
|
||||
const floor = Math.floor(base);
|
||||
const round = Math.round(base);
|
||||
return ((floor === round) ? floor : round);
|
||||
}
|
||||
function clearProps(object, propsArray) {
|
||||
for (const prop of propsArray) {
|
||||
delete object[prop];
|
||||
}
|
||||
}
|
||||
|
||||
export { arrayBufferToString, bufferToHexCodes, checkBufferParams, clearProps, fromBase64, getParametersValue, getUTCDate, isEqualBuffer, nearestPowerOf2, padNumber, stringToArrayBuffer, toBase64, utilConcatBuf, utilConcatView, utilDecodeTC, utilEncodeTC, utilFromBase, utilToBase };
|
||||
360
api.hyungi.net/node_modules/pvutils/build/utils.js
generated
vendored
Normal file
360
api.hyungi.net/node_modules/pvutils/build/utils.js
generated
vendored
Normal file
@@ -0,0 +1,360 @@
|
||||
/*!
|
||||
Copyright (c) Peculiar Ventures, LLC
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
function getUTCDate(date) {
|
||||
return new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
|
||||
}
|
||||
function getParametersValue(parameters, name, defaultValue) {
|
||||
var _a;
|
||||
if ((parameters instanceof Object) === false) {
|
||||
return defaultValue;
|
||||
}
|
||||
return (_a = parameters[name]) !== null && _a !== void 0 ? _a : defaultValue;
|
||||
}
|
||||
function bufferToHexCodes(inputBuffer, inputOffset = 0, inputLength = (inputBuffer.byteLength - inputOffset), insertSpace = false) {
|
||||
let result = "";
|
||||
for (const item of (new Uint8Array(inputBuffer, inputOffset, inputLength))) {
|
||||
const str = item.toString(16).toUpperCase();
|
||||
if (str.length === 1) {
|
||||
result += "0";
|
||||
}
|
||||
result += str;
|
||||
if (insertSpace) {
|
||||
result += " ";
|
||||
}
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) {
|
||||
if (!(inputBuffer instanceof ArrayBuffer)) {
|
||||
baseBlock.error = "Wrong parameter: inputBuffer must be \"ArrayBuffer\"";
|
||||
return false;
|
||||
}
|
||||
if (!inputBuffer.byteLength) {
|
||||
baseBlock.error = "Wrong parameter: inputBuffer has zero length";
|
||||
return false;
|
||||
}
|
||||
if (inputOffset < 0) {
|
||||
baseBlock.error = "Wrong parameter: inputOffset less than zero";
|
||||
return false;
|
||||
}
|
||||
if (inputLength < 0) {
|
||||
baseBlock.error = "Wrong parameter: inputLength less than zero";
|
||||
return false;
|
||||
}
|
||||
if ((inputBuffer.byteLength - inputOffset - inputLength) < 0) {
|
||||
baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function utilFromBase(inputBuffer, inputBase) {
|
||||
let result = 0;
|
||||
if (inputBuffer.length === 1) {
|
||||
return inputBuffer[0];
|
||||
}
|
||||
for (let i = (inputBuffer.length - 1); i >= 0; i--) {
|
||||
result += inputBuffer[(inputBuffer.length - 1) - i] * Math.pow(2, inputBase * i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function utilToBase(value, base, reserved = (-1)) {
|
||||
const internalReserved = reserved;
|
||||
let internalValue = value;
|
||||
let result = 0;
|
||||
let biggest = Math.pow(2, base);
|
||||
for (let i = 1; i < 8; i++) {
|
||||
if (value < biggest) {
|
||||
let retBuf;
|
||||
if (internalReserved < 0) {
|
||||
retBuf = new ArrayBuffer(i);
|
||||
result = i;
|
||||
}
|
||||
else {
|
||||
if (internalReserved < i) {
|
||||
return (new ArrayBuffer(0));
|
||||
}
|
||||
retBuf = new ArrayBuffer(internalReserved);
|
||||
result = internalReserved;
|
||||
}
|
||||
const retView = new Uint8Array(retBuf);
|
||||
for (let j = (i - 1); j >= 0; j--) {
|
||||
const basis = Math.pow(2, j * base);
|
||||
retView[result - j - 1] = Math.floor(internalValue / basis);
|
||||
internalValue -= (retView[result - j - 1]) * basis;
|
||||
}
|
||||
return retBuf;
|
||||
}
|
||||
biggest *= Math.pow(2, base);
|
||||
}
|
||||
return new ArrayBuffer(0);
|
||||
}
|
||||
function utilConcatBuf(...buffers) {
|
||||
let outputLength = 0;
|
||||
let prevLength = 0;
|
||||
for (const buffer of buffers) {
|
||||
outputLength += buffer.byteLength;
|
||||
}
|
||||
const retBuf = new ArrayBuffer(outputLength);
|
||||
const retView = new Uint8Array(retBuf);
|
||||
for (const buffer of buffers) {
|
||||
retView.set(new Uint8Array(buffer), prevLength);
|
||||
prevLength += buffer.byteLength;
|
||||
}
|
||||
return retBuf;
|
||||
}
|
||||
function utilConcatView(...views) {
|
||||
let outputLength = 0;
|
||||
let prevLength = 0;
|
||||
for (const view of views) {
|
||||
outputLength += view.length;
|
||||
}
|
||||
const retBuf = new ArrayBuffer(outputLength);
|
||||
const retView = new Uint8Array(retBuf);
|
||||
for (const view of views) {
|
||||
retView.set(view, prevLength);
|
||||
prevLength += view.length;
|
||||
}
|
||||
return retView;
|
||||
}
|
||||
function utilDecodeTC() {
|
||||
const buf = new Uint8Array(this.valueHex);
|
||||
if (this.valueHex.byteLength >= 2) {
|
||||
const condition1 = (buf[0] === 0xFF) && (buf[1] & 0x80);
|
||||
const condition2 = (buf[0] === 0x00) && ((buf[1] & 0x80) === 0x00);
|
||||
if (condition1 || condition2) {
|
||||
this.warnings.push("Needlessly long format");
|
||||
}
|
||||
}
|
||||
const bigIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
|
||||
const bigIntView = new Uint8Array(bigIntBuffer);
|
||||
for (let i = 0; i < this.valueHex.byteLength; i++) {
|
||||
bigIntView[i] = 0;
|
||||
}
|
||||
bigIntView[0] = (buf[0] & 0x80);
|
||||
const bigInt = utilFromBase(bigIntView, 8);
|
||||
const smallIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
|
||||
const smallIntView = new Uint8Array(smallIntBuffer);
|
||||
for (let j = 0; j < this.valueHex.byteLength; j++) {
|
||||
smallIntView[j] = buf[j];
|
||||
}
|
||||
smallIntView[0] &= 0x7F;
|
||||
const smallInt = utilFromBase(smallIntView, 8);
|
||||
return (smallInt - bigInt);
|
||||
}
|
||||
function utilEncodeTC(value) {
|
||||
const modValue = (value < 0) ? (value * (-1)) : value;
|
||||
let bigInt = 128;
|
||||
for (let i = 1; i < 8; i++) {
|
||||
if (modValue <= bigInt) {
|
||||
if (value < 0) {
|
||||
const smallInt = bigInt - modValue;
|
||||
const retBuf = utilToBase(smallInt, 8, i);
|
||||
const retView = new Uint8Array(retBuf);
|
||||
retView[0] |= 0x80;
|
||||
return retBuf;
|
||||
}
|
||||
let retBuf = utilToBase(modValue, 8, i);
|
||||
let retView = new Uint8Array(retBuf);
|
||||
if (retView[0] & 0x80) {
|
||||
const tempBuf = retBuf.slice(0);
|
||||
const tempView = new Uint8Array(tempBuf);
|
||||
retBuf = new ArrayBuffer(retBuf.byteLength + 1);
|
||||
retView = new Uint8Array(retBuf);
|
||||
for (let k = 0; k < tempBuf.byteLength; k++) {
|
||||
retView[k + 1] = tempView[k];
|
||||
}
|
||||
retView[0] = 0x00;
|
||||
}
|
||||
return retBuf;
|
||||
}
|
||||
bigInt *= Math.pow(2, 8);
|
||||
}
|
||||
return (new ArrayBuffer(0));
|
||||
}
|
||||
function isEqualBuffer(inputBuffer1, inputBuffer2) {
|
||||
if (inputBuffer1.byteLength !== inputBuffer2.byteLength) {
|
||||
return false;
|
||||
}
|
||||
const view1 = new Uint8Array(inputBuffer1);
|
||||
const view2 = new Uint8Array(inputBuffer2);
|
||||
for (let i = 0; i < view1.length; i++) {
|
||||
if (view1[i] !== view2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function padNumber(inputNumber, fullLength) {
|
||||
const str = inputNumber.toString(10);
|
||||
if (fullLength < str.length) {
|
||||
return "";
|
||||
}
|
||||
const dif = fullLength - str.length;
|
||||
const padding = new Array(dif);
|
||||
for (let i = 0; i < dif; i++) {
|
||||
padding[i] = "0";
|
||||
}
|
||||
const paddingString = padding.join("");
|
||||
return paddingString.concat(str);
|
||||
}
|
||||
const base64Template = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
const base64UrlTemplate = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
|
||||
function toBase64(input, useUrlTemplate = false, skipPadding = false, skipLeadingZeros = false) {
|
||||
let i = 0;
|
||||
let flag1 = 0;
|
||||
let flag2 = 0;
|
||||
let output = "";
|
||||
const template = (useUrlTemplate) ? base64UrlTemplate : base64Template;
|
||||
if (skipLeadingZeros) {
|
||||
let nonZeroPosition = 0;
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (input.charCodeAt(i) !== 0) {
|
||||
nonZeroPosition = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
input = input.slice(nonZeroPosition);
|
||||
}
|
||||
while (i < input.length) {
|
||||
const chr1 = input.charCodeAt(i++);
|
||||
if (i >= input.length) {
|
||||
flag1 = 1;
|
||||
}
|
||||
const chr2 = input.charCodeAt(i++);
|
||||
if (i >= input.length) {
|
||||
flag2 = 1;
|
||||
}
|
||||
const chr3 = input.charCodeAt(i++);
|
||||
const enc1 = chr1 >> 2;
|
||||
const enc2 = ((chr1 & 0x03) << 4) | (chr2 >> 4);
|
||||
let enc3 = ((chr2 & 0x0F) << 2) | (chr3 >> 6);
|
||||
let enc4 = chr3 & 0x3F;
|
||||
if (flag1 === 1) {
|
||||
enc3 = enc4 = 64;
|
||||
}
|
||||
else {
|
||||
if (flag2 === 1) {
|
||||
enc4 = 64;
|
||||
}
|
||||
}
|
||||
if (skipPadding) {
|
||||
if (enc3 === 64) {
|
||||
output += `${template.charAt(enc1)}${template.charAt(enc2)}`;
|
||||
}
|
||||
else {
|
||||
if (enc4 === 64) {
|
||||
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}`;
|
||||
}
|
||||
else {
|
||||
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}${template.charAt(enc4)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}${template.charAt(enc4)}`;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
function fromBase64(input, useUrlTemplate = false, cutTailZeros = false) {
|
||||
const template = (useUrlTemplate) ? base64UrlTemplate : base64Template;
|
||||
function indexOf(toSearch) {
|
||||
for (let i = 0; i < 64; i++) {
|
||||
if (template.charAt(i) === toSearch)
|
||||
return i;
|
||||
}
|
||||
return 64;
|
||||
}
|
||||
function test(incoming) {
|
||||
return ((incoming === 64) ? 0x00 : incoming);
|
||||
}
|
||||
let i = 0;
|
||||
let output = "";
|
||||
while (i < input.length) {
|
||||
const enc1 = indexOf(input.charAt(i++));
|
||||
const enc2 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++));
|
||||
const enc3 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++));
|
||||
const enc4 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++));
|
||||
const chr1 = (test(enc1) << 2) | (test(enc2) >> 4);
|
||||
const chr2 = ((test(enc2) & 0x0F) << 4) | (test(enc3) >> 2);
|
||||
const chr3 = ((test(enc3) & 0x03) << 6) | test(enc4);
|
||||
output += String.fromCharCode(chr1);
|
||||
if (enc3 !== 64) {
|
||||
output += String.fromCharCode(chr2);
|
||||
}
|
||||
if (enc4 !== 64) {
|
||||
output += String.fromCharCode(chr3);
|
||||
}
|
||||
}
|
||||
if (cutTailZeros) {
|
||||
const outputLength = output.length;
|
||||
let nonZeroStart = (-1);
|
||||
for (let i = (outputLength - 1); i >= 0; i--) {
|
||||
if (output.charCodeAt(i) !== 0) {
|
||||
nonZeroStart = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nonZeroStart !== (-1)) {
|
||||
output = output.slice(0, nonZeroStart + 1);
|
||||
}
|
||||
else {
|
||||
output = "";
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
function arrayBufferToString(buffer) {
|
||||
let resultString = "";
|
||||
const view = new Uint8Array(buffer);
|
||||
for (const element of view) {
|
||||
resultString += String.fromCharCode(element);
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
function stringToArrayBuffer(str) {
|
||||
const stringLength = str.length;
|
||||
const resultBuffer = new ArrayBuffer(stringLength);
|
||||
const resultView = new Uint8Array(resultBuffer);
|
||||
for (let i = 0; i < stringLength; i++) {
|
||||
resultView[i] = str.charCodeAt(i);
|
||||
}
|
||||
return resultBuffer;
|
||||
}
|
||||
const log2 = Math.log(2);
|
||||
function nearestPowerOf2(length) {
|
||||
const base = (Math.log(length) / log2);
|
||||
const floor = Math.floor(base);
|
||||
const round = Math.round(base);
|
||||
return ((floor === round) ? floor : round);
|
||||
}
|
||||
function clearProps(object, propsArray) {
|
||||
for (const prop of propsArray) {
|
||||
delete object[prop];
|
||||
}
|
||||
}
|
||||
|
||||
exports.arrayBufferToString = arrayBufferToString;
|
||||
exports.bufferToHexCodes = bufferToHexCodes;
|
||||
exports.checkBufferParams = checkBufferParams;
|
||||
exports.clearProps = clearProps;
|
||||
exports.fromBase64 = fromBase64;
|
||||
exports.getParametersValue = getParametersValue;
|
||||
exports.getUTCDate = getUTCDate;
|
||||
exports.isEqualBuffer = isEqualBuffer;
|
||||
exports.nearestPowerOf2 = nearestPowerOf2;
|
||||
exports.padNumber = padNumber;
|
||||
exports.stringToArrayBuffer = stringToArrayBuffer;
|
||||
exports.toBase64 = toBase64;
|
||||
exports.utilConcatBuf = utilConcatBuf;
|
||||
exports.utilConcatView = utilConcatView;
|
||||
exports.utilDecodeTC = utilDecodeTC;
|
||||
exports.utilEncodeTC = utilEncodeTC;
|
||||
exports.utilFromBase = utilFromBase;
|
||||
exports.utilToBase = utilToBase;
|
||||
59
api.hyungi.net/node_modules/pvutils/package.json
generated
vendored
Normal file
59
api.hyungi.net/node_modules/pvutils/package.json
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"author": {
|
||||
"email": "yury@strozhevsky.com",
|
||||
"name": "Yury Strozhevsky"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"email": "rmh@unmitigatedrisk.com",
|
||||
"name": "Ryan Hurst"
|
||||
},
|
||||
{
|
||||
"email": "microshine@mail.ru",
|
||||
"name": "Miroshin Stepan"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PeculiarVentures/pvutils.git"
|
||||
},
|
||||
"description": "Common utilities for products from Peculiar Ventures",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "npm run build",
|
||||
"test": "mocha",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"lint:fix": "eslint --fix . --ext .ts",
|
||||
"build": "rollup -c",
|
||||
"coverage": "nyc npm test",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
||||
},
|
||||
"files": [
|
||||
"build",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"module": "./build/utils.es.js",
|
||||
"main": "./build/utils.js",
|
||||
"types": "./build/index.d.ts",
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^9.1.0",
|
||||
"@types/node": "^17.0.19",
|
||||
"@typescript-eslint/eslint-plugin": "^5.12.1",
|
||||
"@typescript-eslint/parser": "^5.12.1",
|
||||
"eslint": "^8.9.0",
|
||||
"eslint-plugin-import": "^2.25.4",
|
||||
"mocha": "^9.2.1",
|
||||
"nyc": "^15.1.0",
|
||||
"rollup": "2.68.0",
|
||||
"rollup-plugin-dts": "^4.1.0",
|
||||
"rollup-plugin-typescript2": "^0.31.2",
|
||||
"ts-node": "^10.5.0",
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"name": "pvutils",
|
||||
"version": "1.1.3",
|
||||
"license": "MIT"
|
||||
}
|
||||
Reference in New Issue
Block a user