ts-pair
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

ts-pair

Pair classes for TypeScript and JavaScript

Install

npm install ts-pair --save

Example

let pair = new Pair( 1, "Hello" );
console.log( pair.first, '', pair.second ); // 1, Hello
console.log( 'Pair is ' + pair ); // Pair is [ 1, Hello ]
 
pair.first = 2;
pair.second = "hi";
 
console.log( 'JSON', pair.toJSON() ); // Pair is { "first": 2, "second": "hi" }
 
let [ first, second ] = pair.toArray();
console.log( first, second ); // 2, hi
 
// chainable
console.log( pair.setFirst( 10 ).setSecond( "bye" ).toString() ); // [ 10, bye ]
 
let otherPair = new Pair( 20, "bye" );
console.log( otherPair.equals( pair ) ? 'equal': 'different' ); // different
 
let aImmutable = new ImmutablePair( 20, "bye" );
console.log( aImmutable.equals( otherPair ) ? 'equal': 'different' ); // equal
 
aImmutable.first = "baz"; // Error

Available Types

  • IPair interface, with getFirst(), getSecond(), equals(), toArray(), and toJSON()
  • AbstractPair that implements IPair and declares toString()
  • Pair that extends AbstractPair
  • ImmutablePair that extends AbstractPair

License

MIT © Thiago Delgado Pinto

Readme

Keywords

none

Package Sidebar

Install

npm i ts-pair

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

10.1 kB

Total Files

7

Last publish

Collaborators

  • thiagodp