
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Or in short "DTA". Is a library to map arguments by type or prototype.
You are able to use this module in Node.js and in your browser as global-function or as amd-module. You can fetch this module using npm or Bower.
You can get the package with:
npm install dta
After that you are able to load this module the common node.js way:
var dta = require('dta');
You can get the package with:
bower install dta
git clone https://github.com/atd-schubert/dta.git
wget https://github.com/atd-schubert/dta/archive/master.zip
If you are not using AMD, you have to add a script-tag with the dta.js
as src attribute.
If you are using AMD, you have to put the dta.js file into your scripts
folder, or edit your shim-config accordingly and require this module
with require(['dta'], function (dta) { /* now you have the dta-function available in this scope... */ }).
The main idea behind DTA is to pass the arguments variable of any function to DTA and get an object of arguments by type, so you are not forced to give your function parameters an order.
Adopted you have a function where you want to request an url, it is not necessary if you want to do this with an ajax
call, or with a function called request in node, you can do this the following way:
// you have already loaded DTA with one of the above described methods.
var getContent;
getContent = function getContent() {
var params, opts;
opts = {};
params = dta({
string: 'url',
number: 'timeout',
function: 'callback'
}, arguments);
if (params.timeout) {
opts.timeout = params.timeout;
}
if (!params.url) {
throw new Error('You have to specify an url');
}
if (!params.callback) {
throw new Error('You have to specify a callback');
}
request(params.url, opts, params.callback);
};
Now the order of your parameters in getContent is not necessary any more.
But DTA is also able to get mandatory parameters:
// you have already loaded DTA with one of the above described methods.
var getContent;
getContent = function getContent() {
var params, opts;
opts = {};
params = dta({
mandatory: ['url', 'callback'],
string: 'url',
number: 'timeout',
function: 'callback'
}, arguments);
if (params.timeout) {
opts.timeout = params.timeout;
}
request(params.url, opts, params.callback);
};
DTA can handle multiple arguments of the same type:
// you have already loaded DTA with one of the above described methods.
var sayHello;
sayHello = function sayHello() {
var params;
params = dta({
mandatory: 'firstName',
string: ['firstName', 'surname']
}, arguments);
if (!params.surname) {
return 'Hi ' + params.firstName;
}
return 'Hello ' + params.firstName + params.surname;
};
If you have unspecific number of parameters of a type you are able to handle it this way:
// you have already loaded DTA with one of the above described methods.
var factorize;
factorize = function factorize() {
var params, i, result;
params = dta({
mandatory: 'factor',
number: '[factor]'
}, arguments);
result = params.factor[0];
for (i = 1; i < params.factor.length; i += 1) {
result *= params.factor[i];
}
return result;
};
booleannumberstringfunctionobjectarrayerrorregExpargumentDTA is also able to handle your own types. You have to define your prototypes in an object to give them a name and map them the default way:
// you have already loaded DTA with one of the above described methods.
var anyFunction, myOwnClass;
myOwnClass = function () {
// Your class logic
}
anyFunction = function anyFunction() {
var params;
params = dta({
prototypes: {
own: myOwnClass
},
own: 'own',
// [...]
}, arguments);
// do something with params.own
};
anyFunction(new myOwnClass());
No, you are also able to use DTA with normal arrays!
You can also use dta to create a function (with thanks to Andreas for this idea!)
// you have already loaded DTA with one of the above described methods.
var factorize;
factorize = dta({
mandatory: 'factor',
number: '[factor]'
}, function factorize(params) {
var i, result;
result = params.factor[0];
for (i = 1; i < params.factor.length; i += 1) {
result *= params.factor[i];
}
return result;
});
The order of the two arguments in DTA is not compulsory. If you want you can pass arguments first.
// you have already loaded DTA with one of the above described methods.
var factorize;
factorize = function factorize() {
var params, i, result;
params = dta(arguments, {
mandatory: 'factor',
number: '[factor]'
});
result = params.factor[0];
for (i = 1; i < params.factor.length; i += 1) {
result *= params.factor[i];
}
return result;
};
FAQs
Dynamically typed arguments for javascript
The npm package dta receives a total of 4 weekly downloads. As such, dta popularity was classified as not popular.
We found that dta 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.