Skip to content

Instantly share code, notes, and snippets.

View wmakeev's full-sized avatar
💭
💻

Makeev Vitaliy wmakeev

💭
💻
View GitHub Profile
@wmakeev
wmakeev / phone-format-simple.js
Created June 22, 2024 07:52
[phone format] #phone #format
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);
@wmakeev
wmakeev / isGTIN.js
Created March 15, 2024 10:00
[barcode] #barcode #gtin #ean
/**
* 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;
@wmakeev
wmakeev / unicode_spaces.js
Last active March 9, 2024 09:02
[unicode] #unicode #regex #space
// https://jkorpela.fi/chars/spaces.html
export const UNICODE_SPACES_REGEX =
/[\u00A0\u180E\u2000-\u200B\u202F\u205F\u3000\uFEFF]/gm;
@wmakeev
wmakeev / zip.js
Last active February 15, 2024 05:33
[gzip buffer async] #zip #gzip
import { pipeline } from 'node:stream/promises'
import zlib from 'node:zlib'
/**
* gzip
*
* @param {Buffer | string} data
*/
export async function gzip(data) {
/** @type {Buffer} */
@wmakeev
wmakeev / consts.ts
Last active January 24, 2024 08:59
[highland.js ETL] #etl #highland #tools
export const Kbyte = 1024;
export const Mbyte = Kbyte * Kbyte;
export const Gbyte = Kbyte * Mbyte;
@wmakeev
wmakeev / global.d.ts
Created December 18, 2023 06:11
Node global typing #node #typescript #global
declare module NodeJS {
interface Global {
// TODO Использовать Symbol?
appConfig: {
/**
* Продукты которые необходимо добавить в заказ
*/
appedingProducts: Array<{
/** Ссылка на товар в API */
ref: `entity/${string}/${string}`
@wmakeev
wmakeev / index.js
Created October 22, 2023 12:21
[S3BucketStorage] #s3 #bucket #upload #storage #tools
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'
@wmakeev
wmakeev / read-stdin.js
Last active October 4, 2023 07:09
[Read stdin node.js] #node #stdin #stream
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);
@wmakeev
wmakeev / farmhash.js
Last active June 4, 2024 07:19
[hash] #hash #sha256 #md5 #farmhash
import farmhash from "farmhash";
/**
* Returns a farmhash
*
* @param {string} content
*/
export function getFarmhash(content) {
return farmhash.hash64(stable);
}
@wmakeev
wmakeev / date.js
Created July 29, 2023 13:20
[Яндекс Маркет (даты)] #yandex #market #date #parse
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