Skip to content

Instantly share code, notes, and snippets.

View wmakeev's full-sized avatar
💭
💻

Makeev Vitaliy wmakeev

💭
💻
View GitHub Profile
@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
@wmakeev
wmakeev / getMatchMap.js
Last active September 19, 2023 11:28
[CSV transform] #csv #stream #pipeline #zip
import { parse } from 'csv-parse/sync'
import { fetch } from 'undici'
/**
* Возвращает Map для сопоставления
*
* @param {string} matchTableCsvUrl
* @param {string} fieldFrom
* @param {string} fieldTo
* @returns {Promise<Map<string, string>>}
@wmakeev
wmakeev / isNotNullable.js
Created July 25, 2023 16:29
[JS typeguards] #typescript #typeguard #js #jsdoc
/**
* Checks if the value is neither `null` or `undefined`.
* @template T
* @param {T} value The value to check.
* @returns { value is NonNullable<T> } Returns `true` if `value` is non-nullable, else `false`.
*/
export default function isNonNullable(value) {
return value != null
}
@wmakeev
wmakeev / attachment-download.js
Created July 25, 2023 02:02
[Get email attachments with IMAP] #email #imap
import { ImapFlow } from 'imapflow'
import { simpleParser } from 'mailparser'
import { writeFile } from 'node:fs/promises'
import path from 'node:path'
import { env } from './env.js'
const { EMAIL_HOST, EMAIL_PORT, EMAIL_USER, EMAIL_PASSWORD } = env
const client = new ImapFlow({
@wmakeev
wmakeev / getLocationHashMap.js
Created June 20, 2023 08:21
[window.location.hash parser] #window #location #hash #parse #js #browser
const getLocationHashMap = () => {
const hash = window.location.hash.substring(
window.location.hash.substring(0, 2) === "#!" ? 2 : 1
);
const hashMap = hash
.split("&")
.map((entry) => {
const eqIndex = entry.indexOf("=");
@wmakeev
wmakeev / index.js
Last active September 2, 2024 03:47
[OZON JS API wrapper rev.2] #ozon #api
import { request } from "undici";
import nodePath from "node:path";
const OZON_API_ENDPOINT = "api-seller.ozon.ru";
export class Ozon {
/** @type {OzonOptions} */
#options;
/**