https://github.com/thomscoder/timber-deno
Find strings in large arrays fast. A simple Deno module that aims to handle large datasets
https://github.com/thomscoder/timber-deno
Last synced: 3 months ago
JSON representation
Find strings in large arrays fast. A simple Deno module that aims to handle large datasets
- Host: GitHub
- URL: https://github.com/thomscoder/timber-deno
- Owner: thomscoder
- Created: 2022-06-25T13:52:09.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-25T14:41:27.000Z (over 3 years ago)
- Last Synced: 2023-08-08T20:44:38.658Z (over 2 years ago)
- Language: TypeScript
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TimberJS for Deno 🍃
Find strings in large arrays fast.
Timber implements a Prefix Tree under the hood and allows a fast string search in hundred thousands of entries.
Import
```javascript
// Either...
import { Timber } from "https://deno.land/x/timberjs@timber/mod.ts";
// or...
import { Timber } from "https://raw.githubusercontent.com/thomscoder/timber-deno/master/mod.ts"
```
Usage
```javascript
// Import timber
import { Timber } from "https://deno.land/x/timberjs@timber/mod.ts";
// Random names generator
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
const arr = Array.from({length: 100}, () => {
const randomName = faker.name.firstName();
return randomName;
});
const timber = new Timber();
// Insert an entire array...
timber.insert(arr);
// ...or a single string passing an identifier (e.g. the variable that contains that value or a category)
timber.insert("imaginary", "Voldemort");
// Find the word
timber.search("Voldemort"); // Voldemort
// Find all words that start with given Prefix
timber.findAllWords("Vold"); // ["Voldemort", ...]
// Get the identifier
timber.belongsTo("Voldemort"); // ["imaginary"]
// Delete a word
timber.delete("Voldemort");
```
Follow the ./main.ts or the ./tests/test.ts files to see some examples