Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update doc #4

Merged
merged 3 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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