
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@caliatys/array-typer
Advanced tools
A Node.js module that create an array or dictionnary of generic type object from an array of Object
npm install @caliatys/array-typer --save
// Let's create our own object type
let MyObject = /** @class */ (function () {
function MyObject(obj) {
// Simple object with one property...
this.private_prop = obj.prop;
}
// ...and one getter method
Object.defineProperty(MyObject.prototype, "prop", {
get: function () { return this.private_prop; },
enumerable: true,
configurable: true
});
return MyObject;
}());
let ArrayTyper = require('@caliatys/array-typer').ArrayTyper;
// Let's create an array of untyped object
let untypedArray = [{"prop": 1},{"prop": 2}];
// And type its elemetns
let typedArray = ArrayTyper.asArray(MyObject, untypedArray);
// Each element of the array are typed, so we can now call its methods
for (let typedObj of typedArray)
console.log(typedObj.prop) // 1 & 2
We can also send the array as a json
let untypedArray = '[{"prop": 1},{"prop": 2}]';
let typedArray = ArrayTyper.asArray(MyObject, untypedArray);
for (let typedObj of typedArray)
console.log(typedObj.prop);
//Print
// 1
// 2
Additional arguments can be sent to the constructor
let typedArray = ArrayTyper.asArray(MyObject, untypedArray, 'several', 'additional', 'arguments');
These arguments are accessed in MyObject constructor like this
function MyObject(obj) {
this.private_prop = obj.prop;
let additionalArguments = arguments[1];
for (let arg of additionalArguments)
console.log(arg);
}
//Print
// several
// additional
// arguments
If you'd rather want a dictionnary, you can use asDict providing a function to generate the key
let untypedArray = [{"prop": 1},{"prop": 2}];
let typedDict = ArrayTyper.asDict(MyObject, untypedArray, t => ""+t.prop); //Using stringified MyObject.prop as key
// typedDict structure
// [
// "1": {"prop": 1},
// "2": {"prop": 2}
// ]
Of course, json and additionnal arguments are accepted
let untypedArray = '[{"prop": 1},{"prop": 2}]';
let typedDict = ArrayTyper.asDict(MyObject, untypedArray, t => ""+t.prop, 'several', 'additional', 'arguments');
class MyObject
{
private _prop : number = -1;
public get prop() {return this._prop};
constructor(obj: {})
{
this._prop = obj.prop;
}
}
The module can be used in Typescript
import { ArrayTyper } from '@caliatys/array-typer';
let untypedArray = '[{"prop": 1},{"prop": 2}]';
let typedArray : MyObject[] = ArrayTyper.asArray(MyObject, untypedArray);
npm run test
FAQs
Create an array or dictionnary of generic type object
We found that @caliatys/array-typer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.