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; |
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
declare module NodeJS { | |
interface Global { | |
// TODO Использовать Symbol? | |
appConfig: { | |
/** | |
* Продукты которые необходимо добавить в заказ | |
*/ | |
appedingProducts: Array<{ | |
/** Ссылка на товар в API */ | |
ref: `entity/${string}/${string}` |
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 { | |
S3Client, | |
PutObjectCommand, | |
GetObjectCommand, | |
HeadObjectCommand | |
} from '@aws-sdk/client-s3' | |
import { getSignedUrl } from '@aws-sdk/s3-request-presigner' | |
import path from 'node:path' | |
import mime from 'mime-types' |
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 assert from "node:assert"; | |
import { readFileSync } from "node:fs"; | |
let inputText; | |
try { | |
inputText = readFileSync(process.stdin.fd, "utf-8"); | |
} catch (err) { | |
assert.ok(err instanceof Error); |
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 farmhash from "farmhash"; | |
/** | |
* Returns a farmhash | |
* | |
* @param {string} content | |
*/ | |
export function getFarmhash(content) { | |
return farmhash.hash64(stable); | |
} |
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 assert from 'node:assert' | |
const YA_DATE_REGEX = /(\d\d)-(\d\d)-(\d\d\d\d)(?:\s(\d\d):(\d\d):(\d\d))?/g | |
/** | |
* Разбор даты в формате `ДД-ММ-ГГГГ ЧЧ:ММ:СС` | |
* @param {string} date | |
*/ | |
export const parseYaMarketDate = date => { | |
YA_DATE_REGEX.lastIndex = 0 |
NewerOlder