Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Created December 14, 2016 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rich-Harris/39128d7fecbc4e62c16f9b692ac52541 to your computer and use it in GitHub Desktop.
Save Rich-Harris/39128d7fecbc4e62c16f9b692ac52541 to your computer and use it in GitHub Desktop.
.DS_Store
node_modules
(function () {
'use strict';
var BEEP_DELAY = 500;
function beep() {
process.stdout.write('\u0007');
}
function melodicalBeep(val, cb) {
if (val.length === 0) {
cb();
return;
}
setTimeout(function () {
if (val.shift() === '*') {
beep();
}
melodicalBeep(val, cb);
}, BEEP_DELAY);
}
var index = function (val, cb) {
if (!process.stdout.isTTY ||
process.argv.indexOf('--no-beep') !== -1 ||
process.argv.indexOf('--beep=false') !== -1) {
return;
}
cb = cb || function () {};
if (val === parseInt(val)) {
if (val < 0) {
throw new TypeError('Negative numbers are not accepted');
}
if (val === 0) {
cb();
return;
}
for (var i = 0; i < val; i++) {
setTimeout(function (i) {
beep();
if (i === val - 1) {
cb();
}
}, BEEP_DELAY * i, i);
}
} else if (!val) {
beep();
cb();
} else if (typeof val === 'string') {
melodicalBeep(val.split(''), cb);
} else {
throw new TypeError('Not an accepted type');
}
};
console.log( `beeper`, index );
}());
import beeper from 'beeper';
console.log( `beeper`, beeper )
{
"devDependencies": {
"rollup": "^0.37.0",
"rollup-plugin-commonjs": "^5.0.5",
"rollup-plugin-node-resolve": "^2.0.0"
},
"dependencies": {
"beeper": "^1.1.1"
},
"scripts": {
"build": "rollup -c"
}
}
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
export default {
entry: 'index.js',
dest: 'bundle.js',
format: 'iife',
plugins: [
nodeResolve(),
commonjs()
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment