Socket
Socket
Sign inDemoInstall

omelette

Package Overview
Dependencies
0
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.9 to 0.4.11

2

package.json

@@ -11,3 +11,3 @@ {

"author": "Fatih Kadir Akın <fka@fatihak.in>",
"version": "0.4.9",
"version": "0.4.11",
"licenses": [

@@ -14,0 +14,0 @@ {

@@ -146,6 +146,6 @@ <img src="https://rawgit.com/f/omelette/master/resources/logo.svg?v1" height="80">

Omelette allows you to use `async` functions. You have to pass `Promise` object to the `reply` function.
Omelette allows you to use `async` functions. You have to use `onAsync` and to pass `Promise` object to the `reply` function.
```javascript
complete.on('user', async ({ reply }) => {
complete.onAsync('user', async ({ reply }) => {
reply(new Promise((resolve) => {

@@ -166,3 +166,3 @@ fs.readdir('/Users/', (err, users) => {

complete.on('user', async ({ reply }) => {
complete.onAsync('user', async ({ reply }) => {
reply(new Promise((resolve) => {

@@ -191,3 +191,3 @@ fs.readdir('/Users/', (err, users) => {

complete.on('user', async ({ reply }) => {
complete.onAsync('user', async ({ reply }) => {
reply(await promisify(fs.readdir)('/Users'))

@@ -194,0 +194,0 @@ })

@@ -1,14 +0,10 @@

// Generated by CoffeeScript 1.12.7
/*
* Omelette Simple Auto Completion for Node
*/
// Generated by CoffeeScript 2.2.4
(function() {
/*
* Omelette Simple Auto Completion for Node
*/
var EventEmitter, Omelette, depthOf, fs, os, path,
hasProp = {}.hasOwnProperty,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
slice = [].slice;
hasProp = {}.hasOwnProperty;
EventEmitter = require("events").EventEmitter;
({EventEmitter} = require("events"));

@@ -34,250 +30,236 @@ path = require("path");

Omelette = (function(superClass) {
Omelette = (function() {
var log;
extend(Omelette, superClass);
class Omelette extends EventEmitter {
constructor() {
var isFish, isZsh, ref;
super();
this.asyncs = 0;
this.compgen = process.argv.indexOf("--compgen");
this.install = process.argv.indexOf("--completion") > -1;
this.installFish = process.argv.indexOf("--completion-fish") > -1;
isZsh = process.argv.indexOf("--compzsh") > -1;
isFish = process.argv.indexOf("--compfish") > -1;
this.isDebug = process.argv.indexOf("--debug") > -1;
this.fragment = parseInt(process.argv[this.compgen + 1]) - (isZsh ? 1 : 0);
this.line = process.argv.slice(this.compgen + 3).join(' ');
this.word = (ref = this.line) != null ? ref.trim().split(/\s+/).pop() : void 0;
({HOME: this.HOME, SHELL: this.SHELL} = process.env);
this.mainProgram = function() {};
}
log = console.log;
setProgram(programs) {
programs = programs.split('|');
[this.program] = programs;
return this.programs = programs.map(function(program) {
return program.replace(/[^A-Za-z0-9\.\_\-]/g, ''); // Do not allow except:
// .. uppercase
// .. lowercase
// .. numbers
// .. dots
// .. underscores
// .. dashes
});
}
function Omelette() {
var isFish, isZsh, ref, ref1;
Omelette.__super__.constructor.call(this);
this.asyncs = 0;
this.compgen = process.argv.indexOf("--compgen");
this.install = process.argv.indexOf("--completion") > -1;
this.installFish = process.argv.indexOf("--completion-fish") > -1;
isZsh = process.argv.indexOf("--compzsh") > -1;
isFish = process.argv.indexOf("--compfish") > -1;
this.isDebug = process.argv.indexOf("--debug") > -1;
this.fragment = parseInt(process.argv[this.compgen + 1]) - (isZsh ? 1 : 0);
this.line = process.argv.slice(this.compgen + 3).join(' ');
this.word = (ref = this.line) != null ? ref.trim().split(/\s+/).pop() : void 0;
ref1 = process.env, this.HOME = ref1.HOME, this.SHELL = ref1.SHELL;
this.mainProgram = function() {};
}
setFragments(...fragments1) {
this.fragments = fragments1;
}
Omelette.prototype.setProgram = function(programs) {
programs = programs.split('|');
this.program = programs[0];
return this.programs = programs.map(function(program) {
return program.replace(/[^A-Za-z0-9\.\_\-]/g, '');
});
};
Omelette.prototype.setFragments = function() {
var fragments1;
fragments1 = 1 <= arguments.length ? slice.call(arguments, 0) : [];
this.fragments = fragments1;
};
Omelette.prototype.generate = function() {
var data;
data = {
before: this.word,
fragment: this.fragment,
line: this.line,
reply: this.reply
};
this.emit("complete", this.fragments[this.fragment - 1], data);
this.emit(this.fragments[this.fragment - 1], data);
this.emit("$" + this.fragment, data);
if (this.asyncs === 0) {
return process.exit();
generate() {
var data;
data = {
before: this.word,
fragment: this.fragment,
line: this.line,
reply: this.reply
};
this.emit("complete", this.fragments[this.fragment - 1], data);
this.emit(this.fragments[this.fragment - 1], data);
this.emit(`$${this.fragment}`, data);
if (this.asyncs === 0) {
return process.exit();
}
}
};
Omelette.prototype.reply = function(words) {
var writer;
if (words == null) {
words = [];
reply(words = []) {
var writer;
writer = function(options) {
console.log(typeof options.join === "function" ? options.join(os.EOL) : void 0);
return process.exit();
};
if (words instanceof Promise) {
return words.then(writer);
} else {
return writer(words);
}
}
writer = function(options) {
console.log(typeof options.join === "function" ? options.join(os.EOL) : void 0);
return process.exit();
};
if (words instanceof Promise) {
return words.then(writer);
} else {
return writer(words);
}
};
Omelette.prototype.next = function(handler) {
if (typeof handler === 'function') {
return this.mainProgram = handler;
next(handler) {
if (typeof handler === 'function') {
return this.mainProgram = handler;
}
}
};
Omelette.prototype.tree = function(objectTree) {
var depth, i, level, ref;
if (objectTree == null) {
objectTree = {};
}
depth = depthOf(objectTree);
for (level = i = 1, ref = depth; 1 <= ref ? i <= ref : i >= ref; level = 1 <= ref ? ++i : --i) {
this.on("$" + level, function(arg) {
var accessor, fragment, lastIndex, line, replies, reply;
fragment = arg.fragment, reply = arg.reply, line = arg.line;
if (!(/\s+/.test(line.slice(-1)))) {
lastIndex = -1;
}
accessor = new Function('_', "return _['" + (line.split(/\s+/).slice(1, lastIndex).filter(Boolean).join("']['")) + "']");
replies = fragment === 1 ? Object.keys(objectTree) : accessor(objectTree);
return reply((function(replies) {
if (replies instanceof Function) {
return replies();
tree(objectTree = {}) {
var depth, i, level, ref;
depth = depthOf(objectTree);
for (level = i = 1, ref = depth; (1 <= ref ? i <= ref : i >= ref); level = 1 <= ref ? ++i : --i) {
this.on(`$${level}`, function({fragment, reply, line}) {
var accessor, lastIndex, replies;
if (!(/\s+/.test(line.slice(-1)))) {
lastIndex = -1;
}
if (replies instanceof Array) {
return replies;
}
if (replies instanceof Object) {
return Object.keys(replies);
}
})(replies));
});
accessor = new Function('_', `return _['${line.split(/\s+/).slice(1, lastIndex).filter(Boolean).join("']['")}']`);
replies = fragment === 1 ? Object.keys(objectTree) : accessor(objectTree);
return reply((function(replies) {
if (replies instanceof Function) {
return replies();
}
if (replies instanceof Array) {
return replies;
}
if (replies instanceof Object) {
return Object.keys(replies);
}
})(replies));
});
}
return this;
}
return this;
};
Omelette.prototype.generateCompletionCode = function() {
var completions;
completions = this.programs.map((function(_this) {
return function(program) {
generateCompletionCode() {
var completions;
completions = this.programs.map((program) => {
var completion;
completion = "_" + program + "_completion";
return "### " + program + " completion - begin. generated by omelette.js ###\nif type compdef &>/dev/null; then\n " + completion + "() {\n compadd -- `" + _this.program + " --compzsh --compgen \"${CURRENT}\" \"${words[CURRENT-1]}\" \"${BUFFER}\"`\n }\n compdef " + completion + " " + program + "\nelif type complete &>/dev/null; then\n " + completion + "() {\n local cur prev nb_colon\n _get_comp_words_by_ref -n : cur prev\n nb_colon=$(grep -o \":\" <<< \"$COMP_LINE\" | wc -l)\n\n COMPREPLY=( $(compgen -W '$(" + _this.program + " --compbash --compgen \"$((COMP_CWORD - (nb_colon * 2)))\" \"$prev\" \"${COMP_LINE}\")' -- \"$cur\") )\n\n __ltrim_colon_completions \"$cur\"\n }\n complete -F " + completion + " " + program + "\nfi\n### " + program + " completion - end ###";
};
})(this));
if (this.isDebug) {
completions.push(this.generateTestAliases());
completion = `_${program}_completion`;
return `### ${program} completion - begin. generated by omelette.js ###\nif type compdef &>/dev/null; then\n ${completion}() {\n compadd -- \`${this.program} --compzsh --compgen "\${CURRENT}" "\${words[CURRENT-1]}" "\${BUFFER}"\`\n }\n compdef ${completion} ${program}\nelif type complete &>/dev/null; then\n ${completion}() {\n local cur prev nb_colon\n _get_comp_words_by_ref -n : cur prev\n nb_colon=$(grep -o ":" <<< "$COMP_LINE" | wc -l)\n\n COMPREPLY=( $(compgen -W '$(${this.program} --compbash --compgen "$((COMP_CWORD - (nb_colon * 2)))" "$prev" "\${COMP_LINE}")' -- "$cur") )\n\n __ltrim_colon_completions "$cur"\n }\n complete -F ${completion} ${program}\nfi\n### ${program} completion - end ###`;
});
if (this.isDebug) {
// Adding aliases for testing purposes
completions.push(this.generateTestAliases());
}
return completions.join(os.EOL);
}
return completions.join(os.EOL);
};
Omelette.prototype.generateCompletionCodeFish = function() {
var completions;
completions = this.programs.map((function(_this) {
return function(program) {
generateCompletionCodeFish() {
var completions;
completions = this.programs.map((program) => {
var completion;
completion = "_" + program + "_completion";
return "### " + program + " completion - begin. generated by omelette.js ###\nfunction " + completion + "\n " + _this.program + " --compfish --compgen (count (commandline -poc)) (commandline -pt) (commandline -pb)\nend\ncomplete -f -c " + program + " -a '(" + completion + ")'\n### " + program + " completion - end ###";
};
})(this));
if (this.isDebug) {
completions.push(this.generateTestAliases());
completion = `_${program}_completion`;
return `### ${program} completion - begin. generated by omelette.js ###\nfunction ${completion}\n ${this.program} --compfish --compgen (count (commandline -poc)) (commandline -pt) (commandline -pb)\nend\ncomplete -f -c ${program} -a '(${completion})'\n### ${program} completion - end ###`;
});
if (this.isDebug) {
// Adding aliases for testing purposes
completions.push(this.generateTestAliases());
}
return completions.join(os.EOL);
}
return completions.join(os.EOL);
};
Omelette.prototype.generateTestAliases = function() {
var debugAliases, debugUnaliases, fullPath;
fullPath = path.join(process.cwd(), this.program);
debugAliases = this.programs.map(function(program) {
return " alias " + program + "=" + fullPath;
}).join(os.EOL);
debugUnaliases = this.programs.map(function(program) {
return " unalias " + program;
}).join(os.EOL);
return "### test method ###\nomelette-debug-" + this.program + "() {\n" + debugAliases + "\n}\nomelette-nodebug-" + this.program + "() {\n" + debugUnaliases + "\n}\n### tests ###";
};
generateTestAliases() {
var debugAliases, debugUnaliases, fullPath;
fullPath = path.join(process.cwd(), this.program);
debugAliases = this.programs.map(function(program) {
return ` alias ${program}=${fullPath}`;
}).join(os.EOL);
debugUnaliases = this.programs.map(function(program) {
return ` unalias ${program}`;
}).join(os.EOL);
return `### test method ###\nomelette-debug-${this.program}() {\n${debugAliases}\n}\nomelette-nodebug-${this.program}() {\n${debugUnaliases}\n}\n### tests ###`;
}
Omelette.prototype.checkInstall = function() {
if (this.install) {
log(this.generateCompletionCode());
process.exit();
checkInstall() {
if (this.install) {
log(this.generateCompletionCode());
process.exit();
}
if (this.installFish) {
log(this.generateCompletionCodeFish());
return process.exit();
}
}
if (this.installFish) {
log(this.generateCompletionCodeFish());
return process.exit();
}
};
Omelette.prototype.getActiveShell = function() {
if (this.SHELL.match(/bash/)) {
return 'bash';
} else if (this.SHELL.match(/zsh/)) {
return 'zsh';
} else if (this.SHELL.match(/fish/)) {
return 'fish';
getActiveShell() {
if (this.SHELL.match(/bash/)) {
return 'bash';
} else if (this.SHELL.match(/zsh/)) {
return 'zsh';
} else if (this.SHELL.match(/fish/)) {
return 'fish';
}
}
};
Omelette.prototype.getDefaultShellInitFile = function() {
var fileAt, fileAtHome;
fileAt = function(root) {
return function(file) {
return path.join(root, file);
getDefaultShellInitFile() {
var fileAt, fileAtHome;
fileAt = function(root) {
return function(file) {
return path.join(root, file);
};
};
};
fileAtHome = fileAt(this.HOME);
switch (this.shell = this.getActiveShell()) {
case 'bash':
return fileAtHome('.bash_profile');
case 'zsh':
return fileAtHome('.zshrc');
case 'fish':
return fileAtHome('.config/fish/config.fish');
fileAtHome = fileAt(this.HOME);
switch (this.shell = this.getActiveShell()) {
case 'bash':
return fileAtHome('.bash_profile');
case 'zsh':
return fileAtHome('.zshrc');
case 'fish':
return fileAtHome('.config/fish/config.fish');
}
}
};
Omelette.prototype.setupShellInitFile = function(initFile) {
var completionPath, programFolder, template;
if (initFile == null) {
initFile = this.getDefaultShellInitFile();
}
template = (function(_this) {
return function(command) {
return "\n# begin " + _this.program + " completion\n" + command + "\n# end " + _this.program + " completion\n";
setupShellInitFile(initFile = this.getDefaultShellInitFile()) {
var completionPath, programFolder, template;
template = (command) => {
return `\n# begin ${this.program} completion\n${command}\n# end ${this.program} completion\n`;
};
})(this);
switch (this.shell) {
case 'bash':
programFolder = path.join(this.HOME, "." + this.program);
completionPath = path.join(programFolder, 'completion.sh');
if (!fs.existsSync(programFolder)) {
fs.mkdirSync(programFolder);
}
fs.writeFileSync(completionPath, this.generateCompletionCode());
fs.appendFileSync(initFile, template("source " + completionPath));
break;
case 'zsh':
fs.appendFileSync(initFile, template(". <(" + this.program + " --completion)"));
break;
case 'fish':
fs.appendFileSync(initFile, template(this.program + " --completion-fish | source"));
switch (this.shell) {
case 'bash':
programFolder = path.join(this.HOME, `.${this.program}`);
completionPath = path.join(programFolder, 'completion.sh');
if (!fs.existsSync(programFolder)) {
fs.mkdirSync(programFolder);
}
fs.writeFileSync(completionPath, this.generateCompletionCode());
fs.appendFileSync(initFile, template(`source ${completionPath}`));
break;
case 'zsh':
fs.appendFileSync(initFile, template(`. <(${this.program} --completion)`));
break;
case 'fish':
fs.appendFileSync(initFile, template(`${this.program} --completion-fish | source`));
}
return process.exit();
}
return process.exit();
};
Omelette.prototype.init = function() {
if (this.compgen > -1) {
return this.generate();
} else {
return this.mainProgram();
init() {
if (this.compgen > -1) {
return this.generate();
} else {
return this.mainProgram();
}
}
};
Omelette.prototype.on = function(event, handler) {
var isAsync;
Omelette.__super__.on.call(this, event, handler);
isAsync = handler.toString().match(/^async/);
if (isAsync) {
onAsync(event, handler) {
super.on(event, handler);
return this.asyncs += 1;
}
};
({log} = console);
return Omelette;
})(EventEmitter);
}).call(this);
module.exports = function() {
var _omelette, args, callback, callbacks, fn, fragment, fragments, i, index, len, program, ref, ref1, template;
template = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
module.exports = function(template, ...args) {
var _omelette, callback, callbacks, fragment, fragments, i, index, len, program;
if (template instanceof Array && args.length > 0) {
ref = [template[0].trim(), args], program = ref[0], callbacks = ref[1];
[program, callbacks] = [template[0].trim(), args];
fragments = callbacks.map(function(callback, index) {
return "arg" + index;
return `arg${index}`;
});
} else {
ref1 = template.split(/\s+/), program = ref1[0], fragments = 2 <= ref1.length ? slice.call(ref1, 1) : [];
[program, ...fragments] = template.split(/\s+/);
callbacks = [];

@@ -290,15 +272,12 @@ }

_omelette.setProgram(program);
_omelette.setFragments.apply(_omelette, fragments);
_omelette.setFragments(...fragments);
_omelette.checkInstall();
fn = function(callback) {
return _omelette.on(fragment, function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return this.reply(callback instanceof Array ? callback : callback.apply(null, args));
});
};
for (index = i = 0, len = callbacks.length; i < len; index = ++i) {
callback = callbacks[index];
fragment = "arg" + index;
fn(callback);
fragment = `arg${index}`;
(function(callback) {
return _omelette.on(fragment, function(...args) {
return this.reply(callback instanceof Array ? callback : callback(...args));
});
})(callback);
}

@@ -305,0 +284,0 @@ return _omelette;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc