Beta 7 with some repo names changed.

This commit is contained in:
Luis Fernando Molina committed 2020-11-15 13:05:19 +01:00
1 parent 0f7b40cca7
commit 963c19493a
3408 files changed
+462217 -15516

No files matched your search

+4928
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -0,0 +1,3 @@
/*! For license information please see index.min.js.LICENSE */
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.Cids=n():e.Cids=n()}(window,(function(){return function(e){var n={};function t(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=e,t.c=n,t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:i})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)t.d(i,r,function(n){return e[n]}.bind(null,r));return i},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=6)}([function(e,n,t){"use strict";(function(e){var i=t(9),r=t(10),o=t(11);function s(){return k.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,n){if(s()<n)throw new RangeError("Invalid typed array length");return k.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(n)).__proto__=k.prototype:(null===e&&(e=new k(n)),e.length=n),e}function k(e,n,t){if(!(k.TYPED_ARRAY_SUPPORT||this instanceof k))return new k(e,n,t);if("number"==typeof e){if("string"==typeof n)throw new Error("If encoding is specified then the first argument must be a string");return l(this,e)}return u(this,e,n,t)}function u(e,n,t,i){if("number"==typeof n)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&n instanceof ArrayBuffer?function(e,n,t,i){if(n.byteLength,t<0||n.byteLength<t)throw new RangeError("'offset' is out of bounds");if(n.byteLength<t+(i||0))throw new RangeError("'length' is out of bounds");n=void 0===t&&void 0===i?new Uint8Array(n):void 0===i?new Uint8Array(n,t):new Uint8Array(n,t,i);k.TYPED_ARRAY_SUPPORT?(e=n).__proto__=k.prototype:e=c(e,n);return e}(e,n,t,i):"string"==typeof n?function(e,n,t){"string"==typeof t&&""!==t||(t="utf8");if(!k.isEncoding(t))throw new TypeError('"encoding" must be a valid string encoding');var i=0|b(n,t),r=(e=a(e,i)).write(n,t);r!==i&&(e=e.slice(0,r));return e}(e,n,t):function(e,n){if(k.isBuffer(n)){var t=0|h(n.length);return 0===(e=a(e,t)).length?e:(n.copy(e,0,0,t),e)}if(n){if("undefined"!=typeof ArrayBuffer&&n.buffer instanceof ArrayBuffer||"length"in n)return"number"!=typeof n.length||(i=n.length)!=i?a(e,0):c(e,n);if("Buffer"===n.type&&o(n.data))return c(e,n.data)}var i;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,n)}function f(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function l(e,n){if(f(n),e=a(e,n<0?0:0|h(n)),!k.TYPED_ARRAY_SUPPORT)for(var t=0;t<n;++t)e[t]=0;return e}function c(e,n){var t=n.length<0?0:0|h(n.length);e=a(e,t);for(var i=0;i<t;i+=1)e[i]=255&n[i];return e}function h(e){if(e>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|e}function b(e,n){if(k.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var t=e.length;if(0===t)return 0;for(var i=!1;;)switch(n){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":case void 0:return L(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*t;case"hex":return t>>>1;case"base64":return z(e).length;default:if(i)return L(e).length;n=(""+n).toLowerCase(),i=!0}}function S(e,n,t){var i=!1;if((void 0===n||n<0)&&(n=0),n>this.length)return"";if((void 0===t||t>this.length)&&(t=this.length),t<=0)return"";if((t>>>=0)<=(n>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return P(this,n,t);case"utf8":case"utf-8":return B(this,n,t);case"ascii":return _(this,n,t);case"latin1":case"binary":return R(this,n,t);case"base64":return x(this,n,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,n,t);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}function p(e,n,t){var i=e[n];e[n]=e[t],e[t]=i}function d(e,n,t,i,r){if(0===e.length)return-1;if("string"==typeof t?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,isNaN(t)&&(t=r?0:e.length-1),t<0&&(t=e.length+t),t>=e.length){if(r)return-1;t=e.length-1}else if(t<0){if(!r)return-1;t=0}if("string"==typeof n&&(n=k.from(n,i)),k.isBuffer(n))return 0===n.length?-1:g(e,n,t,i,r);if("number"==typeof n)return n&=255,k.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Line truncated
//# sourceMappingURL=index.min.js.map
+350
View File
@@ -0,0 +1,350 @@
/*!
* AnchorJS - v4.0.0 - 2017-06-02
* https://github.com/bryanbraun/anchorjs
* Copyright (c) 2017 Bryan Braun; Licensed MIT
*/
/* eslint-env amd, node */
// https://github.com/umdjs/umd/blob/master/templates/returnExports.js
(function(root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.AnchorJS = factory();
root.anchors = new root.AnchorJS();
}
})(this, function() {
'use strict';
function AnchorJS(options) {
this.options = options || {};
this.elements = [];
/**
* Assigns options to the internal options object, and provides defaults.
* @param {Object} opts - Options object
*/
function _applyRemainingDefaultOptions(opts) {
opts.icon = opts.hasOwnProperty('icon') ? opts.icon : '\ue9cb'; // Accepts characters (and also URLs?), like '#', '¶', '❡', or '§'.
opts.visible = opts.hasOwnProperty('visible') ? opts.visible : 'hover'; // Also accepts 'always' & 'touch'
opts.placement = opts.hasOwnProperty('placement')
? opts.placement
: 'right'; // Also accepts 'left'
opts.class = opts.hasOwnProperty('class') ? opts.class : ''; // Accepts any class name.
// Using Math.floor here will ensure the value is Number-cast and an integer.
opts.truncate = opts.hasOwnProperty('truncate')
? Math.floor(opts.truncate)
: 64; // Accepts any value that can be typecast to a number.
}
_applyRemainingDefaultOptions(this.options);
/**
* Checks to see if this device supports touch. Uses criteria pulled from Modernizr:
* https://github.com/Modernizr/Modernizr/blob/da22eb27631fc4957f67607fe6042e85c0a84656/feature-detects/touchevents.js#L40
* @returns {Boolean} - true if the current device supports touch.
*/
this.isTouchDevice = function() {
return !!(
'ontouchstart' in window ||
(window.DocumentTouch && document instanceof DocumentTouch)
);
};
/**
* Add anchor links to page elements.
* @param {String|Array|Nodelist} selector - A CSS selector for targeting the elements you wish to add anchor links
* to. Also accepts an array or nodeList containing the relavant elements.
* @returns {this} - The AnchorJS object
*/
this.add = function(selector) {
var elements,
elsWithIds,
idList,
elementID,
i,
index,
count,
tidyText,
newTidyText,
readableID,
anchor,
visibleOptionToUse,
indexesToDrop = [];
// We reapply options here because somebody may have overwritten the default options object when setting options.
// For example, this overwrites all options but visible:
//
// anchors.options = { visible: 'always'; }
_applyRemainingDefaultOptions(this.options);
visibleOptionToUse = this.options.visible;
if (visibleOptionToUse === 'touch') {
visibleOptionToUse = this.isTouchDevice() ? 'always' : 'hover';
}
// Provide a sensible default selector, if none is given.
if (!selector) {
selector = 'h2, h3, h4, h5, h6';
}
elements = _getElements(selector);
if (elements.length === 0) {
return this;
}
_addBaselineStyles();
// We produce a list of existing IDs so we don't generate a duplicate.
elsWithIds = document.querySelectorAll('[id]');
idList = [].map.call(elsWithIds, function assign(el) {
return el.id;
});
for (i = 0; i < elements.length; i++) {
if (this.hasAnchorJSLink(elements[i])) {
indexesToDrop.push(i);
continue;
}
if (elements[i].hasAttribute('id')) {
elementID = elements[i].getAttribute('id');
} else if (elements[i].hasAttribute('data-anchor-id')) {
elementID = elements[i].getAttribute('data-anchor-id');
} else {
tidyText = this.urlify(elements[i].textContent);
// Compare our generated ID to existing IDs (and increment it if needed)
// before we add it to the page.
newTidyText = tidyText;
count = 0;
do {
if (index !== undefined) {
newTidyText = tidyText + '-' + count;
}
index = idList.indexOf(newTidyText);
count += 1;
} while (index !== -1);
index = undefined;
idList.push(newTidyText);
elements[i].setAttribute('id', newTidyText);
elementID = newTidyText;
}
readableID = elementID.replace(/-/g, ' ');
// The following code builds the following DOM structure in a more effiecient (albeit opaque) way.
// '<a class="anchorjs-link ' + this.options.class + '" href="#' + elementID + '" aria-label="Anchor link for: ' + readableID + '" data-anchorjs-icon="' + this.options.icon + '"></a>';
anchor = document.createElement('a');
anchor.className = 'anchorjs-link ' + this.options.class;
anchor.href = '#' + elementID;
anchor.setAttribute('aria-label', 'Anchor link for: ' + readableID);
anchor.setAttribute('data-anchorjs-icon', this.options.icon);
if (visibleOptionToUse === 'always') {
anchor.style.opacity = '1';
}
if (this.options.icon === '\ue9cb') {
anchor.style.font = '1em/1 anchorjs-icons';
// We set lineHeight = 1 here because the `anchorjs-icons` font family could otherwise affect the
// height of the heading. This isn't the case for icons with `placement: left`, so we restore
// line-height: inherit in that case, ensuring they remain positioned correctly. For more info,
// see https://github.com/bryanbraun/anchorjs/issues/39.
if (this.options.placement === 'left') {
anchor.style.lineHeight = 'inherit';
}
}
if (this.options.placement === 'left') {
anchor.style.position = 'absolute';
anchor.style.marginLeft = '-1em';
anchor.style.paddingRight = '0.5em';
elements[i].insertBefore(anchor, elements[i].firstChild);
} else {
// if the option provided is `right` (or anything else).
anchor.style.paddingLeft = '0.375em';
elements[i].appendChild(anchor);
}
}
for (i = 0; i < indexesToDrop.length; i++) {
elements.splice(indexesToDrop[i] - i, 1);
}
this.elements = this.elements.concat(elements);
return this;
};
/**
* Removes all anchorjs-links from elements targed by the selector.
* @param {String|Array|Nodelist} selector - A CSS selector string targeting elements with anchor links,
* OR a nodeList / array containing the DOM elements.
* @returns {this} - The AnchorJS object
*/
this.remove = function(selector) {
var index,
domAnchor,
elements = _getElements(selector);
for (var i = 0; i < elements.length; i++) {
domAnchor = elements[i].querySelector('.anchorjs-link');
if (domAnchor) {
// Drop the element from our main list, if it's in there.
index = this.elements.indexOf(elements[i]);
if (index !== -1) {
this.elements.splice(index, 1);
}
// Remove the anchor from the DOM.
elements[i].removeChild(domAnchor);
}
}
return this;
};
/**
* Removes all anchorjs links. Mostly used for tests.
*/
this.removeAll = function() {
this.remove(this.elements);
};
/**
* Urlify - Refine text so it makes a good ID.
*
* To do this, we remove apostrophes, replace nonsafe characters with hyphens,
* remove extra hyphens, truncate, trim hyphens, and make lowercase.
*
* @param {String} text - Any text. Usually pulled from the webpage element we are linking to.
* @returns {String} - hyphen-delimited text for use in IDs and URLs.
*/
this.urlify = function(text) {
// Regex for finding the nonsafe URL characters (many need escaping): & +$,:;=?@"#{}|^~[`%!'<>]./()*\
var nonsafeChars = /[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\]/g,
urlText;
// The reason we include this _applyRemainingDefaultOptions is so urlify can be called independently,
// even after setting options. This can be useful for tests or other applications.
if (!this.options.truncate) {
_applyRemainingDefaultOptions(this.options);
}
// Note: we trim hyphens after truncating because truncating can cause dangling hyphens.
// Example string: // " ⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
urlText = text
.trim() // "⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
.replace(/\'/gi, '') // "⚡⚡ Dont forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
.replace(nonsafeChars, '-') // "⚡⚡-Dont-forget--URL-fragments-should-be-i18n-friendly--hyphenated--short--and-clean-"
.replace(/-{2,}/g, '-') // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-short-and-clean-"
.substring(0, this.options.truncate) // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-"
.replace(/^-+|-+$/gm, '') // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated"
.toLowerCase(); // "⚡⚡-dont-forget-url-fragments-should-be-i18n-friendly-hyphenated"
return urlText;
};
/**
* Determines if this element already has an AnchorJS link on it.
* Uses this technique: http://stackoverflow.com/a/5898748/1154642
* @param {HTMLElemnt} el - a DOM node
* @returns {Boolean} true/false
*/
this.hasAnchorJSLink = function(el) {
var hasLeftAnchor =
el.firstChild &&
(' ' + el.firstChild.className + ' ').indexOf(' anchorjs-link ') > -1,
hasRightAnchor =
el.lastChild &&
(' ' + el.lastChild.className + ' ').indexOf(' anchorjs-link ') > -1;
return hasLeftAnchor || hasRightAnchor || false;
};
/**
* Turns a selector, nodeList, or array of elements into an array of elements (so we can use array methods).
* It also throws errors on any other inputs. Used to handle inputs to .add and .remove.
* @param {String|Array|Nodelist} input - A CSS selector string targeting elements with anchor links,
* OR a nodeList / array containing the DOM elements.
* @returns {Array} - An array containing the elements we want.
*/
function _getElements(input) {
var elements;
if (typeof input === 'string' || input instanceof String) {
// See https://davidwalsh.name/nodelist-array for the technique transforming nodeList -> Array.
elements = [].slice.call(document.querySelectorAll(input));
// I checked the 'input instanceof NodeList' test in IE9 and modern browsers and it worked for me.
} else if (Array.isArray(input) || input instanceof NodeList) {
elements = [].slice.call(input);
} else {
throw new Error('The selector provided to AnchorJS was invalid.');
}
return elements;
}
/**
* _addBaselineStyles
* Adds baseline styles to the page, used by all AnchorJS links irregardless of configuration.
*/
function _addBaselineStyles() {
// We don't want to add global baseline styles if they've been added before.
if (document.head.querySelector('style.anchorjs') !== null) {
return;
}
var style = document.createElement('style'),
linkRule =
' .anchorjs-link {' +
' opacity: 0;' +
' text-decoration: none;' +
' -webkit-font-smoothing: antialiased;' +
' -moz-osx-font-smoothing: grayscale;' +
' }',
hoverRule =
' *:hover > .anchorjs-link,' +
' .anchorjs-link:focus {' +
' opacity: 1;' +
' }',
anchorjsLinkFontFace =
' @font-face {' +
' font-family: "anchorjs-icons";' + // Icon from icomoon; 10px wide & 10px tall; 2 empty below & 4 above
' src: url(data:n/a;base64,AAEAAAALAIAAAwAwT1MvMg8yG2cAAAE4AAAAYGNtYXDp3gC3AAABpAAAAExnYXNwAAAAEAAAA9wAAAAIZ2x5ZlQCcfwAAAH4AAABCGhlYWQHFvHyAAAAvAAAADZoaGVhBnACFwAAAPQAAAAkaG10eASAADEAAAGYAAAADGxvY2EACACEAAAB8AAAAAhtYXhwAAYAVwAAARgAAAAgbmFtZQGOH9cAAAMAAAAAunBvc3QAAwAAAAADvAAAACAAAQAAAAEAAHzE2p9fDzz1AAkEAAAAAADRecUWAAAAANQA6R8AAAAAAoACwAAAAAgAAgAAAAAAAAABAAADwP/AAAACgAAA/9MCrQABAAAAAAAAAAAAAAAAAAAAAwABAAAAAwBVAAIAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAMCQAGQAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAQAAg//0DwP/AAEADwABAAAAAAQAAAAAAAAAAAAAAIAAAAAAAAAIAAAACgAAxAAAAAwAAAAMAAAAcAAEAAwAAABwAAwABAAAAHAAEADAAAAAIAAgAAgAAACDpy//9//8AAAAg6cv//f///+EWNwADAAEAAAAAAAAAAAAAAAAACACEAAEAAAAAAAAAAAAAAAAxAAACAAQARAKAAsAAKwBUAAABIiYnJjQ3NzY2MzIWFxYUBwcGIicmNDc3NjQnJiYjIgYHBwYUFxYUBwYGIwciJicmNDc3NjIXFhQHBwYUFxYWMzI2Nzc2NCcmNDc2MhcWFAcHBgYjARQGDAUtLXoWOR8fORYtLTgKGwoKCjgaGg0gEhIgDXoaGgkJBQwHdR85Fi0tOAobCgoKOBoaDSASEiANehoaCQkKGwotLXoWOR8BMwUFLYEuehYXFxYugC44CQkKGwo4GkoaDQ0NDXoaShoKGwoFBe8XFi6ALjgJCQobCjgaShoNDQ0NehpKGgobCgoKLYEuehYXAAAADACWAAEAAAAAAAEACAAAAAEAAAAAAAIAAwAIAAEAAAAAAAMACAAAAAEAAAAAAAQACAAAAAEAAAAAAAUAAQALAAEAAAAAAAYACAAAAAMAAQQJAAEAEAAMAAMAAQQJAAIABgAcAAMAAQQJAAMAEAAMAAMAAQQJAAQAEAAMAAMAAQQJAAUAAgAiAAMAAQQJAAYAEAAMYW5jaG9yanM0MDBAAGEAbgBjAGgAbwByAGoAcwA0ADAAMABAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAH//wAP) format("truetype");' +
' }',
pseudoElContent =
' [data-anchorjs-icon]::after {' +
' content: attr(data-anchorjs-icon);' +
' }',
firstStyleEl;
style.className = 'anchorjs';
style.appendChild(document.createTextNode('')); // Necessary for Webkit.
// We place it in the head with the other style tags, if possible, so as to
// not look out of place. We insert before the others so these styles can be
// overridden if necessary.
firstStyleEl = document.head.querySelector('[rel="stylesheet"], style');
if (firstStyleEl === undefined) {
document.head.appendChild(style);
} else {
document.head.insertBefore(style, firstStyleEl);
}
style.sheet.insertRule(linkRule, style.sheet.cssRules.length);
style.sheet.insertRule(hoverRule, style.sheet.cssRules.length);
style.sheet.insertRule(pseudoElContent, style.sheet.cssRules.length);
style.sheet.insertRule(anchorjsLinkFontFace, style.sheet.cssRules.length);
}
}
return AnchorJS;
});
+168
View File
@@ -0,0 +1,168 @@
/* global anchors */
// add anchor links to headers
anchors.options.placement = 'left';
anchors.add('h3');
// Filter UI
var tocElements = document.getElementById('toc').getElementsByTagName('li');
document.getElementById('filter-input').addEventListener('keyup', function(e) {
var i, element, children;
// enter key
if (e.keyCode === 13) {
// go to the first displayed item in the toc
for (i = 0; i < tocElements.length; i++) {
element = tocElements[i];
if (!element.classList.contains('display-none')) {
location.replace(element.firstChild.href);
return e.preventDefault();
}
}
}
var match = function() {
return true;
};
var value = this.value.toLowerCase();
if (!value.match(/^\s*$/)) {
match = function(element) {
var html = element.firstChild.innerHTML;
return html && html.toLowerCase().indexOf(value) !== -1;
};
}
for (i = 0; i < tocElements.length; i++) {
element = tocElements[i];
children = Array.from(element.getElementsByTagName('li'));
if (match(element) || children.some(match)) {
element.classList.remove('display-none');
} else {
element.classList.add('display-none');
}
}
});
var items = document.getElementsByClassName('toggle-sibling');
for (var j = 0; j < items.length; j++) {
items[j].addEventListener('click', toggleSibling);
}
function toggleSibling() {
var stepSibling = this.parentNode.getElementsByClassName('toggle-target')[0];
var icon = this.getElementsByClassName('icon')[0];
var klass = 'display-none';
if (stepSibling.classList.contains(klass)) {
stepSibling.classList.remove(klass);
icon.innerHTML = '▾';
} else {
stepSibling.classList.add(klass);
icon.innerHTML = '▸';
}
}
function showHashTarget(targetId) {
if (targetId) {
var hashTarget = document.getElementById(targetId);
// new target is hidden
if (
hashTarget &&
hashTarget.offsetHeight === 0 &&
hashTarget.parentNode.parentNode.classList.contains('display-none')
) {
hashTarget.parentNode.parentNode.classList.remove('display-none');
}
}
}
function scrollIntoView(targetId) {
// Only scroll to element if we don't have a stored scroll position.
if (targetId && !history.state) {
var hashTarget = document.getElementById(targetId);
if (hashTarget) {
hashTarget.scrollIntoView();
}
}
}
function gotoCurrentTarget() {
showHashTarget(location.hash.substring(1));
scrollIntoView(location.hash.substring(1));
}
window.addEventListener('hashchange', gotoCurrentTarget);
gotoCurrentTarget();
var toclinks = document.getElementsByClassName('pre-open');
for (var k = 0; k < toclinks.length; k++) {
toclinks[k].addEventListener('mousedown', preOpen, false);
}
function preOpen() {
showHashTarget(this.hash.substring(1));
}
var split_left = document.querySelector('#split-left');
var split_right = document.querySelector('#split-right');
var split_parent = split_left.parentNode;
var cw_with_sb = split_left.clientWidth;
split_left.style.overflow = 'hidden';
var cw_without_sb = split_left.clientWidth;
split_left.style.overflow = '';
Split(['#split-left', '#split-right'], {
elementStyle: function(dimension, size, gutterSize) {
return {
'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)'
};
},
gutterStyle: function(dimension, gutterSize) {
return {
'flex-basis': gutterSize + 'px'
};
},
gutterSize: 20,
sizes: [33, 67]
});
// Chrome doesn't remember scroll position properly so do it ourselves.
// Also works on Firefox and Edge.
function updateState() {
history.replaceState(
{
left_top: split_left.scrollTop,
right_top: split_right.scrollTop
},
document.title
);
}
function loadState(ev) {
if (ev) {
// Edge doesn't replace change history.state on popstate.
history.replaceState(ev.state, document.title);
}
if (history.state) {
split_left.scrollTop = history.state.left_top;
split_right.scrollTop = history.state.right_top;
}
}
window.addEventListener('load', function() {
// Restore after Firefox scrolls to hash.
setTimeout(function() {
loadState();
// Update with initial scroll position.
updateState();
// Update scroll positions only after we've loaded because Firefox
// emits an initial scroll event with 0.
split_left.addEventListener('scroll', updateState);
split_right.addEventListener('scroll', updateState);
}, 1);
});
window.addEventListener('popstate', loadState);
+782
View File
@@ -0,0 +1,782 @@
/*! Split.js - v1.5.11 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Split = factory());
}(this, (function () { 'use strict';
// The programming goals of Split.js are to deliver readable, understandable and
// maintainable code, while at the same time manually optimizing for tiny minified file size,
// browser compatibility without additional requirements, graceful fallback (IE8 is supported)
// and very few assumptions about the user's page layout.
var global = window;
var document = global.document;
// Save a couple long function names that are used frequently.
// This optimization saves around 400 bytes.
var addEventListener = 'addEventListener';
var removeEventListener = 'removeEventListener';
var getBoundingClientRect = 'getBoundingClientRect';
var gutterStartDragging = '_a';
var aGutterSize = '_b';
var bGutterSize = '_c';
var HORIZONTAL = 'horizontal';
var NOOP = function () { return false; };
// Figure out if we're in IE8 or not. IE8 will still render correctly,
// but will be static instead of draggable.
var isIE8 = global.attachEvent && !global[addEventListener];
// Helper function determines which prefixes of CSS calc we need.
// We only need to do this once on startup, when this anonymous function is called.
//
// Tests -webkit, -moz and -o prefixes. Modified from StackOverflow:
// http://stackoverflow.com/questions/16625140/js-feature-detection-to-detect-the-usage-of-webkit-calc-over-calc/16625167#16625167
var calc = (['', '-webkit-', '-moz-', '-o-']
.filter(function (prefix) {
var el = document.createElement('div');
el.style.cssText = "width:" + prefix + "calc(9px)";
return !!el.style.length
})
.shift()) + "calc";
// Helper function checks if its argument is a string-like type
var isString = function (v) { return typeof v === 'string' || v instanceof String; };
// Helper function allows elements and string selectors to be used
// interchangeably. In either case an element is returned. This allows us to
// do `Split([elem1, elem2])` as well as `Split(['#id1', '#id2'])`.
var elementOrSelector = function (el) {
if (isString(el)) {
var ele = document.querySelector(el);
if (!ele) {
throw new Error(("Selector " + el + " did not match a DOM element"))
}
return ele
}
return el
};
// Helper function gets a property from the properties object, with a default fallback
var getOption = function (options, propName, def) {
var value = options[propName];
if (value !== undefined) {
return value
}
return def
};
var getGutterSize = function (gutterSize, isFirst, isLast, gutterAlign) {
if (isFirst) {
if (gutterAlign === 'end') {
return 0
}
if (gutterAlign === 'center') {
return gutterSize / 2
}
} else if (isLast) {
if (gutterAlign === 'start') {
return 0
}
if (gutterAlign === 'center') {
return gutterSize / 2
}
}
return gutterSize
};
// Default options
var defaultGutterFn = function (i, gutterDirection) {
var gut = document.createElement('div');
gut.className = "gutter gutter-" + gutterDirection;
return gut
};
var defaultElementStyleFn = function (dim, size, gutSize) {
var style = {};
if (!isString(size)) {
if (!isIE8) {
style[dim] = calc + "(" + size + "% - " + gutSize + "px)";
} else {
style[dim] = size + "%";
}
} else {
style[dim] = size;
}
return style
};
var defaultGutterStyleFn = function (dim, gutSize) {
var obj;
return (( obj = {}, obj[dim] = (gutSize + "px"), obj ));
};
// The main function to initialize a split. Split.js thinks about each pair
// of elements as an independant pair. Dragging the gutter between two elements
// only changes the dimensions of elements in that pair. This is key to understanding
// how the following functions operate, since each function is bound to a pair.
//
// A pair object is shaped like this:
//
// {
// a: DOM element,
// b: DOM element,
// aMin: Number,
// bMin: Number,
// dragging: Boolean,
// parent: DOM element,
// direction: 'horizontal' | 'vertical'
// }
//
// The basic sequence:
//
// 1. Set defaults to something sane. `options` doesn't have to be passed at all.
// 2. Initialize a bunch of strings based on the direction we're splitting.
// A lot of the behavior in the rest of the library is paramatized down to
// rely on CSS strings and classes.
// 3. Define the dragging helper functions, and a few helpers to go with them.
// 4. Loop through the elements while pairing them off. Every pair gets an
// `pair` object and a gutter.
// 5. Actually size the pair elements, insert gutters and attach event listeners.
var Split = function (idsOption, options) {
if ( options === void 0 ) options = {};
var ids = idsOption;
var dimension;
var clientAxis;
var position;
var positionEnd;
var clientSize;
var elements;
// Allow HTMLCollection to be used as an argument when supported
if (Array.from) {
ids = Array.from(ids);
}
// All DOM elements in the split should have a common parent. We can grab
// the first elements parent and hope users read the docs because the
// behavior will be whacky otherwise.
var firstElement = elementOrSelector(ids[0]);
var parent = firstElement.parentNode;
var parentStyle = getComputedStyle ? getComputedStyle(parent) : null;
var parentFlexDirection = parentStyle ? parentStyle.flexDirection : null;
// Set default options.sizes to equal percentages of the parent element.
var sizes = getOption(options, 'sizes') || ids.map(function () { return 100 / ids.length; });
// Standardize minSize to an array if it isn't already. This allows minSize
// to be passed as a number.
var minSize = getOption(options, 'minSize', 100);
var minSizes = Array.isArray(minSize) ? minSize : ids.map(function () { return minSize; });
// Get other options
var expandToMin = getOption(options, 'expandToMin', false);
var gutterSize = getOption(options, 'gutterSize', 10);
var gutterAlign = getOption(options, 'gutterAlign', 'center');
var snapOffset = getOption(options, 'snapOffset', 30);
var dragInterval = getOption(options, 'dragInterval', 1);
var direction = getOption(options, 'direction', HORIZONTAL);
var cursor = getOption(
options,
'cursor',
direction === HORIZONTAL ? 'col-resize' : 'row-resize'
);
var gutter = getOption(options, 'gutter', defaultGutterFn);
var elementStyle = getOption(
options,
'elementStyle',
defaultElementStyleFn
);
var gutterStyle = getOption(options, 'gutterStyle', defaultGutterStyleFn);
// 2. Initialize a bunch of strings based on the direction we're splitting.
// A lot of the behavior in the rest of the library is paramatized down to
// rely on CSS strings and classes.
if (direction === HORIZONTAL) {
dimension = 'width';
clientAxis = 'clientX';
position = 'left';
positionEnd = 'right';
clientSize = 'clientWidth';
} else if (direction === 'vertical') {
dimension = 'height';
clientAxis = 'clientY';
position = 'top';
positionEnd = 'bottom';
clientSize = 'clientHeight';
}
// 3. Define the dragging helper functions, and a few helpers to go with them.
// Each helper is bound to a pair object that contains its metadata. This
// also makes it easy to store references to listeners that that will be
// added and removed.
//
// Even though there are no other functions contained in them, aliasing
// this to self saves 50 bytes or so since it's used so frequently.
//
// The pair object saves metadata like dragging state, position and
// event listener references.
function setElementSize(el, size, gutSize, i) {
// Split.js allows setting sizes via numbers (ideally), or if you must,
// by string, like '300px'. This is less than ideal, because it breaks
// the fluid layout that `calc(% - px)` provides. You're on your own if you do that,
// make sure you calculate the gutter size by hand.
var style = elementStyle(dimension, size, gutSize, i);
Object.keys(style).forEach(function (prop) {
// eslint-disable-next-line no-param-reassign
el.style[prop] = style[prop];
});
}
function setGutterSize(gutterElement, gutSize, i) {
var style = gutterStyle(dimension, gutSize, i);
Object.keys(style).forEach(function (prop) {
// eslint-disable-next-line no-param-reassign
gutterElement.style[prop] = style[prop];
});
}
function getSizes() {
return elements.map(function (element) { return element.size; })
}
// Supports touch events, but not multitouch, so only the first
// finger `touches[0]` is counted.
function getMousePosition(e) {
if ('touches' in e) { return e.touches[0][clientAxis] }
return e[clientAxis]
}
// Actually adjust the size of elements `a` and `b` to `offset` while dragging.
// calc is used to allow calc(percentage + gutterpx) on the whole split instance,
// which allows the viewport to be resized without additional logic.
// Element a's size is the same as offset. b's size is total size - a size.
// Both sizes are calculated from the initial parent percentage,
// then the gutter size is subtracted.
function adjust(offset) {
var a = elements[this.a];
var b = elements[this.b];
var percentage = a.size + b.size;
a.size = (offset / this.size) * percentage;
b.size = percentage - (offset / this.size) * percentage;
setElementSize(a.element, a.size, this[aGutterSize], a.i);
setElementSize(b.element, b.size, this[bGutterSize], b.i);
}
// drag, where all the magic happens. The logic is really quite simple:
//
// 1. Ignore if the pair is not dragging.
// 2. Get the offset of the event.
// 3. Snap offset to min if within snappable range (within min + snapOffset).
// 4. Actually adjust each element in the pair to offset.
//
// ---------------------------------------------------------------------
// | | <- a.minSize || b.minSize -> | |
// | | | <- this.snapOffset || this.snapOffset -> | | |
// | | | || | | |
// | | | || | | |
// ---------------------------------------------------------------------
// | <- this.start this.size -> |
function drag(e) {
var offset;
var a = elements[this.a];
var b = elements[this.b];
if (!this.dragging) { return }
// Get the offset of the event from the first side of the
// pair `this.start`. Then offset by the initial position of the
// mouse compared to the gutter size.
offset =
getMousePosition(e) -
this.start +
(this[aGutterSize] - this.dragOffset);
if (dragInterval > 1) {
offset = Math.round(offset / dragInterval) * dragInterval;
}
// If within snapOffset of min or max, set offset to min or max.
// snapOffset buffers a.minSize and b.minSize, so logic is opposite for both.
// Include the appropriate gutter sizes to prevent overflows.
if (offset <= a.minSize + snapOffset + this[aGutterSize]) {
offset = a.minSize + this[aGutterSize];
} else if (
offset >=
this.size - (b.minSize + snapOffset + this[bGutterSize])
) {
offset = this.size - (b.minSize + this[bGutterSize]);
}
// Actually adjust the size.
adjust.call(this, offset);
// Call the drag callback continously. Don't do anything too intensive
// in this callback.
getOption(options, 'onDrag', NOOP)();
}
// Cache some important sizes when drag starts, so we don't have to do that
// continously:
//
// `size`: The total size of the pair. First + second + first gutter + second gutter.
// `start`: The leading side of the first element.
//
// ------------------------------------------------
// | aGutterSize -> ||| |
// | ||| |
// | ||| |
// | ||| <- bGutterSize |
// ------------------------------------------------
// | <- start size -> |
function calculateSizes() {
// Figure out the parent size minus padding.
var a = elements[this.a].element;
var b = elements[this.b].element;
var aBounds = a[getBoundingClientRect]();
var bBounds = b[getBoundingClientRect]();
this.size =
aBounds[dimension] +
bBounds[dimension] +
this[aGutterSize] +
this[bGutterSize];
this.start = aBounds[position];
this.end = aBounds[positionEnd];
}
function innerSize(element) {
// Return nothing if getComputedStyle is not supported (< IE9)
// Or if parent element has no layout yet
if (!getComputedStyle) { return null }
var computedStyle = getComputedStyle(element);
if (!computedStyle) { return null }
var size = element[clientSize];
if (size === 0) { return null }
if (direction === HORIZONTAL) {
size -=
parseFloat(computedStyle.paddingLeft) +
parseFloat(computedStyle.paddingRight);
} else {
size -=
parseFloat(computedStyle.paddingTop) +
parseFloat(computedStyle.paddingBottom);
}
return size
}
// When specifying percentage sizes that are less than the computed
// size of the element minus the gutter, the lesser percentages must be increased
// (and decreased from the other elements) to make space for the pixels
// subtracted by the gutters.
function trimToMin(sizesToTrim) {
// Try to get inner size of parent element.
// If it's no supported, return original sizes.
var parentSize = innerSize(parent);
if (parentSize === null) {
return sizesToTrim
}
if (minSizes.reduce(function (a, b) { return a + b; }, 0) > parentSize) {
return sizesToTrim
}
// Keep track of the excess pixels, the amount of pixels over the desired percentage
// Also keep track of the elements with pixels to spare, to decrease after if needed
var excessPixels = 0;
var toSpare = [];
var pixelSizes = sizesToTrim.map(function (size, i) {
// Convert requested percentages to pixel sizes
var pixelSize = (parentSize * size) / 100;
var elementGutterSize = getGutterSize(
gutterSize,
i === 0,
i === sizesToTrim.length - 1,
gutterAlign
);
var elementMinSize = minSizes[i] + elementGutterSize;
// If element is too smal, increase excess pixels by the difference
// and mark that it has no pixels to spare
if (pixelSize < elementMinSize) {
excessPixels += elementMinSize - pixelSize;
toSpare.push(0);
return elementMinSize
}
// Otherwise, mark the pixels it has to spare and return it's original size
toSpare.push(pixelSize - elementMinSize);
return pixelSize
});
// If nothing was adjusted, return the original sizes
if (excessPixels === 0) {
return sizesToTrim
}
return pixelSizes.map(function (pixelSize, i) {
var newPixelSize = pixelSize;
// While there's still pixels to take, and there's enough pixels to spare,
// take as many as possible up to the total excess pixels
if (excessPixels > 0 && toSpare[i] - excessPixels > 0) {
var takenPixels = Math.min(
excessPixels,
toSpare[i] - excessPixels
);
// Subtract the amount taken for the next iteration
excessPixels -= takenPixels;
newPixelSize = pixelSize - takenPixels;
}
// Return the pixel size adjusted as a percentage
return (newPixelSize / parentSize) * 100
})
}
// stopDragging is very similar to startDragging in reverse.
function stopDragging() {
var self = this;
var a = elements[self.a].element;
var b = elements[self.b].element;
if (self.dragging) {
getOption(options, 'onDragEnd', NOOP)(getSizes());
}
self.dragging = false;
// Remove the stored event listeners. This is why we store them.
global[removeEventListener]('mouseup', self.stop);
global[removeEventListener]('touchend', self.stop);
global[removeEventListener]('touchcancel', self.stop);
global[removeEventListener]('mousemove', self.move);
global[removeEventListener]('touchmove', self.move);
// Clear bound function references
self.stop = null;
self.move = null;
a[removeEventListener]('selectstart', NOOP);
a[removeEventListener]('dragstart', NOOP);
b[removeEventListener]('selectstart', NOOP);
b[removeEventListener]('dragstart', NOOP);
a.style.userSelect = '';
a.style.webkitUserSelect = '';
a.style.MozUserSelect = '';
a.style.pointerEvents = '';
b.style.userSelect = '';
b.style.webkitUserSelect = '';
b.style.MozUserSelect = '';
b.style.pointerEvents = '';
self.gutter.style.cursor = '';
self.parent.style.cursor = '';
document.body.style.cursor = '';
}
// startDragging calls `calculateSizes` to store the inital size in the pair object.
// It also adds event listeners for mouse/touch events,
// and prevents selection while dragging so avoid the selecting text.
function startDragging(e) {
// Right-clicking can't start dragging.
if ('button' in e && e.button !== 0) {
return
}
// Alias frequently used variables to save space. 200 bytes.
var self = this;
var a = elements[self.a].element;
var b = elements[self.b].element;
// Call the onDragStart callback.
if (!self.dragging) {
getOption(options, 'onDragStart', NOOP)(getSizes());
}
// Don't actually drag the element. We emulate that in the drag function.
e.preventDefault();
// Set the dragging property of the pair object.
self.dragging = true;
// Create two event listeners bound to the same pair object and store
// them in the pair object.
self.move = drag.bind(self);
self.stop = stopDragging.bind(self);
// All the binding. `window` gets the stop events in case we drag out of the elements.
global[addEventListener]('mouseup', self.stop);
global[addEventListener]('touchend', self.stop);
global[addEventListener]('touchcancel', self.stop);
global[addEventListener]('mousemove', self.move);
global[addEventListener]('touchmove', self.move);
// Disable selection. Disable!
a[addEventListener]('selectstart', NOOP);
a[addEventListener]('dragstart', NOOP);
b[addEventListener]('selectstart', NOOP);
b[addEventListener]('dragstart', NOOP);
a.style.userSelect = 'none';
a.style.webkitUserSelect = 'none';
a.style.MozUserSelect = 'none';
a.style.pointerEvents = 'none';
b.style.userSelect = 'none';
b.style.webkitUserSelect = 'none';
b.style.MozUserSelect = 'none';
b.style.pointerEvents = 'none';
// Set the cursor at multiple levels
self.gutter.style.cursor = cursor;
self.parent.style.cursor = cursor;
document.body.style.cursor = cursor;
// Cache the initial sizes of the pair.
calculateSizes.call(self);
// Determine the position of the mouse compared to the gutter
self.dragOffset = getMousePosition(e) - self.end;
}
// adjust sizes to ensure percentage is within min size and gutter.
sizes = trimToMin(sizes);
// 5. Create pair and element objects. Each pair has an index reference to
// elements `a` and `b` of the pair (first and second elements).
// Loop through the elements while pairing them off. Every pair gets a
// `pair` object and a gutter.
//
// Basic logic:
//
// - Starting with the second element `i > 0`, create `pair` objects with
// `a = i - 1` and `b = i`
// - Set gutter sizes based on the _pair_ being first/last. The first and last
// pair have gutterSize / 2, since they only have one half gutter, and not two.
// - Create gutter elements and add event listeners.
// - Set the size of the elements, minus the gutter sizes.
//
// -----------------------------------------------------------------------
// | i=0 | i=1 | i=2 | i=3 |
// | | | | |
// | pair 0 pair 1 pair 2 |
// | | | | |
// -----------------------------------------------------------------------
var pairs = [];
elements = ids.map(function (id, i) {
// Create the element object.
var element = {
element: elementOrSelector(id),
size: sizes[i],
minSize: minSizes[i],
i: i,
};
var pair;
if (i > 0) {
// Create the pair object with its metadata.
pair = {
a: i - 1,
b: i,
dragging: false,
direction: direction,
parent: parent,
};
pair[aGutterSize] = getGutterSize(
gutterSize,
i - 1 === 0,
false,
gutterAlign
);
pair[bGutterSize] = getGutterSize(
gutterSize,
false,
i === ids.length - 1,
gutterAlign
);
// if the parent has a reverse flex-direction, switch the pair elements.
if (
parentFlexDirection === 'row-reverse' ||
parentFlexDirection === 'column-reverse'
) {
var temp = pair.a;
pair.a = pair.b;
pair.b = temp;
}
}
// Determine the size of the current element. IE8 is supported by
// staticly assigning sizes without draggable gutters. Assigns a string
// to `size`.
//
// IE9 and above
if (!isIE8) {
// Create gutter elements for each pair.
if (i > 0) {
var gutterElement = gutter(i, direction, element.element);
setGutterSize(gutterElement, gutterSize, i);
// Save bound event listener for removal later
pair[gutterStartDragging] = startDragging.bind(pair);
// Attach bound event listener
gutterElement[addEventListener](
'mousedown',
pair[gutterStartDragging]
);
gutterElement[addEventListener](
'touchstart',
pair[gutterStartDragging]
);
parent.insertBefore(gutterElement, element.element);
pair.gutter = gutterElement;
}
}
setElementSize(
element.element,
element.size,
getGutterSize(
gutterSize,
i === 0,
i === ids.length - 1,
gutterAlign
),
i
);
// After the first iteration, and we have a pair object, append it to the
// list of pairs.
if (i > 0) {
pairs.push(pair);
}
return element
});
function adjustToMin(element) {
var isLast = element.i === pairs.length;
var pair = isLast ? pairs[element.i - 1] : pairs[element.i];
calculateSizes.call(pair);
var size = isLast
? pair.size - element.minSize - pair[bGutterSize]
: element.minSize + pair[aGutterSize];
adjust.call(pair, size);
}
elements.forEach(function (element) {
var computedSize = element.element[getBoundingClientRect]()[dimension];
if (computedSize < element.minSize) {
if (expandToMin) {
adjustToMin(element);
} else {
// eslint-disable-next-line no-param-reassign
element.minSize = computedSize;
}
}
});
function setSizes(newSizes) {
var trimmed = trimToMin(newSizes);
trimmed.forEach(function (newSize, i) {
if (i > 0) {
var pair = pairs[i - 1];
var a = elements[pair.a];
var b = elements[pair.b];
a.size = trimmed[i - 1];
b.size = newSize;
setElementSize(a.element, a.size, pair[aGutterSize], a.i);
setElementSize(b.element, b.size, pair[bGutterSize], b.i);
}
});
}
function destroy(preserveStyles, preserveGutter) {
pairs.forEach(function (pair) {
if (preserveGutter !== true) {
pair.parent.removeChild(pair.gutter);
} else {
pair.gutter[removeEventListener](
'mousedown',
pair[gutterStartDragging]
);
pair.gutter[removeEventListener](
'touchstart',
pair[gutterStartDragging]
);
}
if (preserveStyles !== true) {
var style = elementStyle(
dimension,
pair.a.size,
pair[aGutterSize]
);
Object.keys(style).forEach(function (prop) {
elements[pair.a].element.style[prop] = '';
elements[pair.b].element.style[prop] = '';
});
}
});
}
if (isIE8) {
return {
setSizes: setSizes,
destroy: destroy,
}
}
return {
setSizes: setSizes,
getSizes: getSizes,
collapse: function collapse(i) {
adjustToMin(elements[i]);
},
destroy: destroy,
parent: parent,
pairs: pairs,
}
};
return Split;
})));
+12
View File
@@ -0,0 +1,12 @@
'use strict'
const CID = require('../src')
const multihashStr = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
const cidv0 = new CID(multihashStr)
console.log(cidv0.toBaseEncodedString())
const cidv1 = cidv0.toV1()
console.log(cidv1.toBaseEncodedString())
+2
View File
@@ -0,0 +1,2 @@
/*! For license information please see index.min.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Multicodec=t():e.Multicodec=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e){e.exports=JSON.parse('{"identity":0,"ip4":4,"tcp":6,"sha1":17,"sha2-256":18,"sha2-512":19,"sha3-512":20,"sha3-384":21,"sha3-256":22,"sha3-224":23,"shake-128":24,"shake-256":25,"keccak-224":26,"keccak-256":27,"keccak-384":28,"keccak-512":29,"blake3":30,"dccp":33,"murmur3-128":34,"murmur3-32":35,"ip6":41,"ip6zone":42,"path":47,"multicodec":48,"multihash":49,"multiaddr":50,"multibase":51,"dns":53,"dns4":54,"dns6":55,"dnsaddr":56,"protobuf":80,"cbor":81,"raw":85,"dbl-sha2-256":86,"rlp":96,"bencode":99,"dag-pb":112,"dag-cbor":113,"libp2p-key":114,"git-raw":120,"torrent-info":123,"torrent-file":124,"leofcoin-block":129,"leofcoin-tx":130,"leofcoin-pr":131,"sctp":132,"dag-jose":133,"dag-cose":134,"eth-block":144,"eth-block-list":145,"eth-tx-trie":146,"eth-tx":147,"eth-tx-receipt-trie":148,"eth-tx-receipt":149,"eth-state-trie":150,"eth-account-snapshot":151,"eth-storage-trie":152,"bitcoin-block":176,"bitcoin-tx":177,"bitcoin-witness-commitment":178,"zcash-block":192,"zcash-tx":193,"stellar-block":208,"stellar-tx":209,"md4":212,"md5":213,"bmt":214,"decred-block":224,"decred-tx":225,"ipld-ns":226,"ipfs-ns":227,"swarm-ns":228,"ipns-ns":229,"zeronet":230,"secp256k1-pub":231,"bls12_381-g1-pub":234,"bls12_381-g2-pub":235,"x25519-pub":236,"ed25519-pub":237,"dash-block":240,"dash-tx":241,"swarm-manifest":250,"swarm-feed":251,"udp":273,"p2p-webrtc-star":275,"p2p-webrtc-direct":276,"p2p-stardust":277,"p2p-circuit":290,"dag-json":297,"udt":301,"utp":302,"unix":400,"p2p":421,"ipfs":421,"https":443,"onion":444,"onion3":445,"garlic64":446,"garlic32":447,"tls":448,"quic":460,"ws":477,"wss":478,"p2p-websocket-star":479,"http":480,"json":512,"messagepack":513,"libp2p-peer-record":769,"sha2-256-trunc254-padded":4114,"ripemd-128":4178,"ripemd-160":4179,"ripemd-256":4180,"ripemd-320":4181,"x11":4352,"sm3-256":21325,"blake2b-8":45569,"blake2b-16":45570,"blake2b-24":45571,"blake2b-32":45572,"blake2b-40":45573,"blake2b-48":45574,"blake2b-56":45575,"blake2b-64":45576,"blake2b-72":45577,"blake2b-80":45578,"blake2b-88":45579,"blake2b-96":45580,"blake2b-104":45581,"blake2b-112":45582,"blake2b-120":45583,"blake2b-128":45584,"blake2b-136":45585,"blake2b-144":45586,"blake2b-152":45587,"blake2b-160":45588,"blake2b-168":45589,"blake2b-176":45590,"blake2b-184":45591,"blake2b-192":45592,"blake2b-200":45593,"blake2b-208":45594,"blake2b-216":45595,"blake2b-224":45596,"blake2b-232":45597,"blake2b-240":45598,"blake2b-248":45599,"blake2b-256":45600,"blake2b-264":45601,"blake2b-272":45602,"blake2b-280":45603,"blake2b-288":45604,"blake2b-296":45605,"blake2b-304":45606,"blake2b-312":45607,"blake2b-320":45608,"blake2b-328":45609,"blake2b-336":45610,"blake2b-344":45611,"blake2b-352":45612,"blake2b-360":45613,"blake2b-368":45614,"blake2b-376":45615,"blake2b-384":45616,"blake2b-392":45617,"blake2b-400":45618,"blake2b-408":45619,"blake2b-416":45620,"blake2b-424":45621,"blake2b-432":45622,"blake2b-440":45623,"blake2b-448":45624,"blake2b-456":45625,"blake2b-464":45626,"blake2b-472":45627,"blake2b-480":45628,"blake2b-488":45629,"blake2b-496":45630,"blake2b-504":45631,"blake2b-512":45632,"blake2s-8":45633,"blake2s-16":45634,"blake2s-24":45635,"blake2s-32":45636,"blake2s-40":45637,"blake2s-48":45638,"blake2s-56":45639,"blake2s-64":45640,"blake2s-72":45641,"blake2s-80":45642,"blake2s-88":45643,"blake2s-96":45644,"blake2s-104":45645,"blake2s-112":45646,"blake2s-120":45647,"blake2s-128":45648,"blake2s-136":45649,"blake2s-144":45650,"blake2s-152":45651,"blake2s-160":45652,"blake2s-168":45653,"blake2s-176":45654,"blake2s-184":45655,"blake2s-192":45656,"blake2s-200":45657,"blake2s-208":45658,"blake2s-216":45659,"blake2s-224":45660,"blake2s-232":45661,"blake2s-240":45662,"blake2s-248":45663,"blake2s-256":45664,"skein256-8":45825,"skein256-16":45826,"skein256-24":45827,"skein256-32":45828,"skein256-40":45829,"skein256-48":45830,"skein256-5Line truncated
+9
View File
@@ -0,0 +1,9 @@
'use strict'
const multicodec = require('multicodec')
const prefixedProtobuf = multicodec.addPrefix('protobuf', Buffer.from('some protobuf code'))
// eslint-disable-next-line no-console
console.log(prefixedProtobuf)
// => prefixedProtobuf 0x50...
+145
View File
@@ -0,0 +1,145 @@
{
"_from": "multicodec@^1.0.0",
"_id": "multicodec@1.0.4",
"_inBundle": false,
"_integrity": "sha512-NDd7FeS3QamVtbgfvu5h7fd1IlbaC4EQ0/pgU4zqE2vdHCmBGsUa0TiM8/TdSeG6BMPC92OOCf8F1ocE/Wkrrg==",
"_location": "/cids/multicodec",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "multicodec@^1.0.0",
"name": "multicodec",
"escapedName": "multicodec",
"rawSpec": "^1.0.0",
"saveSpec": null,
"fetchSpec": "^1.0.0"
},
"_requiredBy": [
"/cids"
],
"_resolved": "https://registry.npmjs.org/multicodec/-/multicodec-1.0.4.tgz",
"_shasum": "46ac064657c40380c28367c90304d8ed175a714f",
"_spec": "multicodec@^1.0.0",
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\BackendServers\\node_modules\\cids",
"bugs": {
"url": "https://github.com/multiformats/js-multicodec/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "David Dias",
"email": "daviddias.p@gmail.com"
},
{
"name": "Henrique Dias",
"email": "hacdias@gmail.com"
},
{
"name": "Volker Mische",
"email": "volker.mische@gmail.com"
},
{
"name": "Mikeal Rogers",
"email": "mikeal.rogers@gmail.com"
},
{
"name": "Richard Littauer",
"email": "richard.littauer@gmail.com"
},
{
"name": "wanderer",
"email": "mjbecze@gmail.com"
},
{
"name": "Friedel Ziegelmayer",
"email": "dignifiedquire@gmail.com"
},
{
"name": "Rod Vagg",
"email": "rod@vagg.org"
},
{
"name": "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ",
"email": "victorbjelkholm@gmail.com"
},
{
"name": "Filip Š",
"email": "filip.stamcar@hotmail.com"
},
{
"name": "Hugo Dias",
"email": "hugomrdias@gmail.com"
},
{
"name": "Joel Thorstensson",
"email": "oed@3box.io"
},
{
"name": "Marcin Rataj",
"email": "lidel@lidel.org"
},
{
"name": "Vasco Santos",
"email": "vasco.santos@moxy.studio"
},
{
"name": "achingbrain",
"email": "alex@achingbrain.net"
},
{
"name": "Carson Farmer",
"email": "carson.farmer@gmail.com"
}
],
"dependencies": {
"buffer": "^5.6.0",
"varint": "^5.0.0"
},
"deprecated": false,
"description": "JavaScript implementation of the multicodec specification",
"devDependencies": {
"aegir": "^23.0.0",
"bent": "^7.3.4",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"pre-push": "~0.1.1"
},
"homepage": "https://github.com/multiformats/js-multicodec#readme",
"keywords": [
"IPFS",
"multiformats",
"multicodec",
"binary",
"packed",
"the",
"data!"
],
"leadMaintainer": "Henrique Dias <hacdias@gmail.com>",
"license": "MIT",
"main": "src/index.js",
"name": "multicodec",
"pre-push": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "git+https://github.com/multiformats/js-multicodec.git"
},
"scripts": {
"build": "aegir build",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls",
"docs": "aegir docs",
"lint": "aegir lint",
"release": "aegir release",
"release-major": "aegir release --type major",
"release-minor": "aegir release --type minor",
"test": "aegir test",
"test:browser": "aegir test --target browser",
"test:node": "aegir test --target node",
"update-table": "node tools/update-table.js"
},
"version": "1.0.4"
}
+449
View File
@@ -0,0 +1,449 @@
{
"identity": 0,
"ip4": 4,
"tcp": 6,
"sha1": 17,
"sha2-256": 18,
"sha2-512": 19,
"sha3-512": 20,
"sha3-384": 21,
"sha3-256": 22,
"sha3-224": 23,
"shake-128": 24,
"shake-256": 25,
"keccak-224": 26,
"keccak-256": 27,
"keccak-384": 28,
"keccak-512": 29,
"blake3": 30,
"dccp": 33,
"murmur3-128": 34,
"murmur3-32": 35,
"ip6": 41,
"ip6zone": 42,
"path": 47,
"multicodec": 48,
"multihash": 49,
"multiaddr": 50,
"multibase": 51,
"dns": 53,
"dns4": 54,
"dns6": 55,
"dnsaddr": 56,
"protobuf": 80,
"cbor": 81,
"raw": 85,
"dbl-sha2-256": 86,
"rlp": 96,
"bencode": 99,
"dag-pb": 112,
"dag-cbor": 113,
"libp2p-key": 114,
"git-raw": 120,
"torrent-info": 123,
"torrent-file": 124,
"leofcoin-block": 129,
"leofcoin-tx": 130,
"leofcoin-pr": 131,
"sctp": 132,
"dag-jose": 133,
"dag-cose": 134,
"eth-block": 144,
"eth-block-list": 145,
"eth-tx-trie": 146,
"eth-tx": 147,
"eth-tx-receipt-trie": 148,
"eth-tx-receipt": 149,
"eth-state-trie": 150,
"eth-account-snapshot": 151,
"eth-storage-trie": 152,
"bitcoin-block": 176,
"bitcoin-tx": 177,
"bitcoin-witness-commitment": 178,
"zcash-block": 192,
"zcash-tx": 193,
"stellar-block": 208,
"stellar-tx": 209,
"md4": 212,
"md5": 213,
"bmt": 214,
"decred-block": 224,
"decred-tx": 225,
"ipld-ns": 226,
"ipfs-ns": 227,
"swarm-ns": 228,
"ipns-ns": 229,
"zeronet": 230,
"secp256k1-pub": 231,
"bls12_381-g1-pub": 234,
"bls12_381-g2-pub": 235,
"x25519-pub": 236,
"ed25519-pub": 237,
"dash-block": 240,
"dash-tx": 241,
"swarm-manifest": 250,
"swarm-feed": 251,
"udp": 273,
"p2p-webrtc-star": 275,
"p2p-webrtc-direct": 276,
"p2p-stardust": 277,
"p2p-circuit": 290,
"dag-json": 297,
"udt": 301,
"utp": 302,
"unix": 400,
"p2p": 421,
"ipfs": 421,
"https": 443,
"onion": 444,
"onion3": 445,
"garlic64": 446,
"garlic32": 447,
"tls": 448,
"quic": 460,
"ws": 477,
"wss": 478,
"p2p-websocket-star": 479,
"http": 480,
"json": 512,
"messagepack": 513,
"libp2p-peer-record": 769,
"sha2-256-trunc254-padded": 4114,
"ripemd-128": 4178,
"ripemd-160": 4179,
"ripemd-256": 4180,
"ripemd-320": 4181,
"x11": 4352,
"sm3-256": 21325,
"blake2b-8": 45569,
"blake2b-16": 45570,
"blake2b-24": 45571,
"blake2b-32": 45572,
"blake2b-40": 45573,
"blake2b-48": 45574,
"blake2b-56": 45575,
"blake2b-64": 45576,
"blake2b-72": 45577,
"blake2b-80": 45578,
"blake2b-88": 45579,
"blake2b-96": 45580,
"blake2b-104": 45581,
"blake2b-112": 45582,
"blake2b-120": 45583,
"blake2b-128": 45584,
"blake2b-136": 45585,
"blake2b-144": 45586,
"blake2b-152": 45587,
"blake2b-160": 45588,
"blake2b-168": 45589,
"blake2b-176": 45590,
"blake2b-184": 45591,
"blake2b-192": 45592,
"blake2b-200": 45593,
"blake2b-208": 45594,
"blake2b-216": 45595,
"blake2b-224": 45596,
"blake2b-232": 45597,
"blake2b-240": 45598,
"blake2b-248": 45599,
"blake2b-256": 45600,
"blake2b-264": 45601,
"blake2b-272": 45602,
"blake2b-280": 45603,
"blake2b-288": 45604,
"blake2b-296": 45605,
"blake2b-304": 45606,
"blake2b-312": 45607,
"blake2b-320": 45608,
"blake2b-328": 45609,
"blake2b-336": 45610,
"blake2b-344": 45611,
"blake2b-352": 45612,
"blake2b-360": 45613,
"blake2b-368": 45614,
"blake2b-376": 45615,
"blake2b-384": 45616,
"blake2b-392": 45617,
"blake2b-400": 45618,
"blake2b-408": 45619,
"blake2b-416": 45620,
"blake2b-424": 45621,
"blake2b-432": 45622,
"blake2b-440": 45623,
"blake2b-448": 45624,
"blake2b-456": 45625,
"blake2b-464": 45626,
"blake2b-472": 45627,
"blake2b-480": 45628,
"blake2b-488": 45629,
"blake2b-496": 45630,
"blake2b-504": 45631,
"blake2b-512": 45632,
"blake2s-8": 45633,
"blake2s-16": 45634,
"blake2s-24": 45635,
"blake2s-32": 45636,
"blake2s-40": 45637,
"blake2s-48": 45638,
"blake2s-56": 45639,
"blake2s-64": 45640,
"blake2s-72": 45641,
"blake2s-80": 45642,
"blake2s-88": 45643,
"blake2s-96": 45644,
"blake2s-104": 45645,
"blake2s-112": 45646,
"blake2s-120": 45647,
"blake2s-128": 45648,
"blake2s-136": 45649,
"blake2s-144": 45650,
"blake2s-152": 45651,
"blake2s-160": 45652,
"blake2s-168": 45653,
"blake2s-176": 45654,
"blake2s-184": 45655,
"blake2s-192": 45656,
"blake2s-200": 45657,
"blake2s-208": 45658,
"blake2s-216": 45659,
"blake2s-224": 45660,
"blake2s-232": 45661,
"blake2s-240": 45662,
"blake2s-248": 45663,
"blake2s-256": 45664,
"skein256-8": 45825,
"skein256-16": 45826,
"skein256-24": 45827,
"skein256-32": 45828,
"skein256-40": 45829,
"skein256-48": 45830,
"skein256-56": 45831,
"skein256-64": 45832,
"skein256-72": 45833,
"skein256-80": 45834,
"skein256-88": 45835,
"skein256-96": 45836,
"skein256-104": 45837,
"skein256-112": 45838,
"skein256-120": 45839,
"skein256-128": 45840,
"skein256-136": 45841,
"skein256-144": 45842,
"skein256-152": 45843,
"skein256-160": 45844,
"skein256-168": 45845,
"skein256-176": 45846,
"skein256-184": 45847,
"skein256-192": 45848,
"skein256-200": 45849,
"skein256-208": 45850,
"skein256-216": 45851,
"skein256-224": 45852,
"skein256-232": 45853,
"skein256-240": 45854,
"skein256-248": 45855,
"skein256-256": 45856,
"skein512-8": 45857,
"skein512-16": 45858,
"skein512-24": 45859,
"skein512-32": 45860,
"skein512-40": 45861,
"skein512-48": 45862,
"skein512-56": 45863,
"skein512-64": 45864,
"skein512-72": 45865,
"skein512-80": 45866,
"skein512-88": 45867,
"skein512-96": 45868,
"skein512-104": 45869,
"skein512-112": 45870,
"skein512-120": 45871,
"skein512-128": 45872,
"skein512-136": 45873,
"skein512-144": 45874,
"skein512-152": 45875,
"skein512-160": 45876,
"skein512-168": 45877,
"skein512-176": 45878,
"skein512-184": 45879,
"skein512-192": 45880,
"skein512-200": 45881,
"skein512-208": 45882,
"skein512-216": 45883,
"skein512-224": 45884,
"skein512-232": 45885,
"skein512-240": 45886,
"skein512-248": 45887,
"skein512-256": 45888,
"skein512-264": 45889,
"skein512-272": 45890,
"skein512-280": 45891,
"skein512-288": 45892,
"skein512-296": 45893,
"skein512-304": 45894,
"skein512-312": 45895,
"skein512-320": 45896,
"skein512-328": 45897,
"skein512-336": 45898,
"skein512-344": 45899,
"skein512-352": 45900,
"skein512-360": 45901,
"skein512-368": 45902,
"skein512-376": 45903,
"skein512-384": 45904,
"skein512-392": 45905,
"skein512-400": 45906,
"skein512-408": 45907,
"skein512-416": 45908,
"skein512-424": 45909,
"skein512-432": 45910,
"skein512-440": 45911,
"skein512-448": 45912,
"skein512-456": 45913,
"skein512-464": 45914,
"skein512-472": 45915,
"skein512-480": 45916,
"skein512-488": 45917,
"skein512-496": 45918,
"skein512-504": 45919,
"skein512-512": 45920,
"skein1024-8": 45921,
"skein1024-16": 45922,
"skein1024-24": 45923,
"skein1024-32": 45924,
"skein1024-40": 45925,
"skein1024-48": 45926,
"skein1024-56": 45927,
"skein1024-64": 45928,
"skein1024-72": 45929,
"skein1024-80": 45930,
"skein1024-88": 45931,
"skein1024-96": 45932,
"skein1024-104": 45933,
"skein1024-112": 45934,
"skein1024-120": 45935,
"skein1024-128": 45936,
"skein1024-136": 45937,
"skein1024-144": 45938,
"skein1024-152": 45939,
"skein1024-160": 45940,
"skein1024-168": 45941,
"skein1024-176": 45942,
"skein1024-184": 45943,
"skein1024-192": 45944,
"skein1024-200": 45945,
"skein1024-208": 45946,
"skein1024-216": 45947,
"skein1024-224": 45948,
"skein1024-232": 45949,
"skein1024-240": 45950,
"skein1024-248": 45951,
"skein1024-256": 45952,
"skein1024-264": 45953,
"skein1024-272": 45954,
"skein1024-280": 45955,
"skein1024-288": 45956,
"skein1024-296": 45957,
"skein1024-304": 45958,
"skein1024-312": 45959,
"skein1024-320": 45960,
"skein1024-328": 45961,
"skein1024-336": 45962,
"skein1024-344": 45963,
"skein1024-352": 45964,
"skein1024-360": 45965,
"skein1024-368": 45966,
"skein1024-376": 45967,
"skein1024-384": 45968,
"skein1024-392": 45969,
"skein1024-400": 45970,
"skein1024-408": 45971,
"skein1024-416": 45972,
"skein1024-424": 45973,
"skein1024-432": 45974,
"skein1024-440": 45975,
"skein1024-448": 45976,
"skein1024-456": 45977,
"skein1024-464": 45978,
"skein1024-472": 45979,
"skein1024-480": 45980,
"skein1024-488": 45981,
"skein1024-496": 45982,
"skein1024-504": 45983,
"skein1024-512": 45984,
"skein1024-520": 45985,
"skein1024-528": 45986,
"skein1024-536": 45987,
"skein1024-544": 45988,
"skein1024-552": 45989,
"skein1024-560": 45990,
"skein1024-568": 45991,
"skein1024-576": 45992,
"skein1024-584": 45993,
"skein1024-592": 45994,
"skein1024-600": 45995,
"skein1024-608": 45996,
"skein1024-616": 45997,
"skein1024-624": 45998,
"skein1024-632": 45999,
"skein1024-640": 46000,
"skein1024-648": 46001,
"skein1024-656": 46002,
"skein1024-664": 46003,
"skein1024-672": 46004,
"skein1024-680": 46005,
"skein1024-688": 46006,
"skein1024-696": 46007,
"skein1024-704": 46008,
"skein1024-712": 46009,
"skein1024-720": 46010,
"skein1024-728": 46011,
"skein1024-736": 46012,
"skein1024-744": 46013,
"skein1024-752": 46014,
"skein1024-760": 46015,
"skein1024-768": 46016,
"skein1024-776": 46017,
"skein1024-784": 46018,
"skein1024-792": 46019,
"skein1024-800": 46020,
"skein1024-808": 46021,
"skein1024-816": 46022,
"skein1024-824": 46023,
"skein1024-832": 46024,
"skein1024-840": 46025,
"skein1024-848": 46026,
"skein1024-856": 46027,
"skein1024-864": 46028,
"skein1024-872": 46029,
"skein1024-880": 46030,
"skein1024-888": 46031,
"skein1024-896": 46032,
"skein1024-904": 46033,
"skein1024-912": 46034,
"skein1024-920": 46035,
"skein1024-928": 46036,
"skein1024-936": 46037,
"skein1024-944": 46038,
"skein1024-952": 46039,
"skein1024-960": 46040,
"skein1024-968": 46041,
"skein1024-976": 46042,
"skein1024-984": 46043,
"skein1024-992": 46044,
"skein1024-1000": 46045,
"skein1024-1008": 46046,
"skein1024-1016": 46047,
"skein1024-1024": 46048,
"poseidon-bls12_381-a2-fc1": 46081,
"poseidon-bls12_381-a2-fc1-sc": 46082,
"zeroxcert-imprint-256": 52753,
"fil-commitment-unsealed": 61697,
"fil-commitment-sealed": 61698,
"holochain-adr-v0": 8417572,
"holochain-adr-v1": 8483108,
"holochain-key-v0": 9728292,
"holochain-key-v1": 9793828,
"holochain-sig-v0": 10645796,
"holochain-sig-v1": 10711332
}
+12
View File
@@ -0,0 +1,12 @@
'use strict'
const table = require('./base-table.json')
// map for codecConstant -> code
const constants = {}
for (const [name, code] of Object.entries(table)) {
constants[name.toUpperCase().replace(/-/g, '_')] = code
}
module.exports = Object.freeze(constants)
+127
View File
@@ -0,0 +1,127 @@
/**
* Implementation of the multicodec specification.
*
* @module multicodec
* @example
* const multicodec = require('multicodec')
*
* const prefixedProtobuf = multicodec.addPrefix('protobuf', protobufBuffer)
* // prefixedProtobuf 0x50...
*
*/
'use strict'
const { Buffer } = require('buffer')
const varint = require('varint')
const intTable = require('./int-table')
const codecNameToCodeVarint = require('./varint-table')
const util = require('./util')
exports = module.exports
/**
* Prefix a buffer with a multicodec-packed.
*
* @param {string|number} multicodecStrOrCode
* @param {Buffer} data
* @returns {Buffer}
*/
exports.addPrefix = (multicodecStrOrCode, data) => {
let prefix
if (Buffer.isBuffer(multicodecStrOrCode)) {
prefix = util.varintBufferEncode(multicodecStrOrCode)
} else {
if (codecNameToCodeVarint[multicodecStrOrCode]) {
prefix = codecNameToCodeVarint[multicodecStrOrCode]
} else {
throw new Error('multicodec not recognized')
}
}
return Buffer.concat([prefix, data])
}
/**
* Decapsulate the multicodec-packed prefix from the data.
*
* @param {Buffer} data
* @returns {Buffer}
*/
exports.rmPrefix = (data) => {
varint.decode(data)
return data.slice(varint.decode.bytes)
}
/**
* Get the codec of the prefixed data.
* @param {Buffer} prefixedData
* @returns {string}
*/
exports.getCodec = (prefixedData) => {
const code = varint.decode(prefixedData)
const codecName = intTable.get(code)
if (codecName === undefined) {
throw new Error(`Code ${code} not found`)
}
return codecName
}
/**
* Get the name of the codec.
* @param {number} codec
* @returns {string}
*/
exports.getName = (codec) => {
return intTable.get(codec)
}
/**
* Get the code of the codec
* @param {string} name
* @returns {number}
*/
exports.getNumber = (name) => {
const code = codecNameToCodeVarint[name]
if (code === undefined) {
throw new Error('Codec `' + name + '` not found')
}
return util.varintBufferDecode(code)[0]
}
/**
* Get the code of the prefixed data.
* @param {Buffer} prefixedData
* @returns {number}
*/
exports.getCode = (prefixedData) => {
return varint.decode(prefixedData)
}
/**
* Get the code as varint of a codec name.
* @param {string} codecName
* @returns {Buffer}
*/
exports.getCodeVarint = (codecName) => {
const code = codecNameToCodeVarint[codecName]
if (code === undefined) {
throw new Error('Codec `' + codecName + '` not found')
}
return code
}
/**
* Get the varint of a code.
* @param {Number} code
* @returns {Array.<number>}
*/
exports.getVarint = (code) => {
return varint.encode(code)
}
// Make the constants top-level constants
const constants = require('./constants')
Object.assign(exports, constants)
// Human friendly names for printing, e.g. in error messages
exports.print = require('./print')
+12
View File
@@ -0,0 +1,12 @@
'use strict'
const baseTable = require('./base-table.json')
// map for hexString -> codecName
const nameTable = new Map()
for (const encodingName in baseTable) {
const code = baseTable[encodingName]
nameTable.set(code, encodingName)
}
module.exports = Object.freeze(nameTable)
+12
View File
@@ -0,0 +1,12 @@
'use strict'
const table = require('./base-table.json')
// map for code -> print friendly name
const tableByCode = {}
for (const [name, code] of Object.entries(table)) {
if (tableByCode[code] === undefined) tableByCode[code] = name
}
module.exports = Object.freeze(tableByCode)
+35
View File
@@ -0,0 +1,35 @@
'use strict'
const varint = require('varint')
const { Buffer } = require('buffer')
module.exports = {
numberToBuffer,
bufferToNumber,
varintBufferEncode,
varintBufferDecode,
varintEncode
}
function bufferToNumber (buf) {
return parseInt(buf.toString('hex'), 16)
}
function numberToBuffer (num) {
let hexString = num.toString(16)
if (hexString.length % 2 === 1) {
hexString = '0' + hexString
}
return Buffer.from(hexString, 'hex')
}
function varintBufferEncode (input) {
return Buffer.from(varint.encode(bufferToNumber(input)))
}
function varintBufferDecode (input) {
return numberToBuffer(varint.decode(input))
}
function varintEncode (num) {
return Buffer.from(varint.encode(num))
}
+14
View File
@@ -0,0 +1,14 @@
'use strict'
const baseTable = require('./base-table.json')
const varintEncode = require('./util').varintEncode
// map for codecName -> codeVarintBuffer
const varintTable = {}
for (const encodingName in baseTable) {
const code = baseTable[encodingName]
varintTable[encodingName] = varintEncode(code)
}
module.exports = Object.freeze(varintTable)
+30
View File
@@ -0,0 +1,30 @@
'use strict'
const bent = require('bent')
const path = require('path')
const get = bent('string')
const url = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv'
const fs = require('fs')
const parse = async function * () {
const str = await get(url)
const lines = str.split('\n')
lines.shift()
for (const line of lines) {
if (!line.length) continue
const [name, tag, code] = line.split(',')
yield { name: name.trim(), tag: tag.trim(), code: parseInt(code.trim(), 16) }
}
}
const run = async () => {
const table = {}
for await (const { name, code } of parse()) {
table[name] = code
}
fs.writeFileSync(path.join(__dirname, '../src/base-table.json'), JSON.stringify(table, null, 2))
}
run()
+174
View File
@@ -0,0 +1,174 @@
{
"_from": "cids@^0.7.1",
"_id": "cids@0.7.5",
"_inBundle": false,
"_integrity": "sha512-zT7mPeghoWAu+ppn8+BS1tQ5qGmbMfB4AregnQjA/qHY3GC1m1ptI9GkWNlgeu38r7CuRdXB47uY2XgAYt6QVA==",
"_location": "/cids",
"_phantomChildren": {
"buffer": "5.7.1",
"varint": "5.0.2"
},
"_requested": {
"type": "range",
"registry": true,
"raw": "cids@^0.7.1",
"name": "cids",
"escapedName": "cids",
"rawSpec": "^0.7.1",
"saveSpec": null,
"fetchSpec": "^0.7.1"
},
"_requiredBy": [
"/content-hash"
],
"_resolved": "https://registry.npmjs.org/cids/-/cids-0.7.5.tgz",
"_shasum": "60a08138a99bfb69b6be4ceb63bfef7a396b28b2",
"_spec": "cids@^0.7.1",
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\BackendServers\\node_modules\\content-hash",
"bugs": {
"url": "https://github.com/multiformats/js-cid/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Alan Shaw",
"email": "alan.shaw@protocol.ai"
},
{
"name": "Alan Shaw",
"email": "alan@tableflip.io"
},
{
"name": "Carson Farmer",
"email": "carson.farmer@gmail.com"
},
{
"name": "David Dias",
"email": "daviddias.p@gmail.com"
},
{
"name": "Enrico Marino",
"email": "enrico.marino@email.com"
},
{
"name": "Friedel Ziegelmayer",
"email": "dignifiedquire@gmail.com"
},
{
"name": "Henrique Dias",
"email": "hacdias@gmail.com"
},
{
"name": "Hugo Dias",
"email": "hugomrdias@gmail.com"
},
{
"name": "Irakli Gozalishvili",
"email": "contact@gozala.io"
},
{
"name": "Irakli Gozalishvili",
"email": "rfobic@gmail.com"
},
{
"name": "Marcin Rataj",
"email": "lidel@lidel.org"
},
{
"name": "Mikeal Rogers",
"email": "mikeal.rogers@gmail.com"
},
{
"name": "Mitar",
"email": "mitar.github@tnode.com"
},
{
"name": "Oli Evans",
"email": "oli@tableflip.io"
},
{
"name": "Real Harry",
"email": "sidewaybot@gmail.com"
},
{
"name": "Richard Littauer",
"email": "richard.littauer@gmail.com"
},
{
"name": "Rod Vagg",
"email": "rod@vagg.org"
},
{
"name": "Victor Bjelkholm",
"email": "victorbjelkholm@gmail.com"
},
{
"name": "Volker Mische",
"email": "volker.mische@gmail.com"
},
{
"name": "bluelovers",
"email": "codelovers@users.sourceforge.net"
},
{
"name": "greenkeeper[bot]",
"email": "greenkeeper[bot]@users.noreply.github.com"
},
{
"name": "kumavis",
"email": "kumavis@users.noreply.github.com"
}
],
"dependencies": {
"buffer": "^5.5.0",
"class-is": "^1.1.0",
"multibase": "~0.6.0",
"multicodec": "^1.0.0",
"multihashes": "~0.4.15"
},
"deprecated": false,
"description": "CID Implementation in JavaScript",
"devDependencies": {
"aegir": "^21.3.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"multihashing": "~0.3.3",
"multihashing-async": "~0.8.0"
},
"engines": {
"node": ">=4.0.0",
"npm": ">=3.0.0"
},
"homepage": "https://github.com/multiformats/js-cid#readme",
"keywords": [
"multihash",
"cid",
"ipld"
],
"leadMaintainer": "Volker Mische <volker.mische@gmail.com>",
"license": "MIT",
"main": "src/index.js",
"name": "cids",
"pre-push": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "git://github.com/multiformats/js-cid.git"
},
"scripts": {
"build": "aegir build",
"coverage": "aegir coverage",
"docs": "aegir docs",
"lint": "aegir lint",
"release": "aegir release --docs",
"release-major": "aegir release --type major --docs",
"release-minor": "aegir release --type minor --docs",
"test": "aegir test",
"test:browser": "aegir test --target browser",
"test:node": "aegir test --target node"
},
"types": "src/index.d.ts",
"version": "0.7.5"
}
+52
View File
@@ -0,0 +1,52 @@
'use strict'
const mh = require('multihashes')
const { Buffer } = require('buffer')
var CIDUtil = {
/**
* Test if the given input is a valid CID object.
* Returns an error message if it is not.
* Returns undefined if it is a valid CID.
*
* @param {any} other
* @returns {string}
*/
checkCIDComponents: function (other) {
if (other == null) {
return 'null values are not valid CIDs'
}
if (!(other.version === 0 || other.version === 1)) {
return 'Invalid version, must be a number equal to 1 or 0'
}
if (typeof other.codec !== 'string') {
return 'codec must be string'
}
if (other.version === 0) {
if (other.codec !== 'dag-pb') {
return "codec must be 'dag-pb' for CIDv0"
}
if (other.multibaseName !== 'base58btc') {
return "multibaseName must be 'base58btc' for CIDv0"
}
}
if (!Buffer.isBuffer(other.multihash)) {
return 'multihash must be a Buffer'
}
try {
mh.validate(other.multihash)
} catch (err) {
let errorMsg = err.message
if (!errorMsg) { // Just in case mh.validate() throws an error with empty error message
errorMsg = 'Multihash validation failed'
}
return errorMsg
}
}
}
module.exports = CIDUtil
+308
View File
@@ -0,0 +1,308 @@
'use strict'
const { Buffer } = require('buffer')
const mh = require('multihashes')
const multibase = require('multibase')
const multicodec = require('multicodec')
const codecs = require('multicodec/src/base-table.json')
const CIDUtil = require('./cid-util')
const withIs = require('class-is')
/**
* @typedef {Object} SerializedCID
* @param {string} codec
* @param {number} version
* @param {Buffer} multihash
*/
/**
* Test if the given input is a CID.
* @function isCID
* @memberof CID
* @static
* @param {any} other
* @returns {bool}
*/
/**
* Class representing a CID `<mbase><version><mcodec><mhash>`
* , as defined in [ipld/cid](https://github.com/multiformats/cid).
* @class CID
*/
class CID {
/**
* Create a new CID.
*
* The algorithm for argument input is roughly:
* ```
* if (cid)
* -> create a copy
* else if (str)
* if (1st char is on multibase table) -> CID String
* else -> bs58 encoded multihash
* else if (Buffer)
* if (1st byte is 0 or 1) -> CID
* else -> multihash
* else if (Number)
* -> construct CID by parts
* ```
*
* @param {string|Buffer|CID} version
* @param {string} [codec]
* @param {Buffer} [multihash]
* @param {string} [multibaseName]
*
* @example
* new CID(<version>, <codec>, <multihash>, <multibaseName>)
* new CID(<cidStr>)
* new CID(<cid.buffer>)
* new CID(<multihash>)
* new CID(<bs58 encoded multihash>)
* new CID(<cid>)
*/
constructor (version, codec, multihash, multibaseName) {
if (_CID.isCID(version)) {
// version is an exising CID instance
const cid = version
this.version = cid.version
this.codec = cid.codec
this.multihash = Buffer.from(cid.multihash)
// Default guard for when a CID < 0.7 is passed with no multibaseName
this.multibaseName = cid.multibaseName || (cid.version === 0 ? 'base58btc' : 'base32')
return
}
if (typeof version === 'string') {
// e.g. 'base32' or false
const baseName = multibase.isEncoded(version)
if (baseName) {
// version is a CID String encoded with multibase, so v1
const cid = multibase.decode(version)
this.version = parseInt(cid.slice(0, 1).toString('hex'), 16)
this.codec = multicodec.getCodec(cid.slice(1))
this.multihash = multicodec.rmPrefix(cid.slice(1))
this.multibaseName = baseName
} else {
// version is a base58btc string multihash, so v0
this.version = 0
this.codec = 'dag-pb'
this.multihash = mh.fromB58String(version)
this.multibaseName = 'base58btc'
}
CID.validateCID(this)
Object.defineProperty(this, 'string', { value: version })
return
}
if (Buffer.isBuffer(version)) {
const firstByte = version.slice(0, 1)
const v = parseInt(firstByte.toString('hex'), 16)
if (v === 1) {
// version is a CID buffer
const cid = version
this.version = v
this.codec = multicodec.getCodec(cid.slice(1))
this.multihash = multicodec.rmPrefix(cid.slice(1))
this.multibaseName = 'base32'
} else {
// version is a raw multihash buffer, so v0
this.version = 0
this.codec = 'dag-pb'
this.multihash = version
this.multibaseName = 'base58btc'
}
CID.validateCID(this)
return
}
// otherwise, assemble the CID from the parameters
/**
* @type {number}
*/
this.version = version
/**
* @type {string}
*/
this.codec = codec
/**
* @type {Buffer}
*/
this.multihash = multihash
/**
* @type {string}
*/
this.multibaseName = multibaseName || (version === 0 ? 'base58btc' : 'base32')
CID.validateCID(this)
}
/**
* The CID as a `Buffer`
*
* @return {Buffer}
* @readonly
*
* @memberOf CID
*/
get buffer () {
let buffer = this._buffer
if (!buffer) {
if (this.version === 0) {
buffer = this.multihash
} else if (this.version === 1) {
buffer = Buffer.concat([
Buffer.from('01', 'hex'),
multicodec.getCodeVarint(this.codec),
this.multihash
])
} else {
throw new Error('unsupported version')
}
// Cache this buffer so it doesn't have to be recreated
Object.defineProperty(this, '_buffer', { value: buffer })
}
return buffer
}
/**
* Get the prefix of the CID.
*
* @returns {Buffer}
* @readonly
*/
get prefix () {
return Buffer.concat([
Buffer.from(`0${this.version}`, 'hex'),
multicodec.getCodeVarint(this.codec),
mh.prefix(this.multihash)
])
}
/**
* Convert to a CID of version `0`.
*
* @returns {CID}
*/
toV0 () {
if (this.codec !== 'dag-pb') {
throw new Error('Cannot convert a non dag-pb CID to CIDv0')
}
const { name, length } = mh.decode(this.multihash)
if (name !== 'sha2-256') {
throw new Error('Cannot convert non sha2-256 multihash CID to CIDv0')
}
if (length !== 32) {
throw new Error('Cannot convert non 32 byte multihash CID to CIDv0')
}
return new _CID(0, this.codec, this.multihash)
}
/**
* Convert to a CID of version `1`.
*
* @returns {CID}
*/
toV1 () {
return new _CID(1, this.codec, this.multihash)
}
/**
* Encode the CID into a string.
*
* @param {string} [base=this.multibaseName] - Base encoding to use.
* @returns {string}
*/
toBaseEncodedString (base = this.multibaseName) {
if (this.string && base === this.multibaseName) {
return this.string
}
let str = null
if (this.version === 0) {
if (base !== 'base58btc') {
throw new Error('not supported with CIDv0, to support different bases, please migrate the instance do CIDv1, you can do that through cid.toV1()')
}
str = mh.toB58String(this.multihash)
} else if (this.version === 1) {
str = multibase.encode(base, this.buffer).toString()
} else {
throw new Error('unsupported version')
}
if (base === this.multibaseName) {
// cache the string value
Object.defineProperty(this, 'string', { value: str })
}
return str
}
/**
* CID(QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n)
*
* @returns {String}
*/
[Symbol.for('nodejs.util.inspect.custom')] () {
return 'CID(' + this.toString() + ')'
}
toString (base) {
return this.toBaseEncodedString(base)
}
/**
* Serialize to a plain object.
*
* @returns {SerializedCID}
*/
toJSON () {
return {
codec: this.codec,
version: this.version,
hash: this.multihash
}
}
/**
* Compare equality with another CID.
*
* @param {CID} other
* @returns {bool}
*/
equals (other) {
return this.codec === other.codec &&
this.version === other.version &&
this.multihash.equals(other.multihash)
}
/**
* Test if the given input is a valid CID object.
* Throws if it is not.
*
* @param {any} other
* @returns {void}
*/
static validateCID (other) {
const errorMsg = CIDUtil.checkCIDComponents(other)
if (errorMsg) {
throw new Error(errorMsg)
}
}
}
const _CID = withIs(CID, {
className: 'CID',
symbolName: '@ipld/js-cid/CID'
})
_CID.codecs = codecs
module.exports = _CID