1.0.6-dev.1 • Published 10 months ago
@millionfor/utils v1.0.6-dev.1
@millionfor/utils
A Typescript based Node Development Tool Library.
Installation
$ npm i @millionfor/utilsUsage
const tryToCatch = require('try-catch')
const utils = require('@millionfor/utils')
const { writeJSON, rmDirFile } = utilsAPIs
1. writeJSON
writeJSON.default(name, object, options, callback)
Asynchonouse write stringified object.
const [error] = await tryToCatch(writeJSON.default, 'data.json', {hello: 'world'});
if (error)
console.error(error.message);
const options = {
replacer: ['hello'], // properties to put in json
space: 4, // default space count
eof: true, // default new line at end of file
encoding: 'utf8', // default
mode: '0o666', // default
flag: 'w', // default
};
await writeJSON.default('data.json', {hello: 'world'}, options);writeJSON.sync(name, object, options)
Synchonouse write stringified object.
try {
writeJSON.sync('data.json', {hello: 'world'});
} catch(error) {
console.log(error.message);
}writeJSON.syncTry(name, object, options)
Synchonouse try to write stringified object.
writeJSON.syncTry('data.json', {hello: 'world'});2. rm
delete directory recursively
rmDirFile('./data.json')3. writeText
Write file text content
writeText('./data.md', 'my test')import writeJSON, { sync, syncTry } from './writeJSON';
declare const _default: {
writeJSON: {
default: typeof writeJSON;
sync: typeof sync;
syncTry: typeof syncTry;
};
rmDirFile: (path: string) => Promise<void>;
writeText: (filePath: string, content: string) => Promise<any>;
};
export default _default;License
MIT
3.1.0-0
11 months ago
3.1.1-1
11 months ago
3.1.1-0
11 months ago
1.0.7-0
11 months ago
1.0.6-0
11 months ago
1.0.5
11 months ago
2.1.1
11 months ago
3.0.0-0
11 months ago
1.0.4-dev.6
11 months ago
1.0.4-dev.5
11 months ago
1.0.6-dev.1
10 months ago
1.0.4-dev.7
11 months ago
1.0.4-dev.2
11 months ago
1.0.4-dev.1
11 months ago
1.0.4-dev.4
11 months ago
1.0.4-dev.3
11 months ago
2.1.0
11 months ago
2.0.0
11 months ago
1.0.3
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago