Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

feat: add class-is module #24

Merged
merged 2 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
},
"dependencies": {
"async": "^2.6.1",
"class-is": "^1.1.0",
"err-code": "^1.1.2",
"pull-defer": "~0.2.2",
"pull-stream": "^3.6.8",
"uuid": "^3.2.1"
Expand All @@ -60,5 +62,5 @@
"tcme <hi@this-connect.me>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
],
"bundleDependencies": [],
"bundleDependencies": []
}
19 changes: 11 additions & 8 deletions src/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict'

const uuid = require('uuid/v4')
const withIs = require('class-is')

const pathSepS = '/'
const pathSepB = Buffer.from(pathSepS)
Expand Down Expand Up @@ -83,7 +84,7 @@ class Key {
*
*/
static withNamespaces (list /* : Array<string> */) /* : Key */ {
return new Key(list.join(pathSepS))
return new _Key(list.join(pathSepS))
}

/**
Expand All @@ -97,7 +98,7 @@ class Key {
*
*/
static random () /* : Key */ {
return new Key(uuid().replace(/-/g, ''))
return new _Key(uuid().replace(/-/g, ''))
}

/**
Expand Down Expand Up @@ -236,7 +237,7 @@ class Key {
* // => Key('/Comedy/MontyPython/Actor:JohnCleese')
*/
instance (s /* : string */) /* : Key */ {
return new Key(this.toString() + ':' + s)
return new _Key(this.toString() + ':' + s)
}

/**
Expand All @@ -255,7 +256,7 @@ class Key {
p += pathSepS
}
p += this.type()
return new Key(p)
return new _Key(p)
}

/**
Expand All @@ -271,10 +272,10 @@ class Key {
parent () /* : Key */ {
const list = this.list()
if (list.length === 1) {
return new Key(pathSepS)
return new _Key(pathSepS)
}

return new Key(list.slice(0, -1).join(pathSepS))
return new _Key(list.slice(0, -1).join(pathSepS))
}

/**
Expand All @@ -295,7 +296,7 @@ class Key {
return this
}

return new Key(this.toString() + key.toString(), false)
return new _Key(this.toString() + key.toString(), false)
}

/**
Expand Down Expand Up @@ -372,4 +373,6 @@ function namespaceValue (ns /* : string */) /* : string */ {
return parts[parts.length - 1]
}

module.exports = Key
const _Key = withIs(Key, { className: 'Key', symbolName: '@ipfs/interface-datastore/key' })

module.exports = _Key