
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@scuba-squad/type-array
Advanced tools
TypeArray is a Proxy allowing you to define validation of values that may be set
TypeArray class definition
Via npm
npm install @scuba-squad/type-array
TypeArray(validator: function | string | RegExp | Array, message?: string | null)
Added in: v1.0.0
Factory method to get a function to create a Typed|Validated Array
arguments:
validator: function | string | RegExp | Array
message: string | null = 'invalid value'
returns: Function
throws: TypeError
const TypeArray = require('@scuba-squad/type-array');
const NumberArray = TypeArray((value) => {
return typeof value === 'number';
});
const test = NumberArray(1, 5.4, -9);
console.log(test.length); // 3
console.log(test[0]); // 1
test.push(0); // 4
console.log(test[3]); // 0
test.shift(); // 3
console.log(test[0]); // 5.4
test.push('5'); // TypeError: invalid value
const TypeArray = require('@scuba-squad/type-array');
const NumberArray = TypeArray('isFloat');
const test = NumberArray(1, 5.4, -9);
console.log(test.length); // 3
console.log(test[0]); // 1
test.push(0); // 4
console.log(test[3]); // 0
test.shift(); // 3
console.log(test[0]); // 5.4
test.push('5'); // 4 (value is castable to float so passes isFloat validation)
test.push('asd'); // TypeError: invalid value
const TypeArray = require('@scuba-squad/type-array');
const NumberArray = TypeArray(/^-?\d+(?:\.\d+)?$/);
const test = NumberArray(1, 5.4, -9);
console.log(test.length); // 3
console.log(test[0]); // 1
test.push(0); // 4
console.log(test[3]); // 0
test.shift(); // 3
console.log(test[0]); // 5.4
test.push('5'); // 4 (value passes validation)
test.push('asd'); // TypeError: invalid value
const TypeArray = require('@scuba-squad/type-array');
const NumberArray = TypeArray(['isFloat', {min: -10, max: 10}]);
const test = NumberArray(1, 5.4, -9);
console.log(test.length); // 3
console.log(test[0]); // 1
test.push(0); // 4
console.log(test[3]); // 0
test.shift(); // 3
console.log(test[0]); // 5.4
test.push('5'); // 4 (value is castable to float so passes isFloat validation)
test.push(11); // TypeError: invalid value
TypeArray.ErrorArray(...args: Error)
Added in: v1.0.0
Function to create a predefined ErrorArray
arguments:
...args: Error
returns: Array
throws: TypeError
const {ErrorArray} = require('@scuba-squad/type-array');
const test = ErrorArray(new Error('a'));
console.log(test.length); // 1
console.log(test[0]); // Error: a
test.push(new TypeError('invalid'));
console.log(test[1]); // TypeError: invalid
test.push('hello'); // TypeError: value must be an Error
TypeArray.FunctionArray(...args: Function)
Added in: v1.0.0
Function to create a predefined FunctionArray
arguments:
...args: Function
returns: Array
throws: TypeError
const {FunctionArray} = require('@scuba-squad/type-array');
const test = FunctionArray(Number);
console.log(test.length); // 1
console.log(test[0]); // [Function: Number]
test.push(() => {});
console.log(test[1]); // [Function]
test.push('hello'); // TypeError: value must be a Function
TypeArray.PromiseArray(...args: Promise)
Added in: v1.0.0
Function to create a predefined PromiseArray
arguments:
...args: Promise
returns: Array
throws: TypeError
const {PromiseArray} = require('@scuba-squad/type-array');
const test = PromiseArray(Promise.resolve(5));
console.log(test.length); // 1
console.log(test[0]); // Promise { 5 }
test.push(Promise.reject('fail'));
console.log(test[1]); // Promise { <rejected> 'fail' }
test.push('hello'); // TypeError: value must be a Promise
npm install
npm test
FAQs
TypeArray is a Proxy allowing you to define validation of values that may be set
We found that @scuba-squad/type-array 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.