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

feat: add util.cid options #13

Merged
merged 2 commits into from
Jun 25, 2018
Merged

feat: add util.cid options #13

merged 2 commits into from
Jun 25, 2018

Conversation

richardschneider
Copy link
Contributor

src/index.js Outdated
cid: (data, cb) => {
cb(null, new CID(1, 'raw', data))
cid: (data, options, cb) => {
if (options instanceof Function) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searching through the existing IPFS/IPLD code base it seems that the preferred way for checking if something is a function is: if (typeof options !== 'function') {. My guess is that it is related to code minifiers. Please change it.

src/index.js Outdated
}
options = options || {}
const hashAlg = options.hashAlg || 'sha2-256'
const version = options.version || 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. If options.version is set to 0, it will result in version == 1 as 0 evaluates to false.

Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should've found that earlier. Can you please add tests for the error cases, when invalid options are passed in?

Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm changing my mind (due to @richardschneider being right ipld/js-ipld-dag-cbor#66 (comment)).

When you merge, please do a "squash merge" and use the commit message of the first commit. That gives a clean Git history.

@richardschneider richardschneider merged commit bb2fbf7 into master Jun 25, 2018
@richardschneider richardschneider removed the status/in-progress In progress label Jun 25, 2018
@richardschneider richardschneider deleted the cid-options branch June 25, 2018 07:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants