Skip to content

Instantly share code, notes, and snippets.

View wmakeev's full-sized avatar
💭
💻

Makeev Vitaliy wmakeev

💭
💻
View GitHub Profile
@wmakeev
wmakeev / index.js
Last active November 8, 2024 01:45
[Yandex Query API wrapper] #yandex-cloud #yandex #api #yandex-query
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', {
@wmakeev
wmakeev / date-format.js
Last active September 2, 2024 03:40
[Intl format] #date #number #money #format #intl #locale
// 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",
@wmakeev
wmakeev / getResourceDataUrl.js
Last active September 1, 2024 18:25
[base64 data url] #base64 #url #data
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);
@wmakeev
wmakeev / chan.js
Created August 3, 2024 23:14 — forked from benjamingr/chan.js
/*
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
@wmakeev
wmakeev / getPromiseWithResolvers.js
Last active August 2, 2024 13:35
[Promise with resolvers] #promise #helper
export function getPromiseWithResolvers() {
let resolve;
let reject;
const promise = new Promise((resolve_, reject_) => {
resolve = resolve_;
reject = reject_;
});
return { promise, resolve, reject };
@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;