Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
peol committed Jul 14, 2014
0 parents commit bd2dabe
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_STORE
node_modules/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Andrée Hansson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# sigint-hook
Normalize the process SIGINT signal.

## Usage

### Install
```
npm install sigint-hook
```

### Configuration
`eventOnHookOnly` (default `false`): if `true`, will not emit on the `process` global object
`triggerOnce` (default: `false`): if `true`, will stop listening after first `SIGINT` signal

### Examples
Default:
```js
require("sigint-hook")().on("SIGINT", function() {
// do something
});
```
Customized:
```js
require("sigint-hook")({
eventOnHookOnly: true,
triggerOnce: true
}).on("SIGINT", function() {
// do something
});
```
Please note that you can kill sigint-hook by running the `.close()` method on the return object:
```js
var sigint = require("sigint-hook")({
eventOnHookOnly: true
}).on("SIGINT", function() {
// do something
});

// kill off early:
sigint.close();
```

## License
This project uses MIT. See `LICENSE` file for additional information.
29 changes: 29 additions & 0 deletions esformatter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"indent": {
"value": "\t"
},
"whiteSpace": {
"before": {
"ArgumentList": 1,
"ArgumentListArrayExpression": 1,
"ArgumentListFunctionExpression": 1,
"ArgumentListObjectExpression": 1,
"CallExpression": 0,
"ForStatementExpression": 1,
"IfStatementConditionalClosing": 1,
"ParameterList": 1,
"WhileStatementConditional": 1
},
"after": {
"ArgumentList": 1,
"ArgumentListArrayExpression": 1,
"ArgumentListFunctionExpression": 1,
"ArgumentListObjectExpression": 1,
"ForStatementExpression": 1,
"FunctionExpressionClosingBrace": 1,
"IfStatementConditionalOpening": 1,
"ParameterList": 1,
"WhileStatementConditional": 1
}
}
}
134 changes: 134 additions & 0 deletions eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"env": {
"browser": false,
"node": true,
"amd": false
},

"rules": {
"no-alert": 2,
"no-array-constructor": 2,
"no-bitwise": 0,
"no-caller": 2,
"no-catch-shadow": 2,
"no-comma-dangle": 2,
"no-cond-assign": 2,
"no-console": 2,
"no-constant-condition": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-div-regex": 0,
"no-dupe-keys": 2,
"no-else-return": 0,
"no-empty": 2,
"no-empty-class": 2,
"no-empty-label": 2,
"no-eq-null": 0,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": 0,
"no-extra-semi": 2,
"no-extra-strict": 2,
"no-fallthrough": 2,
"no-floating-decimal": 0,
"no-func-assign": 2,
"no-global-strict": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 0,
"no-loop-func": 2,
"no-mixed-requires": [0, false],
"no-multi-str": 2,
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-nested-ternary": 0,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 0,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-path-concat": 0,
"no-plusplus": 0,
"no-process-exit": 2,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-restricted-modules": 0,
"no-return-assign": 2,
"no-script-url": 2,
"no-self-compare": 0,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-space-before-semi": 2,
"no-sparse-arrays": 2,
"no-sync": 0,
"no-ternary": 0,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-undefined": 0,
"no-undef-init": 2,
"no-underscore-dangle": 0,
"no-unreachable": 2,
"no-unused-expressions": 2,
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
"no-use-before-define": 2,
"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
"no-with": 2,
"no-wrap-func": 2,
"no-mixed-spaces-and-tabs": [2, false],

"block-scoped-var": 0,
"brace-style": [0, "1tbs"],
"camelcase": 2,
"complexity": [0, 11],
"consistent-return": 2,
"consistent-this": [0, "that"],
"curly": [2, "all"],
"default-case": 0,
"dot-notation": 2,
"eol-last": 2,
"eqeqeq": 2,
"func-names": 0,
"func-style": [0, "declaration"],
"guard-for-in": 0,
"max-depth": [0, 4],
"max-len": [0, 80, 4],
"max-nested-callbacks": [0, 2],
"max-params": [0, 3],
"max-statements": [0, 10],
"handle-callback-err": 0,
"new-cap": 2,
"new-parens": 2,
"one-var": 0,
"quote-props": 0,
"quotes": [2, "double"],
"radix": 0,
"semi": 2,
"sort-vars": 0,
"space-after-keywords": [0, "always"],
"space-in-brackets": [0, "never"],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-word-ops": 0,
"strict": 2,
"use-isnan": 2,
"valid-jsdoc": 0,
"valid-typeof": 2,
"wrap-iife": 0,
"wrap-regex": 0,
"yoda": [2, "never"]
}
}
35 changes: 35 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

module.exports = function( grunt ) {
grunt.initConfig( {
jsFiles: ["gruntfile.js", "index.js"],
eslint: {
options: {
config: "eslint.json"
},
src: "<%= jsFiles %>"
},
esformatter: {
options: require( "./esformatter.json" ),
src: "<%= jsFiles %>"
},
surveil: {
jsFormatting: {
rewritesWatchedFiles: true,
src: "<%= jsFiles %>",
tasks: ["eslint:partial", "esformatter:partial"],
prepare: function( files, task ) {
if ( task === "eslint:partial" ) {
grunt.config( "eslint.partial", files );
} else if ( task === "esformatter:partial" ) {
grunt.config( "esformatter.partial", files );
}
}
}
}
} );

grunt.loadNpmTasks( "grunt-esformatter" );
grunt.loadNpmTasks( "grunt-eslint" );
grunt.loadNpmTasks("grunt-surveil");
};
32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

var rlInstance = null;

module.exports = function sigintHook( opts ) {
opts = opts || {
eventOnHookOnly: false,
triggerOnce: false
};

if ( !rlInstance ) {
rlInstance = require( "readline" ).createInterface( {
input: process.stdin,
output: process.stdout
} );

rlInstance.on( "SIGINT", function() {
if ( !opts.eventOnHookOnly ) {
process.emit( "SIGINT" );
}
if ( opts.triggerOnce ) {
rlInstance.close();
}
} );

rlInstance.on( "close", function() {
rlInstance = null;
} );
}

return rlInstance;
};
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "sigint-hook",
"version": "0.1.0",
"description": "Take control of the SIGINT signal",
"keywords": [
"sigint",
"exit",
"windows"
],
"files": [
"index.js",
"LICENSE"
],
"repository": {
"type": "git",
"url": "git://github.com/peol/sigint-hook"
},
"bugs": "https://github.com/peol/sigint-hook/issues",
"author": "Andrée Hansson",
"license": "MIT",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-esformatter": "^0.2.3",
"grunt-eslint": "^0.6.0",
"grunt-surveil": "~0.1.1"
}
}

0 comments on commit bd2dabe

Please sign in to comment.