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.
convert javascript object to numerical 1-D array (vector) representation
Jotun is the (anglicized) term used to describe the race of Giants living in Jotunheimr, one of the nine worlds in Norse mythology.
In this case it also means Javascript Objects To Numbers (however jotn
sounded stupid and was only one u
away from keeping in line with all the other norse-themed repositories I have).
Why on Midgard would you want to turn objects into vectors?
Pretty much that's it, but you can also use it for serialization purposes, or even create ArrayBuffer
s to be used in TypedArray
s so you can use DataView
s?
Simple enough:
let jotun = require('jotun'),
convert = jotun.converter();
let vector = convert({ foo: 'bar', quux: [2, 3, 4]});
// print [3, 2, 3, 4]
jotun
will turn your objects into vectors with default converters following this behaviour:
The final resulting array will be flattened.
You may want to cater for special cases, like NaN or Infinity or undefined.
You can specify a map which defines the conversion behaviour. All you need to do is associate a conversion function for the object property. For instance, example/example.es6.js
includes a conversion of text into bag-of-words vector representation:
let jotun = require('../index'),
mimir = require('mimir');
let list = [{
name: 'joe',
age: 40,
dob: new Date(1975, 1, 28),
description: 'a javascript programmer that loves heavy metal',
contractor: true,
code: {
languages: ['javascript', 'java', 'c++'],
foo: 'bar'
}
}, {
name: 'jack',
age: 25,
dob: new Date(1990, 2, 20),
description: 'an ios programmer that pretends to like jazz',
contractor: false,
code: {
languages: ['objective-c', 'some other hipsteria language', 'ruby'],
foo: 'bar'
}
}];
let dict = mimir.dict(list.map(o => o.description));
let convert = jotun.converter({
description: description => mimir.bow(description, dict),
code: jotun.converter({})
});
FAQs
convert objects to number arrays
We found that jotun 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.