Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Factory Module Definition a simple factory module wrapper (Node, AMD, Browser, ...).
Requirements:
npm install fmd
var Fmd = require("fmd");
require("fmd")({
target: "dist/lib",
trim_whitespace: true,
new_line: "unix",
indent: 2
})
.vendor("bar", "Bar")
.define("foo", ["source/foo.js"], {
depends: {
"bar": "Baz"
},
exports: "Foo",
global: "Foo"
})
.build();
Files:
Input: "source/foo.js"
function Foo () {
}
Foo.prototype = new Baz();
Foo.prototype.qux = "foo";
Foo.prototype.bar = function () {
};
Foo.prototype.baz = function () {
};
Output: "dist/lib/foo.js"
;(function (root, factory) {
if (typeof exports === "object") {
// CommonJS
module.exports = exports = factory(require("bar"));
}
else if (typeof define === "function" && define.amd) {
// AMD
define(["bar"], factory);
}
else {
// Global (browser)
root.Foo = factory(root.Bar);
}
}(this, function (Baz) {
function Foo () {
}
Foo.prototype = new Baz();
Foo.prototype.qux = "foo";
Foo.prototype.bar = function () {
};
Foo.prototype.baz = function () {
};
return Foo;
}));
var fmd = require("fmd")(settings);
["commonjs", "amd", "global"]
null
"unix"
, "mac"
, "windows"
, "\n"
, "\r"
, "\r\n"
(null: don't change) Default: null
"\t"
, " "
, 1
, 2,
3, ...
(null: don't add indent, number: count of spaces) Default: null
null
Factory adds a "Factory Module Definition" handle.
Predefined: commonjs
, amd
and global
.
.factory( name, when, define )
fmd
.factory("commonjs", function () {
return "typeof exports === \"object\""
}, function () {
var depends = [],
requires = this.getModule().require;
// Compose dependencies
_.each(requires, function (require) {
depends.push("require(\"" + require + "\")");
});
return "// CommonJS\nmodule.exports = exports = " + this.factory() + "(" + depends.join(", ") + ");";
});
// Or multiple factory definition
fmd
.factory({
"commonjs": [
function () {
return "typeof exports === \"object\""
},
function () {
var depends = [],
requires = this.getModule().require;
// Compose dependencies
_.each(requires, function (require) {
depends.push("require(\"" + require + "\")");
});
return "// CommonJS\nmodule.exports = exports = " + this.factory() + "(" + depends.join(", ") + ");";
}
]
});
Vendor doesn't create/build files, it adds just the ability to inherit (especially for global mode) from modules I don't want to create/build by my self.
.vendor( module [, global] )
fmd
.vendor("foo", "Foo");
.vendor("foo/bar", "FooBar");
// Or multiple vendor definition
fmd
.vendor({
"foo": ["Foo"],
"foo/bar": ["FooBar"]
});
Import loads/copies modules which include a definiton already.
.import( module, sources [, global] [, concat(source1, sourceN)] )
fmd
.import("foo/bar", ["http://example.com/foo/bar.js", "/soruces/foo/bar-extension.js"], "FooBar", function (base, ext) {
return base + "\n\n/* Special extension */\n\n" + ext;
})
.import("foo", ["/soruces/foo.js"], "Foo")
.import("bar", ["/soruces/bar.js"]);
// Or multiple import
fmd
.import({
"foo/bar": [
["http://example.com/foo/bar.js", "/soruces/foo/bar-extension.js"],
"FooBar",
function (base, ext) {
return base + "\n\n/* Special extension */\n\n" + ext;
}
],
"foo": [
["/soruces/foo.js"],
"Foo"
],
"bar", [
["/soruces/bar.js"]
]
});
Define loads/copies scripts and wraps them in a factory module definition.
.define( module, sources, options [, concat] )
fmd
.define("bar", ["/soruces/bar.js"], {
exports: "Bar",
global: "Bar"
})
.define("foo", ["/soruces/foo.js"], "Foo", {
exports: "Foo",
global: "Foo"
})
.define("foo/bar", ["http://example.com/foo/bar.js", "/soruces/foo/bar-extension.js"], {
depends: {
"foo": "Foo",
"bar": "Bar"
},
exports: "FooBar",
global: "FooBar"
}, function (base, ext) {
return base + "\n\n/* Speciale extension */\n\n" + ext;
});
// Or multiple define
fmd
.define({
"bar": [
["/soruces/bar.js"],
{
exports: "Bar",
global: "Bar"
}
],
"foo": [
["/soruces/foo.js"],
{
exports: "Foo",
global: "Foo"
}
],
"foo/bar": [
["http://example.com/foo/bar.js", "/soruces/foo/bar-extension.js"],
{
depends: {
"foo": "Foo",
"bar": "Bar"
},
exports: "FooBar",
global: "FooBar"
},
function (base, ext) {
return base + "\n\n/* Speciale extension */\n\n" + ext;
}
]
});
Build starts the (async) process of creating defined modules and copying imported modules.
.build( [callback(createdFiles)] )
fmd
.build(function (createdFiles) {
// Log the list of created files
console.log(createdFiles);
});
FAQs
Factory Module Definition a simple factory module wrapper (Node, AMD, Browser, ...).
The npm package fmd receives a total of 9 weekly downloads. As such, fmd popularity was classified as not popular.
We found that fmd demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.