Skip to content

Commit

Permalink
Update Typescript types to include import and export (#99)
Browse files Browse the repository at this point in the history
* Update types

* Fix export description

* Fixed documentation description of the export method
  • Loading branch information
strenkml committed Sep 23, 2022
1 parent 4414057 commit e7b94df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/api-docs.md
Expand Up @@ -507,7 +507,7 @@ enmap.remove('objectarray', (value) => value.e === 5); // value is now [{ a: 1,
<a name="Enmap+export"></a>

### enmap.export() ⇒ <code>string</code>
Exports the enmap data to a JSON file.
Exports the enmap data to stringified JSON format.
**__WARNING__**: Does not work on memory enmaps containing complex data!

**Kind**: instance method of [<code>Enmap</code>](#enmap-map)
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Expand Up @@ -156,15 +156,15 @@ class Enmap extends Map {
this.#db = new Database(':memory:', { verbose: this.#verbose });
this.#name = 'MemoryEnmap';
}

if (this.#polling) {
process.emitWarning(
'Polling features will be removed in Enmap v6. If you need enmap in multiple processes, please consider moving to JOSH, https://josh.evie.dev/',
);
}
// Initialize this property, to prepare for a possible destroy() call.
// This is completely ignored in all situations except destroying the enmap.
);
}

// Initialize this property, to prepare for a possible destroy() call.
// This is completely ignored in all situations except destroying the enmap.
this.#validateName();
this.#isDestroyed = false;
this.#init(this.#db);
Expand Down Expand Up @@ -820,7 +820,7 @@ class Enmap extends Map {
}

/**
* Exports the enmap data to a JSON file.
* Exports the enmap data to stringified JSON format.
* **__WARNING__**: Does not work on memory enmaps containing complex data!
* @returns {string} The enmap data in a stringified JSON format.
*/
Expand Down
15 changes: 15 additions & 0 deletions typings/index.d.ts
Expand Up @@ -475,6 +475,21 @@ declare module 'enmap' {
*/
public removeFrom(key: K, path: string, val: any): this;

/**
* Exports the enmap data to stringified JSON format. WARNING: Does not work on memory enmaps containing complex data!
* @returns The enmap data in a stringified JSON format.
*/
public export(): string;

/**
* Import an existing json export from enmap from a string. This data must have been exported from enmap, and must be from a version that's equivalent or lower than where you're importing it.
* @param data The data to import to Enmap. Must contain all the required fields provided by export()
* @param overwrite Defaults to true. Whether to overwrite existing key/value data with incoming imported data
* @param clear Defaults to false. Whether to clear the enmap of all data before importing (WARNING: Any exiting data will be lost! This cannot be undone.)
* @returns The enmap.
*/
public import(data: string, overwrite?: boolean, clear?: boolean): this;

/**
* Initialize multiple Enmaps easily.
* @param names Array of strings. Each array entry will create a separate enmap with that name.
Expand Down

0 comments on commit e7b94df

Please sign in to comment.