@leomax/utils
v0.0.3
Published
## Node
Downloads
7
Readme
@leomax/utils
Node
Функции для упрощения работы с node-окружением.
import { node } from '@leomax/utils';
getRootDir
Возвращает корневую директорию проекта (если возможно)
import { getRootDir } from '@leomax/utils/node';
getRootDir(); // путь к корню проекта
// or
node.getRootDir();
Аргументы
- cwd:
string
- исходная точка поиска.
- По-умолчанию:
process.cwd()
(папка, из которой запущен скрипт)
Functions
Различные хелперы (будет часто менятся, юзайте декораторы)
import { functions } from '@leomax/utils';
memorize
Кеширует функцию
import { memorize } from '@leomax/utils/functions';
function myFunc (count: number): number {
if (count < 2) {
return 1;
}
return count + myFunc(count - 1);
}
memorize(myFunc);
// or
functions.memorize(myFunc);
Аргументы
- value:
Function
- функция - keyGetter:
(...args: any[]) => any
- функция, получающая ключ по аргументам
- По-умолчанию ключ, - первый аргумент
Decorators
Декораторы. Просто декораторы.
import { decorators } from '@leomax/utils';
memorize
import { memorize } from '@leomax/utils/decorators';
class {
@memorize()
// or @decorators.memorize()
myMethod () {
// ...
}
}