# @wranggle/storage-key-name-layer

> WranggleStorage feature layer adding key prefixes to create separate namespaces to any data store

Latest version **0.2.4** (published 2019-03-22) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @wranggle/storage-key-name-layer
pnpm add @wranggle/storage-key-name-layer
yarn add @wranggle/storage-key-name-layer
bun add @wranggle/storage-key-name-layer
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2019-03-22 |
| First published | 2019-03-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 44.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jeff Ferber |
| Maintainers | wranggle.ferbs |
| Keywords | wranggle-storage, storage, persistence, middleware, storage-feature-layer |

## Links

- npm: https://www.npmjs.com/package/@wranggle/storage-key-name-layer
- Repository: https://github.com/wranggle/storage
- Issues: https://github.com/wranggle/storage/issues
- npm.io page: https://npm.io/package/@wranggle/storage-key-name-layer

## Dependencies (3)

- [lodash.endswith](https://npm.io/package/lodash.endswith.md) ^4.2.1
- [lodash.startswith](https://npm.io/package/lodash.startswith.md) ^4.2.1
- [@wranggle/storage-core](https://npm.io/package/@wranggle/storage-core.md) ^0.2.4

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.2.4 (latest) — 2019-03-22
- 0.2.3 — 2019-03-21
- 0.2.2 — 2019-03-19
- 0.2.1 — 2019-03-19

## README

# KeyNameLayer

*KeyNameLayer* is a [WranggleStorage](https://github.com/wranggle/storage) feature layer that adds a prefix to each key, effectively imposing an isolated namespace on the store.

For example, we construct two stores in different namespaces:
```javascript
const eastStore = new WranggleStorage({ bucket: 'Region:east' })
const westStore = new WranggleStorage({ bucket: 'Region:west' })
```

Each store can get/set items in isolation, even with the same key:

```javascript
await eastStore.set({ lunch: 'philly' })
await westStore.set({ lunch: 'burrito' })
```
The underlying store will now have two items set without conflict, with keys: `Region:east/lunch` and `Region:west/lunch`.


## Applying the feature

When constructing your WranggleStorage instance, use the `bucket` keyword to add the feature:
```javascript
const store = new WranggleStorage({ bucket: 'SomeNamespace' }); 
```

You can also supply an options object, should you want to supply it with secondary/advanced options.


## Options 

Primary option:
* **bucket** *string* prefix to prepend to keys. The `bucketDelimeter` option will be added. 


Secondary/advanced options:
* **bucketDelimeter** *string* added to **bucket** value when provided. Default is "/". 

* **prefix** *string* prepended to keys. Similar to *bucket* but `bucketDelimeter` is not added. 

* **suffix** *string* appended to keys. Use is discouraged! (Because the ExpirationLayer uses a suffix and if this layer does so too, layer order can no longer be ignored.)


## Installing From Individual Packages

The *KeyNameLayer* is included in the [@wranggle/storage-web](https://github.com/wranggle/storage-web-full) and [@wranggle/storage-node](https://github.com/wranggle/storage-node-full) bundles. 

Or you can add/install the individual package, alongside [@wranggle/storage-core](https://github.com/wranggle/storage-core) and a persistence adapter:

1. Add the [@wranggle/storage-key-name-layer](https://www.npmjs.com/package/@wranggle/storage-key-name-layer) package to your project:
    ```bash
    # From the command line using yarn:
    yarn add @wranggle/storage-key-name-layer
    
    # or with npm:
    npm install @wranggle/storage-key-name-layer
    ```

1. In your JavaScript, import or require the packages: 
    ```javascript
    import KeyNameLayer from '@wranggle/storage-key-name-layer'
    // or:
    const KeyNameLayer = require('@wranggle/storage-key-name-layer')
    ```

1. Instantiate your store:
    ```javascript
    const store = new WranggleStorage({ expire: myDuration });
    ```
    Or do so without the construction shortcut:
    ```javascript
    const store = new WranggleStorage({ persist: new KeyNameLayer({ duration: myDuration }));
    ```

---
_Source: https://npm.io/package/@wranggle/storage-key-name-layer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
