Skip to content

Instantly share code, notes, and snippets.

View GeKiStolyarov's full-sized avatar
🏠
Working from home

Kirill Stolyarov GeKiStolyarov

🏠
Working from home
View GitHub Profile
@GeKiStolyarov
GeKiStolyarov / get-changelog.ts
Created April 30, 2021 05:04
Find files recursive using only node.js
import { resolve, extname, basename } from 'path';
import fsPromises from 'fs/promises';
// @ts-ignore
async function* getFiles(dir: string) {
const dirents = await fsPromises.readdir(dir, { withFileTypes: true });
for (const dirent of dirents) {
const res = resolve(dir, dirent.name);
if (dirent.isDirectory()) {
yield* getFiles(res);
@GeKiStolyarov
GeKiStolyarov / RNL.js
Created August 17, 2018 11:59
react-native link and unlink
react-native link <lib name>
// this command has done the unlinking of the library from both platforms.
react-native unlink <lib name>
// this has uninstalled the library from the node modules and its dependencies
react-native uninstall <lib name>
@GeKiStolyarov
GeKiStolyarov / for.js
Created July 9, 2018 03:28
for...in and for...of
const browsers = ['Chrome', 'Firefox', 'Edge', 'Safari', 'Opera'];
// for in
for (const browser in browsers) {
console.log(browser, '---', browsers[browser]);
}
// output
// "0" "---" "Chrome"
// "1" "---" "Firefox"
// "2" "---" "Edge"
@GeKiStolyarov
GeKiStolyarov / declOfNum.js
Last active July 9, 2018 03:30
Склонение числительных в javascript
function declOfNum(number, titles) {
const cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
// example
declOfNum(1, ['день', 'дня', 'дней']); // 1 день
declOfNum(2, ['день', 'дня', 'дней']); // 2 дня
declOfNum(5, ['день', 'дня', 'дней']); // 5 дней