JStructs
Structs for JavaScript, yay!!
A Ruby-like Struct factory for JavaScript
Installation
npm install jstructs [--save]
or
yarn install jstructs
Usage
const Struct = ;const Contact = ;const bob = 'Bob' 'bob@email.com' 7779311;const alice = 'Alice' 'alice@email.com' 8675309; alice; true // only compares properties alice; false // compares properties and values alice; 'Alice' 'alice@email.com' 8675309 bob; Bob bob@emailcom 7779311 alicelength; 3 alice; 'name' 'email' 'phone' bob; 'Bob' 'bob@email.com' 7779311 bob; 'Bob' 7779311 undefined bob; 'Bob' 7779311 // last value of true will remove falsey values alice; 8675309 alice; // returns arrays of key value pairs 'name' 'Alice' 'email' 'alice@email.com' 'phone' 8675309 bob; // creates a new object from key value pairs 'name': 'Bob' 'email': 'bob@email.com' 'phone': 8675309
Unlike Ruby Structs, you can pass in more arguments than there are properties.
const Struct = ;const Numbers = ;const numbers = 31415 271828 46692 16180 -27315 671 * Math; numbers; 31415 271828 46692 1618 -27315 671000000 numberscatchall; 1618 -27315 671000000
You must pass at least one argument.
const Struct = ;const fail = ; Error