Skip to content

Commit

Permalink
Merge pull request #4 from brutalchrist/update_doc
Browse files Browse the repository at this point in the history
Update doc
  • Loading branch information
brutalchrist committed Sep 28, 2018
2 parents 396a184 + e4ccc4e commit 2ba7f6a
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 4 deletions.
195 changes: 193 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,198 @@

An HashTable for Angular

## Use
## API

### `put(key: K, value: V): HashTable<K, V>`
```typescript
const table = new HashTable<string, any>();

table.put('hi', {
msg: 'Hello World',
from: '🛸'
});
```

### `get(key: V): V`
```typescript
const table = new HashTable<string, any>();

table.put('hi', {
msg: 'Hello World',
from: '🛸'
});

// {msg: "Hello World", emoji: "🛸"}
console.log(table.get('hi'));
```

### `getAll(): V[]`
```typescript
const table = new HashTable<string, any>();

table.put('hi', {
msg: 'Hello World',
from: '🛸'
});

// [0: {msg: "Hello World", emoji: "🛸"}]
console.log(table.getAll());
```

### `getKeys(): string[]`
```typescript
const table = new HashTable<string, any>();

table.put('hi', {
msg: 'Hello World',
from: '🛸'
});

// ['hi']
console.log(table.getKeys());
```

### `has(key: K): boolean`
```typescript
const table = new HashTable<string, any>();

table.put('hi', {
msg: 'Hello World',
from: '🛸'
});

// true
console.log(table.has('hi'));
```

### `remove(key: K): HashTable<K, V>`
```typescript
const table = new HashTable<string, any>();

table.put('hi', {
msg: 'Hello World',
from: '🛸'
});
table.remove('hi');

// []
console.log(this.table.getAll());
```

### `putArray(key: K, value: V): HashTable<K, V>`
```typescript
const table = new HashTable<string, any>();

table.putArray('hi', {
msg: 'Hello World',
from: '🛸'
});

table.putArray('hi', {
msg: 'Hello Space',
from: '🌎'
});
```

### `getArray(key: K): V`
```typescript
const table = new HashTable<string, any>();

table.putArray('hi', {
msg: 'Hello World',
from: '🛸'
});

table.putArray('hi', {
msg: 'Hello Space',
from: '🌎'
});

// [
// 0: {msg: "Hello World", emoji: "🛸"}
// 1: {msg: "Hello Space", emoji: "🌍"}
// ]
console.log(this.table.getArray('hi'));
```

### `removeArray(key: K, value: V): HashTable<K, V>`
```typescript
const table = new HashTable<string, any>();

table.putArray('hi', {
msg: 'Hello World',
from: '🛸'
});

table.putArray('hi', {
msg: 'Hello Space',
from: '🌎'
});

table.remove('hi', 0);

// [0: {msg: "Hello Space", emoji: "🌍"}]
console.log(this.table.getArray('hi'));
```

### `hasArray(key: K): boolean`
```typescript
const table = new HashTable<string, any>();

table.putArray('hi', {
msg: 'Hello World',
from: '🛸'
});

// true
console.log(this.table.hasArray('hi'));
```

### `hasinArray(key: K, value: V): boolean`

### `size(): number`
```typescript
const table = new HashTable<string, any>();

table.put('hi', {
msg: 'Hello World',
from: '🛸'
});

// 1
console.log(this.table.size());
```

### `forEach(callback): void`
```typescript
const table = new HashTable<string, any>();

table.put('hi', {
msg: 'Hello World',
emoji: '🛸'
});

table.putArray('bye', {
msg: 'Bye World',
emoji: '🛸'
});

table.putArray('bye', {
msg: 'Bye Space',
emoji: '🌎'
});

// hi => : {msg: "Hello World", emoji: "🛸"}
// bye => : [
// 0: {msg: "Bye World", emoji: "🛸"}
// 1: {msg: "Bye Space", emoji: "🌎"}
// ]
table.forEach((key, value) => {
console.log(`${key} => :`, value);
});
```

## Example

```typescript
import { Component } from '@angular/core';
Expand All @@ -21,7 +212,7 @@ export class AppComponent {
this.table = new HashTable<string, any>();
this.table.put('hi', {
msg: 'Hello World',
emoji: '🛸'
from: '🛸'
});

if (this.table.has('hi')) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-hashtable",
"version": "0.0.8",
"version": "0.0.9",
"description": "An HashTable for Angular",
"main": "./dist/angular-hashtable/bundles/angular-hashtable.umd.js",
"typings": "./dist/angular-hashtable.d.ts",
Expand Down
1 change: 0 additions & 1 deletion src/lib/angular-hashtable.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
export class HashTable<T, L> {
private table: any;
private id: string;

constructor() {
this.table = {};
Expand Down

0 comments on commit 2ba7f6a

Please sign in to comment.