Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@allnulled/commandir
Advanced tools
Commandir pattern allows to scale command pattern with directories or URLs. Nodejs or browser.
Commandir pattern allows to scale command pattern with directories or URLs. Nodejs or browser.
npm install -s @allnulled/commandir
In node.js:
require("@allnulled/commandir");
In html:
<script src="node_modules/@allnulled/commandir/commandir.js"></script>
In node.js:
const commandir = Commandir.nodejs(__dirname + "/commands");
In browser:
const commandir = Commandir.browser("https://github.com/allnulled/path/to/file/raw");
The browser
mode, which in fact means AJAX mode, is allowed in node.js too as it only uses fetch
.
Then, in any:
commandir.execute("path/to/command.js", {
parameter1: 1,
parameter2: 2,
parameter3: 3
});
You can, then, list()
, register(name, callback)
and unregister(name)
:
console.log(commandir.list());
commandir.register("salute", () => console.log("hi!"));
commandir.execute("salute");
commandir.unregister("salute");
module.exports
and __dirname
exist in both environments.The only difference is that __dirname
in browsers points to the URL of the script. But module.exports
and return
can be used in browser
mode to return a module from the file.
register
receive different parametersIn browser, register(name, url)
. In node.js, register(name, callback)
.
register
and unregister
work differentlyIn browser, they just associate a label with a URL. In node.js, they write a file in the filesystem with the callback provided as second parameter, and remove it on unregister
.
list
cannot work in browserBecause directories in the web do not list by default, the method list
is still not provided with a polyfill.
Names have a process of validation and transformation before they get registered. They rewrite the .js
at the end, and forbid ..
just in case.
For now, I think it is all.
This is the example that the test uses. It is cross-environment but because we discriminated.
let basedir = ".";
const isNodejs = typeof global !== "undefined";
const main = async function () {
if (isNodejs) {
require(__dirname + "/../commandir.js");
basedir = __dirname;
}
if (isNodejs) {
const commandir = Commandir.nodejs(basedir + "/commands");
commandir.execute("/hello", {
dest: "world"
});
commandir.register("/goodbye", function (parameters) {
console.log(`Goodbye, ${parameters.dest}!`);
});
commandir.execute("/goodbye", { dest: "world" });
commandir.unregister("/goodbye");
console.log(commandir.list(""));
} else {
const commandir = Commandir.browser("/test/commands");
await commandir.register("hello", "./commands/hello.js");
await commandir.execute("hello", { dest: "world" });
}
};
main();
FAQs
Commandir pattern allows to scale command pattern with directories or URLs. Nodejs or browser.
We found that @allnulled/commandir demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.