You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 24, 2021. It is now read-only.
- adds support for all the encodings in https://github.com/multiformats/multibase/blob/master/multibase.csv
- better errors showing the invalid chars and inputs
- `names` and `codes` exports the full object that maps names/codes to base instances
- you can use these to get the unprefixed base encoder/decoder
- two new methods exported, `encoding` and `encodingFromData`
- you can use these to get the unprefixed base encoder/decoder
- adds all the spec tests https://github.com/multiformats/multibase/tree/master/tests
- its also faster check benchmarks below
This module now only uses 2 base encoding implementations, 1 generalised rfc4648 and 1 generalised btc like.
closes#49closes#38closes#46closes#53closes#26
BREAKING CHANGE: `names` and `codes` export the full object that maps names/codes to base instances instead of just the keys
Copy file name to clipboardexpand all lines: README.md
+22-92
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,8 @@ js-multibase
17
17
## Table of Contents
18
18
19
19
-[Install](#install)
20
-
-[In Node.js through npm](#in-nodejs-through-npm)
21
-
-[Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
20
+
-[NPM](#npm)
22
21
-[In the Browser through `<script>` tag](#in-the-browser-through-script-tag)
23
-
-[Gotchas](#gotchas)
24
22
-[Usage](#usage)
25
23
-[Example](#example)
26
24
-[API](#api)
@@ -37,10 +35,10 @@ js-multibase
37
35
38
36
## Install
39
37
40
-
### In Node.js through npm
38
+
### NPM
41
39
42
-
```bash
43
-
> npm install --save multibase
40
+
```sh
41
+
$ npm install --save multibase
44
42
```
45
43
46
44
The type definitions for this package are available on http://definitelytyped.org/. To install just use:
@@ -49,23 +47,12 @@ The type definitions for this package are available on http://definitelytyped.or
49
47
$ npm install -D @types/multibase
50
48
```
51
49
52
-
### Browser: Browserify, Webpack, other bundlers
53
-
54
-
The code published to npm that gets loaded on require is in fact an ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
55
-
56
-
```js
57
-
constmultibase=require('multibase')
58
-
```
59
-
60
-
61
50
### In the Browser through `<script>` tag
62
51
63
52
Loading this module through a script tag will make the ```Multibase``` obj available in the global namespace.
### `multibase.decode` - Decodes a buffer or string
88
+
####`multibase.decode` - Decodes a buffer or string
102
89
103
90
```JavaScript
104
91
constdecodedBuf=multibase.decode(bufOrString)
105
92
```
106
93
107
-
### `multibase.isEncoded` - Checks if buffer or string is encoded
94
+
####`multibase.isEncoded` - Checks if buffer or string is encoded
108
95
109
96
```JavaScript
110
97
constvalue=multibase.isEncoded(bufOrString)
111
98
// value is the name of the encoding if it is encoded, false otherwise
112
99
```
113
100
114
-
### `multibase.names`
115
-
116
-
A frozen `Array` of supported base encoding names.
117
-
118
-
### `multibase.codes`
119
-
120
-
A frozen `Array` of supported base encoding codes.
101
+
#### `multibase.encoding` - Get the encoding by name or code
121
102
122
-
### Supported Encodings, see [`src/constants.js`](/src/constants.js)
123
-
124
-
## Architecture and Encoding/Decoding
125
-
126
-
Multibase package defines all the supported bases and the location of their implementation in the constants.js file. A base is a class with a name, a code, an implementation and an alphabet.
// value is an instance of the corresponding `Base`
134
106
```
135
-
The ```implementation``` is an object where the encoding/decoding functions are implemented. It must take one argument, (the alphabet) following the [base-x module](https://github.com/cryptocoinjs/base-x) architecture.
136
-
137
-
The ```alphabet``` is the **ordered** set of defined symbols for a given base.
138
107
139
-
The idea behind this is that several bases may have implementations from different locations/modules so it's useful to have an object (and a summary) of all of them in one location (hence the constants.js).
108
+
#### `multibase.encodingFromData` - Get the encoding from data either a `string` or `Buffer`
140
109
141
-
All the supported bases are currently using the npm [base-x](https://github.com/cryptocoinjs/base-x) module as their implementation. It is using bitwise maipulation to go from one base to another, so this module does not support padding at the moment.
110
+
```JavaScript
111
+
constvalue=multibase.encodingFromData(data)
112
+
// value is an instance of the corresponding `Base`
113
+
```
142
114
143
-
##Adding additional bases
115
+
#### `multibase.names`
144
116
145
-
If the base you are looking for is not supported yet in js-multibase and you know a good encoding/decoding algorithm, you can add support for this base easily by editing the constants.js file
146
-
(**you'll need to create an issue about that beforehand since a code and a canonical name have to be defined**):
117
+
A frozen `Object` of supported base encoding names mapped to the corresponding `Base` instance.
0 commit comments