Package Exports
- @ntlab/ntlib
- @ntlab/ntlib/charseq
- @ntlab/ntlib/charseq.js
- @ntlab/ntlib/cmd
- @ntlab/ntlib/cmd.js
- @ntlab/ntlib/index.js
- @ntlab/ntlib/logger
- @ntlab/ntlib/logger.js
- @ntlab/ntlib/token
- @ntlab/ntlib/token.js
- @ntlab/ntlib/util
- @ntlab/ntlib/util.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ntlab/ntlib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A collection of common library
Character Sequence (charseq.js)
Class to handle string as a sequence of character.
const { CharSequence } = require('@ntlab/ntlib');
let charseq = new CharSequence('This is a string');
while (!charseq.eof()) {
console.log(charseq.read(1));
}Command Line Argument Parser (cmd.js)
Provide functions to work with Command Line arguments.
const path = require('path');
const { Cmd } = require('@ntlab/ntlib');
Cmd.addBool('help', 'h', 'Show program usage').setAccessible(false);
Cmd.addVar('something', 's', 'Something description', 'some-argument');
if (!Cmd.parse() || (Cmd.get('help') && usage())) {
process.exit();
}
/* do something here */
function usage() {
console.log('Usage:');
console.log(' node %s [options]', path.basename(process.argv[1]));
console.log('');
console.log('Options:');
console.log(Cmd.dump());
console.log('');
return true;
}CLI or HTTP Executor (command.js, httpcmd.js)
Execute a Command Line Interface (CLI) or HTTP command.
const { CommandExecutor } = require('@ntlab/ntlib');
const cmd = {
bin: 'php',
cli: 'path/to/php.file.to.execute.php',
args: [
'-f',
'%CLI%',
'--',
'%DATA%'
]
}
const p = CommandExecutor(cmd).exec({DATA: 'some-data'});
p.on('exit', (code) => {
/* do something on exit */
});
p.stdout.on('data', (line) => {
/* do something on stdout data */
});
p.stderr.on('data', (line) => {
/* do something on stderr data */
});A Simple Logger (logger.js)
Provide a simple logger class.
const { Logger } = require('@ntlab/ntlib');
const log = new Logger('/path/to/logfile');
log.log('Somthing to log');Stringify (stringify.js)
Convert javascript object to string.
const { Stringify } = require('@ntlab/ntlib');
log.log(Stringify.from({
message: 'message',
raw: Stringify.raw('`string`'),
}));Token Processing (token.js)
Provide an utility to parse string into tokens.
const { Token } = require('@ntlab/ntlib');
console.log(Token.split('1, 2, (1, "ABC")')); // [1, 2, [1, "ABC"]]App Utility (util.js)
Internally used by CLI/HTTP Executor, also provide a small set of common functions.
const { AppUtil } = require('@ntlab/ntlib');
console.log(AppUtil.trans('Translate %ME%', {ME: '123'})); // Translate 123