This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import '@formatjs/intl-durationformat/polyfill.js' | |
import assert from 'assert' | |
import jose from 'node-jose' | |
import { setTimeout as setTimeoutAsync } from 'node:timers/promises' | |
const YA_IAM_TOKENS_URL = 'https://iam.api.cloud.yandex.net/iam/v1/tokens' | |
const YA_QUERY_ENDPOINT = 'https://api.yandex-query.cloud.yandex.net' | |
// @ts-ignore no typings | |
const durationFormat = new Intl.DurationFormat('en', { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 02.09.2024 | |
new Intl.DateTimeFormat("ru", { | |
dateStyle: "short", | |
timeZone: "Europe/Moscow", | |
}).format(new Date()); | |
// 02.09.2024, 05:59 | |
new Intl.DateTimeFormat("ru", { | |
dateStyle: "short", | |
timeStyle: "short", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { fetch } from "undici"; | |
/** | |
* @param {string} url | |
* @param {string} [origin] | |
* @returns {Promise<string>} | |
*/ | |
export async function getResourceDataUrl(url, origin) { | |
const fetchUrl = new URL(url, origin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Makes a channel that buffers up to n items | |
*/ | |
function chan(n) { | |
const data = []; // data not yet read | |
const readersBacklog = []; // readers waiting for data | |
const writersBacklog = []; // writers waiting for data | |
let disposed = false; | |
// TODO(Benjamin) - disposing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getPromiseWithResolvers() { | |
let resolve; | |
let reject; | |
const promise = new Promise((resolve_, reject_) => { | |
resolve = resolve_; | |
reject = reject_; | |
}); | |
return { promise, resolve, reject }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const formatPhone = (phone) => { | |
if (typeof phone !== "string") return ""; | |
const phoneNums = phone.replaceAll(/\D/g, ""); | |
if (phoneNums.length !== 11) return "+" + phoneNums; | |
const code = phoneNums.substring(0, 1); | |
const region = phoneNums.substring(1, 4); | |
const phone1 = phoneNums.substring(4, 7); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if code is EAN13 | |
* | |
* @link https://github.com/hampus-nilsson/gs1-checkdigit/blob/main/checkdigit.js | |
* @param {string} input | |
* @returns {boolean} | |
*/ | |
export function isGTIN(input) { | |
if (![8, 12, 13, 14].includes(input.length)) return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://jkorpela.fi/chars/spaces.html | |
export const UNICODE_SPACES_REGEX = | |
/[\u00A0\u180E\u2000-\u200B\u202F\u205F\u3000\uFEFF]/gm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { pipeline } from 'node:stream/promises' | |
import zlib from 'node:zlib' | |
/** | |
* gzip | |
* | |
* @param {Buffer | string} data | |
*/ | |
export async function gzip(data) { | |
/** @type {Buffer} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const Kbyte = 1024; | |
export const Mbyte = Kbyte * Kbyte; | |
export const Gbyte = Kbyte * Mbyte; |
NewerOlder