Bscotch Utilities
Utility and helper methods for common programming problems in Node.js.
(These utilities do not work in browsers.)
Installation
Requirements
Installation
npm install @bscotch/utility
Usage
Typescript:
import {method} from "@bscotch/utility"
JavaScript:
const {method} = require('@bscotch/utility');
Strings
import {
undent,
oneline
} from '@bscotch/utility';
oneline`
This string
will be converted
into
one that is
on a single line.
`;
undent`
All lines will
be un-inindented
based on the line
with the smallest indentation.
`;
Paths
import {
toPosixPath,
sortedPaths,
parentPaths
} from '@bscotch/utility';
toPosixPath("C:\\hello\\world");
const pathList = [
'hello/world',
'hello',
'h/another',
'hello/world/goodbye'
];
sortedPaths(pathList);
parentPaths('/hello/world/foo/bar.txt')
Files
import {
listPathsSync,
listFoldersSync,
listFilesSync,
listFilesByExtensionSync,
removeEmptyDirsSync,
} from '@bscotch/utility';
const recursive = true;
listPathsSync('.',recursive);
listFoldersSync('.',recursive);
listFilesSync('.',recursive);
listFilesByExtensionSync('.','txt',recursive);
listFilesByExtensionSync('.',['txt','md'],recursive);
removeEmptyDirsSync('.');