다른 작업을 진행하다가 정말로 오랜만에 다시 Node.js 관련 오픈 소스 분석 작업을 하는데 참조하고 있는 패키지들이 많기도 하다. 아는 것보다는 모르는 것이 더 많아서 뭐가 뭔지 하나도 모르겠다.
앞으로 작업을 하면서 좀 더 다양한 패키지들을 자세하게 알아야 하지만, 당장은 제목과 기능이라도 알아야 이해를 할 수 있을 듯 하다. ㅠㅠ
Packages for NodeJS
bluebird
Full featured promise library with unmatched performance
Examples
References
bunyan
Simple and fast JSON Logging Module for node.js services
Examples
References
camelcase
Convert a dash/dot/underscore/space separated string to camelCase: foo-bar -> fooBar
Examples
설치
$ npm install --save camelcase
활용법
const camelCase = require('camelcase');
camelCase('foo-bar'); //=> 'fooBar'
camelCase('foo_bar'); //=> 'fooBar'
camelCase('Foo-Bar'); //=> 'fooBar'
camelCase('--foo.bar'); //=> 'fooBar'
camelCase('__foo__bar__'); //=> 'fooBar'
camelCase('foo bar'); //=> 'fooBar'
camelCase('foo', 'bar'); //=> 'fooBar'
camelCase('__foo__', '--bar'); //=> 'fooBar'
console.log(process.argv[3]); //=> '--foo-bar'
camelCase(process.argv[3]); //=> 'fooBar'
References
chai
BDD (Behavior-Driven Development) / TDD (Test-Driven Development) Assersion Library for Node
Examples
설치
$ npm install bunyan
활용법
// Should
chai.should();
foo.should.be.a('string');
foo.should.equal('bar');
foo.should.have.lengthOf(3);
tea.should.have.property('flavors').with.lengthOf(3);
// Expect
var expect = chai.expect;
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
expect(tea).to.have.property('flavors').with.lengthOf(3);
// Assert
var assert = chai.assert;
assert.typeOf(foo, 'string');
assert.equal(foo, 'bar');
assert.lengthOf(foo, 3)
assert.property(tea, 'flavors');
assert.lengthOf(tea.flavors, 3);
References
chalk
Terminal String Styling done right
Examples
References
chokidar
A neat wrapper around node.js fs.watch / fs.watchFile / fsevents.
Examples
설치
$ npm install chokidar --save
활용법
var chokidar = require('chokidar');
// One-liner for current directory, ignores .dotfiles
chokidar.watch('.', {ignored: /(^|[\/\\])\../}).on('all', (event, path) => {
console.log(event, path);
});
// Example of a more typical implementation structure:
// Initialize watcher.
var watcher = chokidar.watch('file, dir, glob, or array', {
ignored: /(^|[\/\\])\../,
persistent: true
});
// Something to use when events are received.
var log = console.log.bind(console);
// Add event listeners.
watcher
.on('add', path => log(`File ${path} has been added`))
.on('change', path => log(`File ${path} has been changed`))
.on('unlink', path => log(`File ${path} has been removed`));
// More possible events.
watcher
.on('addDir', path => log(`Directory ${path} has been added`))
.on('unlinkDir', path => log(`Directory ${path} has been removed`))
.on('error', error => log(`Watcher error: ${error}`))
.on('ready', () => log('Initial scan complete. Ready for changes'))
.on('raw', (event, path, details) => {
log('Raw event info:', event, path, details);
});
// 'add', 'addDir' and 'change' events also receive stat() results as second
// argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats
watcher.on('change', (path, stats) => {
if (stats) console.log(`File ${path} changed size to ${stats.size}`);
});
// Watch new files.
watcher.add('new-file');
watcher.add(['new-file-2', 'new-file-3', '**/other-file*']);
// Get list of actual paths being watched on the filesystem
var watchedPaths = watcher.getWatched();
// Un-watch some files.
watcher.unwatch('new-file*');
// Stop watching.
watcher.close();
// Full list of options. See below for descriptions. (do not use this example)
chokidar.watch('file', {
persistent: true,
ignored: '*.txt',
ignoreInitial: false,
followSymlinks: true,
cwd: '.',
usePolling: true,
interval: 100,
binaryInterval: 300,
alwaysStat: false,
depth: 99,
awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 100
},
ignorePermissionErrors: false,
atomic: true // or a custom 'atomicity delay', in milliseconds (default 100)
});
References
escape-string-regexp
Escape RegExp Special Characters
Examples
설치
$ npm install --save escape-string-regexp
활용법
const escapeStringRegexp = require('escape-string-regexp');
const escapedString = escapeStringRegexp('how much $ for a unicorn?');
//=> 'how much \$ for a unicorn\?'
new RegExp(escapedString);
References
eslint
Pluggable Linting utility for JavaScript and JSX
Examples
References
graceful-fs
drop-in replacement for the fs module, making various improvements.
Examples
설치
$ npm install graceful-fs
활용법
// use just like fs
var fs = require('graceful-fs')
// now go and do stuff with it...
fs.readFileSync('some-file-or-whatever')
//
// Global Patching
//
// Make sure to read the caveat below.
var realFs = require('fs')
var gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(realFs)
References
istanbul
JS Code Coverage tool written in JS
Examples
References
jscs
Javascript Code Style Checker
Examples
References
minimist
guts of optimist's argument parser without all the fanciful decoration
Examples
References
mocha
Fun, Simple, Flexible Javascript Test Framework
Examples
References
nyc
Istanbul command line interface
Examples
설치
$ npm i nyc --save-dev
활용법
References
require-dir
Node.js 지원을 위해 지정한 디렉터리 단위로 존재하는 파일들을 일괄 require() 처리
Examples
설치
$ npm install require-dir
활용법
var requireDir = require('require-dir');
var dir = requireDir('./path/to/dir');
var dir = requireDir('./path/to/dir', {recurse: true});
References
rewire
Easy monkey-patching for node.js unit tests
Examples
설치
$ npm install rewire
활용법
자세한 활용법은 아래 사이트 설명 참조
References
shelljs, shelljs/shx
shelljs: Portable Unix shell commands for Node.js
shelljs/shx: Portable Shell Commands for Node.js
Examples
설치
$ npm install shelljs
$ npm install shelljs/shx # for command line
활용법 (shelljs)
var shell = require('shelljs');
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
}
// Copy files to release dir
shell.rm('-rf', 'out/Release');
shell.cp('-R', 'stuff/', 'out/Release');
// Replace macros in each .js file
shell.cd('lib');
shell.ls('*.js').forEach(function (file) {
shell.sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
shell.sed('-i', /^.*REMOVE_THIS_LINE.*$/, '', file);
shell.sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, shell.cat('macro.js'), file);
});
shell.cd('..');
// Run external tool synchronously
if (shell.exec('git commit -am "Auto-commit"').code !== 0) {
shell.echo('Error: Git commit failed');
shell.exit(1);
}
활용법 (shelljs/shx)
# used in command line using shx
$ shx mkdir -p foo
$ shx touch foo/bar.txt
$ shx rm -rf foo
References
sinon
Standalone test spies, stubs and mocks for Javascript. work with any unit testing framework.
Examples
설치
$ npm install sinon
활용법
자세한 활용법은 아래 사이트 설명 참조
References
standard
Javascript 표준 스타일 가이드 with Linter & Automatic code fixer
Examples
References
tildify
Convert an absolute path to the tilde path: /Users/sindresorhus/dev to ~/dev
Examples
References
yargs
Yargs helps you build interactive command line tools by parsing arguments and generating an elegant user interface
Examples
설치
$ npm install yargs
활용법
#!/usr/bin/env node
require('yargs')
.usage('$0 <cmd> [args]')
.command('hello [name]', 'welcome ter yargs!', {
name: {
default: 'default name'
}
}, function (argv) {
console.log('hello', argv.name, 'welcome to yargs!')
})
.help()
.argv
자세한 활용법은 아래 사이트 설명 참조
References
Written by Morris (ccambo@gmail.com - MSFL)
댓글
댓글 쓰기