An open API service indexing awesome lists of open source software.

https://github.com/neuledge/sort-key

🔑 Tiny library for generating safe sort keys for DynamoDB.
https://github.com/neuledge/sort-key

aws dynamodb sortkey

Last synced: 9 months ago
JSON representation

🔑 Tiny library for generating safe sort keys for DynamoDB.

Awesome Lists containing this project

README

          

🔑 Sort-Key

Tiny library for generating safe sort keys for DynamoDB.



View On NPM


Build Status


Dependency Status


Coverage Status


License



Generating DynamoDB sort keys from multiple string parts as [recommended by
AWS](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-sort-keys.html). It uses
`#` as separator and knows how to escape it when given on one of the key parts.

```
[country]#[region]#[state]#[county]#[city]#[neighborhood]
```

## Install

```bash
npm i sort-key
```


## Usage

```ts
import SortKey from 'sort-key';

const SK = SortKey.generate('1532208', '2020-09-11T15:30:06.822Z');
// 1532208#2020-09-11T15:30:06.822Z

const [order, time] = SortKey.parse(SK);
// "1532208" "2020-09-11T15:30:06.822Z"
```

#### It supports escaping as well:

```ts
const SK = SortKey.generate(
'example.com',
'foo',
'https://example.com/foo/bar#top',
);
// example.com#foo#https://example.com/foo/bar\#top

const [domain, page, url] = SortKey.parse(SK);
// "example.com" "foo" "https://example.com/foo/bar#top"
```


## License

[MIT](LICENSE) license © 2020 [Neuledge](https://neuledge.com)