
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
A module for creating n-dimensional vector types that support swizzling.
Allows for the creation of vectors of arbitrary dimension that are also JavaScript Arrays
. These arrays are fixed-length and accept only numbers as input, though they generally decay gracefully into regular Arrays
. For example, you're allowed to use map
, reduce
, concat
, and other Array
methods, and if the result is a valid vec
, a vec
will be returned. Otherwise, you'll get back a standard Array
with the new elements. These are specifically overloaded methods, so experimental, custom, and rebound methods aren't guaranteed to work.
$ npm install vecn
Since they're the most common, vec2
, vec3
, and vec4
are already included:
const {vec3} = require('vecn')
let v = vec3(1, 2, 3)
console.log(v)
[ 1, 2, 3 ]
If you need to create your own vector type:
const vecn = require('vecn')
const vec5 = vecn.getVecType(5)
var v = vec5(1, 2, 3, 4, 5)
console.log(v)
[ 1, 2, 3, 4, 5 ]
For a more in-depth description of available vector methods, see the documentation.
Swizzling is a technique used in GLSL that allows you to access a vector's components by name and build new vectors from them. It works the same here at arbitrary length. It's easiest to see in an example:
var v = vec4(1, 2, 3, 4)
v.x // 1
v.y // 2
v.z // 3
v.w // 4
v.xx // vec2 [ 1, 1 ]
v.zy // vec2 [ 3, 2 ]
v.zywwxyyz // vec8 [ 3, 2, 4, 4, 1, 2, 2, 3 ]
We can also set values with swizzling.
var v = vec3(1, 2, 3)
v.xz = [4, 5]
console.log(v)
[ 4, 2, 5 ]
Swizzling only works for vec2
, vec3
, and vec4
(with plans to extend it with custom accessors).
When creating a new vecType, you are generating a new class. However, this class is hidden behind a function that creates the object for you and returns a Proxy. Therefore, the function returned by vecn.getVecType
is not a constructor. Since the new
keyword implies a return this
at the end of the function, but the function already returns, the existence of a new
before the function call has no effect. The following code explains the importance:
const vec2 = vecn.getVecType(2)
var v1 = vec2(1, 2) // Valid construction
var v2 = new vec2(1, 2) // Also valid, but misleading
v1.constructor === vec2 // false
Basically this allows for swizzling and lets me extend Array
without letting the user mess with the length.
FAQs
A module for creating n-dimensional vector types that support swizzling.
The npm package vecn receives a total of 708 weekly downloads. As such, vecn popularity was classified as not popular.
We found that vecn 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.