Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/naridal/javasetmap.ts
Java-style Set and Map collections (on `{ hashCode(): int, equals(x: any): boolean}` objects) written in TypeScript.
https://github.com/naridal/javasetmap.ts
javascript map set typescript
Last synced: about 1 month ago
JSON representation
Java-style Set and Map collections (on `{ hashCode(): int, equals(x: any): boolean}` objects) written in TypeScript.
- Host: GitHub
- URL: https://github.com/naridal/javasetmap.ts
- Owner: NaridaL
- License: mit
- Created: 2017-09-02T13:08:18.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-02-11T00:21:59.000Z (almost 3 years ago)
- Last Synced: 2024-01-30T21:05:15.501Z (10 months ago)
- Topics: javascript, map, set, typescript
- Language: TypeScript
- Size: 94.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Travis](https://img.shields.io/travis/NaridaL/javasetmap.ts.svg?style=flat-square)](https://travis-ci.org/NaridaL/javasetmap.ts)
[![npm](https://img.shields.io/npm/v/javasetmap.ts.svg?style=flat-square)](https://www.npmjs.com/package/javasetmap.ts)
[![David](https://img.shields.io/david/expressjs/express.svg?style=flat-square)](https://david-dm.org/NaridaL/javasetmap.ts)# javasetmap.ts
Java-style Set and Map collections (on `{ hashCode(): int, equals(x: any): boolean}` objects) written in TypeScript.## Installation
NPM: `npm install javasetmap.ts --save`
In the browser, you can include the [UMD bundle](./dist/bundle.js) in a script tag, and the module will be available under the global `javasetmap_ts`
## Usage
```ts
import {JavaMap} from 'javasetmap.ts'
// node: const {JavaMap} = require('javasetmap.ts')
// browser: const {JavaMap} = nladeclare global { // remove this block if not using TypeScript
interface Array extends Equalable {}
interface Number extends Equalable {}
}
Array.prototype.equals = function (o) {
return this == o || this.length == o.length && this.every((el, i) => el.equals(o[i]))
}
Array.prototype.hashCode = function () {
return this.reduce((acc, current) => acc * 31 + current.hashCode(), 0)
}
Number.prototype.equals = function (o) { return this == o }
Number.prototype.hashCode = function () { return this | 0 }const myMap = new JavaMap<[number, number], string>() // new JavaMap() if not using TypeScript
myMap.set([1, 2], "foo")
myMap.has([1, 2]) // === true
myMap.get([1, 2]) // === "foo"
myMap.has([1, 3]) // === false
myMap.get([2, 1]) // === undefined
```LICENSE
MIT