Skip to content

Commit

Permalink
Standard (#71)
Browse files Browse the repository at this point in the history
* Add and run standard

* standard --fix + tweaks

* new Buffer() -> Buffer.from()

* Split initialized {const,var} declarations into multiple statements

* != -> !== or == -> ===

* Return statement should not contain assignment

* Missing space

* Handle error

* Add TODO
  • Loading branch information
ralphtheninja committed Jul 2, 2018
1 parent 8ee3b02 commit 4ada06a
Show file tree
Hide file tree
Showing 5 changed files with 397 additions and 449 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -5,6 +5,7 @@
**Add a `'ttl'` (time-to-live) option to LevelUP for `put()` and `batch()`**

[![Build Status](https://travis-ci.org/Level/level-ttl.svg?branch=master)](https://travis-ci.org/Level/level-ttl) [![Greenkeeper badge](https://badges.greenkeeper.io/Level/level-ttl.svg)](https://greenkeeper.io/)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

[![NPM](https://nodei.co/npm/level-ttl.png?downloads=true&downloadRank=true)](https://nodei.co/npm/level-ttl/)
[![NPM](https://nodei.co/npm-dl/level-ttl.png?months=6&height=3)](https://nodei.co/npm/level-ttl/)
Expand Down
30 changes: 15 additions & 15 deletions encoding.js
@@ -1,28 +1,28 @@
exports.create = function createEncoding (options) {
options || (options = {})

if (options.ttlEncoding)
return options.ttlEncoding
if (options.ttlEncoding) return options.ttlEncoding

const PATH_SEP = options.separator
, INITIAL_SEP = options.sub ? '' : PATH_SEP
const PATH_SEP = options.separator
const INITIAL_SEP = options.sub ? '' : PATH_SEP

function encodeElement(e) {
function encodeElement (e) {
// transform dates to timestamp strings
return String(e instanceof Date ? +e : e)
}

return {
buffer : false
, encode : function (e) {
// TODO: reexamine this with respect to level-sublevel@6's native codecs
if (Array.isArray(e))
return new Buffer(INITIAL_SEP + e.map(encodeElement).join(PATH_SEP))
return new Buffer(encodeElement(e))
}
, decode : function (e) {
// TODO: detect and parse ttl records
return e.toString('utf8')
buffer: false,
encode: function (e) {
// TODO: reexamine this with respect to level-sublevel@6's native codecs
if (Array.isArray(e)) {
return Buffer.from(INITIAL_SEP + e.map(encodeElement).join(PATH_SEP))
}
return Buffer.from(encodeElement(e))
},
decode: function (e) {
// TODO: detect and parse ttl records
return e.toString('utf8')
}
}
}

0 comments on commit 4ada06a

Please sign in to comment.