Skip to content

Commit

Permalink
Run yarn format
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Sep 25, 2019
1 parent 6e7f5e9 commit 6c2ef1c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/base16.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const encoding = {
bits: 4
}

export function parse (string, opts) {
export function parse(string, opts) {
return codec.parse(string.toUpperCase(), encoding, opts)
}

export function stringify (data, opts) {
export function stringify(data, opts) {
return codec.stringify(data, encoding, opts)
}
12 changes: 6 additions & 6 deletions src/base32.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ const encoding = {
bits: 5
}

export function parse (string, opts = {}) {
export function parse(string, opts = {}) {
return codec.parse(
opts.loose
? string
.toUpperCase()
.replace(/0/g, 'O')
.replace(/1/g, 'L')
.replace(/8/g, 'B')
.toUpperCase()
.replace(/0/g, 'O')
.replace(/1/g, 'L')
.replace(/8/g, 'B')
: string,
encoding,
opts
)
}

export function stringify (data, opts) {
export function stringify(data, opts) {
return codec.stringify(data, encoding, opts)
}
4 changes: 2 additions & 2 deletions src/base32hex.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const encoding = {
bits: 5
}

export function parse (string, opts) {
export function parse(string, opts) {
return codec.parse(string, encoding, opts)
}

export function stringify (data, opts) {
export function stringify(data, opts) {
return codec.stringify(data, encoding, opts)
}
4 changes: 2 additions & 2 deletions src/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const encoding = {
bits: 6
}

export function parse (string, opts) {
export function parse(string, opts) {
return codec.parse(string, encoding, opts)
}

export function stringify (data, opts) {
export function stringify(data, opts) {
return codec.stringify(data, encoding, opts)
}
4 changes: 2 additions & 2 deletions src/base64url.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const encoding = {
bits: 6
}

export function parse (string, opts) {
export function parse(string, opts) {
return codec.parse(string, encoding, opts)
}

export function stringify (data, opts) {
export function stringify(data, opts) {
return codec.stringify(data, encoding, opts)
}
4 changes: 2 additions & 2 deletions src/codec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function parse (string, encoding, opts = {}) {
export function parse(string, encoding, opts = {}) {
// Build the character lookup table:
if (!encoding.codes) {
encoding.codes = {}
Expand Down Expand Up @@ -56,7 +56,7 @@ export function parse (string, encoding, opts = {}) {
return out
}

export function stringify (data, encoding, opts = {}) {
export function stringify(data, encoding, opts = {}) {
const { pad = true } = opts
const mask = (1 << encoding.bits) - 1
let out = ''
Expand Down
30 changes: 15 additions & 15 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ const {
base64url
} = require('../lib/index.cjs.js')

function parseAscii (string) {
function parseAscii(string) {
const out = new Uint8Array(string.length)
for (let i = 0; i < string.length; ++i) {
out[i] = string.charCodeAt(i)
}
return out
}

function generateTests (codec, vectors) {
function generateTests(codec, vectors) {
for (const [data, text] of vectors) {
it(`round-trips "${text}"`, function () {
it(`round-trips "${text}"`, function() {
const expected =
typeof data === 'string' ? parseAscii(data) : Uint8Array.from(data)
expect(codec.stringify(expected)).equals(text)
Expand All @@ -28,15 +28,15 @@ function generateTests (codec, vectors) {
}
}

function generateErrorTests (codec, vectors) {
function generateErrorTests(codec, vectors) {
for (const [text, error, loose] of vectors) {
if (loose == null || typeof loose === 'string') {
it(`rejects "${text}"`, function () {
it(`rejects "${text}"`, function() {
expect(() => codec.parse(text)).throws(error)
expect(() => codec.parse(text, { loose: true })).throws(loose || error)
})
} else {
it(`loosely parses "${text}"`, function () {
it(`loosely parses "${text}"`, function() {
const expected = Uint8Array.from(loose)
expect(() => codec.parse(text)).throws(error)
expect(codec.parse(text, { loose: true })).deep.equals(expected)
Expand All @@ -45,7 +45,7 @@ function generateErrorTests (codec, vectors) {
}
}

describe('base16', function () {
describe('base16', function() {
generateTests(base16, [
['', ''],
['f', '66'],
Expand All @@ -64,18 +64,18 @@ describe('base16', function () {
['00=', 'Invalid padding', [0x00]]
])

it('decodes lowercase characters', function () {
it('decodes lowercase characters', function() {
const expected = Uint8Array.from([0xab, 0xcd, 0xef])
expect(base16.parse('abcdef')).deep.equals(expected)
})

it('works with plain arrays', function () {
it('works with plain arrays', function() {
const expected = [0xab, 0xcd, 0xef]
expect(base16.parse('abcdef', { out: Array })).deep.equals(expected)
})
})

describe('base32', function () {
describe('base32', function() {
generateTests(base32, [
// rfc4648:
['', ''],
Expand Down Expand Up @@ -116,14 +116,14 @@ describe('base32', function () {
['AAAAAAAA========', 'Invalid padding', [0, 0, 0, 0, 0]]
])

it('Fixes common typos in loose mode', function () {
it('Fixes common typos in loose mode', function() {
expect(base32.parse('He1l0===', { loose: true })).deep.equals(
base32.parse('HELLO===')
)
})
})

describe('base32hex', function () {
describe('base32hex', function() {
generateTests(base32hex, [
// rfc4648:
['', ''],
Expand All @@ -145,7 +145,7 @@ describe('base32hex', function () {
])
})

describe('base64', function () {
describe('base64', function() {
generateTests(base64, [
// rfc4648:
['', ''],
Expand Down Expand Up @@ -187,10 +187,10 @@ describe('base64', function () {
])
})

describe('base64url', function () {
describe('base64url', function() {
generateTests(base64url, [[[0xfb, 0xff], '-_8=']])

it('should work without padding', function () {
it('should work without padding', function() {
expect(base64url.stringify([0x00], { pad: false })).equals('AA')
})
})

0 comments on commit 6c2ef1c

Please sign in to comment.