zerion-nox
v1.3.1
Published
High-level utility library with storage, http, and pattern matching
Readme
Zerion Nox v1.3.0
High-level utility library with storage, HTTP, and pattern matching.
Installation
npm install zerion-noxUsage
CommonJS & ESM
const { st, wg, ptc } = require('zerion-nox');
import { st, wg, ptc } from 'zerion-nox';Storage (st)
await st.read('file.txt');
await st.readBinary('file.bin');
await st.write('file.txt', 'content');
await st.writeBinary('file.bin', buffer);
await st.append('file.txt', 'more');
await st.delete('file.txt');
await st.deleteDir('folder');
st.exists('file.txt');
st.isFile('path');
st.isDir('path');
await st.mkdir('folder');
await st.copy('source.txt', 'dest.txt');
await st.move('old.txt', 'new.txt');
await st.rename('old', 'new');
await st.stat('file.txt');
await st.chmod('file.txt', 0o755);
await st.size('file.txt');
await st.list('folder');
await st.listDeep('folder');
st.watch('file.txt', ({ eventType, filename }) => {});
st.watchDeep('folder', ({ eventType, filename }) => {});
await st.readJson('data.json');
await st.writeJson('data.json', { key: 'value' });
await st.all('folder');
await st.allJson('folder');
await st.allBinary('folder');
await st.glob('folder', '.*\\.js$');
await st.touch('file.txt');
st.getExt('file.txt');
st.getBasename('file.txt');
st.getDirname('file.txt');
st.resolve('file.txt');
st.join('folder', 'file.txt');Web Client (wg)
const res = await wg.req('https://api.example.com/data', { method: 'GET', headers: {}, timeout: 30000 });
const res = await wg.get('https://api.example.com/data');
const res = await wg.post('https://api.example.com/data', { key: 'value' });
const res = await wg.put('https://api.example.com/data/1', { key: 'value' });
const res = await wg.patch('https://api.example.com/data/1', { key: 'value' });
const res = await wg.del('https://api.example.com/data/1');
const res = await wg.delete('https://api.example.com/data/1');
const res = await wg.head('https://api.example.com/data');
const res = await wg.options('https://api.example.com/data');
const formData = new FormData();
formData.append('file', file);
const res = await wg.uploadForm('https://api.example.com/upload', formData);
const results = await wg.batch([
{ url: 'https://api.example.com/1' },
{ url: 'https://api.example.com/2' }
]);
const res = await wg.retry('https://api.example.com/data', {}, 3);
await wg.stream('https://api.example.com/stream', (chunk) => {
console.log(chunk);
});
const result = await wg.timeout(somePromise, 5000);Pattern Checker (ptc)
ptc.test('\\d+', '123');
ptc.match('\\d+', 'abc123def');
ptc.matchAll('\\d+', 'a1b2c3');
ptc.extract('\\d+', 'a1b2c3');
ptc.extractGroups('(\\w+)-(\\d+)', 'user-123');
ptc.replace('\\d+', 'a1b2c3', 'X');
ptc.replaceAll('\\d+', 'a1b2c3', 'X');
ptc.split('\\s+', 'hello world');
ptc.query('div', htmlString);
ptc.queryAttr('img', 'src', htmlString);
ptc.queryText('p', htmlString);
ptc.parse(htmlString);
ptc.parseAttrs('class="active" id="main"');
ptc.clean(htmlString);
ptc.sanitize(textString);
ptc.unsanitize(htmlString);
ptc.email('contact [email protected]');
ptc.url('visit https://example.com');
ptc.phone('call 555-1234');
ptc.ipv4('192.168.1.1');
ptc.uuid('550e8400-e29b-41d4-a716-446655440000');
ptc.camelToSnake('camelCase');
ptc.snakeToCamel('snake_case');
ptc.camelToKebab('camelCase');
ptc.kebabToCamel('kebab-case');License
MIT
