Skip to content

Commit

Permalink
Upgrade to Standard v14
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Mar 30, 2020
1 parent 94009ab commit 48b4cdc
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 86 deletions.
14 changes: 7 additions & 7 deletions examples/clientsideserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ var Image = Canvas.Image

var path = require('path')

// app.use(express.methodOverride())
// app.use(express.bodyParser())
// app.use(app.router)
// app.use(express.static(path.resolve(__dirname, '..')))
// app.use(express.methodOverride())
// app.use(express.bodyParser())
// app.use(app.router)
// app.use(express.static(path.resolve(__dirname, '..')))

app.get('/qrcode.js', (req, res) => {
res.set('content-type', 'text/javascript')
Expand Down Expand Up @@ -162,7 +162,7 @@ effectHandlers.rounded = function (args, cb) {
}
}
})
cb(false, canvas)
cb(null, canvas)
})
}

Expand Down Expand Up @@ -210,7 +210,7 @@ effectHandlers.remoteImage = function (args, cb) {
})

res.on('complete', function () {
cb(false, data)
cb(null, data)
})

res.on('error', function (error) {
Expand Down Expand Up @@ -292,7 +292,7 @@ effectHandlers.image = function (args, cb) {
cb(err, false)
}

cb(false, baconCanvas)
cb(null, baconCanvas)
})
}

Expand Down
2 changes: 1 addition & 1 deletion lib/core/alignment-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ exports.getPositions = function getPositions (version) {
for (var i = 0; i < posLength; i++) {
for (var j = 0; j < posLength; j++) {
// Skip if position is occupied by finder patterns
if ((i === 0 && j === 0) || // top-left
if ((i === 0 && j === 0) || // top-left
(i === 0 && j === posLength - 1) || // bottom-left
(i === posLength - 1 && j === 0)) { // top-right
continue
Expand Down
6 changes: 2 additions & 4 deletions lib/core/qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
var rawSegments = Segments.rawSplit(data)

// Estimate best version that can contain raw splitted segments
estimatedVersion = Version.getBestVersionForData(rawSegments,
errorCorrectionLevel)
estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel)
}

// Build optimized segments
Expand All @@ -400,8 +399,7 @@ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
}

// Get the min version that can contain data
var bestVersion = Version.getBestVersionForData(segments,
errorCorrectionLevel)
var bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel)

// If no version is found, data cannot be stored
if (!bestVersion) {
Expand Down
4 changes: 2 additions & 2 deletions lib/core/segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function buildNodes (segs) {
*/
function buildGraph (nodes, version) {
var table = {}
var graph = {'start': {}}
var graph = { start: {} }
var prevNodeIds = ['start']

for (var i = 0; i < nodes.length; i++) {
Expand Down Expand Up @@ -216,7 +216,7 @@ function buildGraph (nodes, version) {
}

for (n = 0; n < prevNodeIds.length; n++) {
graph[prevNodeIds[n]]['end'] = 0
graph[prevNodeIds[n]].end = 0
}

return { map: graph, table: table }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"htmlparser2": "^3.9.2",
"os-tmpdir": "^1.0.2",
"sinon": "^1.17.7",
"standard": "^9.0.2",
"standard": "^14.3.3",
"tap": "^12.1.1",
"uglify-js": "^2.7.5"
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/toDataURL.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ test('Canvas toDataURL - image/png', function (t) {
'Should throw if no arguments are provided')

t.throw(function () { QRCodeBrowser.toDataURL(function () {}) },
'Should throw if text is not provided')
'Should throw if text is not provided')

var canvas = new Canvas(200, 200)
QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/toFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ test('toFile png', function (t) {
test('toFile svg', function (t) {
var fileName = path.join(tmpDir(), 'qrimage.svg')
var expectedOutput = fs.readFileSync(
path.join(__dirname,
'/svg.expected.out'),
'UTF-8')
path.join(__dirname, '/svg.expected.out'), 'UTF-8')

t.plan(6)

Expand Down
1 change: 1 addition & 0 deletions test/unit/core/mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ test('Char count bits', function (t) {
})

test('Best mode', function (t) {
/* eslint-disable quote-props */
var EXPECTED_MODE = {
'12345': Mode.NUMERIC,
'abcde': Mode.BYTE,
Expand Down
107 changes: 54 additions & 53 deletions test/unit/core/segments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,175 +10,176 @@ var Utils = require('core/utils')
var testData = [
{
input: '1A1',
result: [{data: '1A1', mode: Mode.ALPHANUMERIC}]
result: [{ data: '1A1', mode: Mode.ALPHANUMERIC }]
},
{
input: 'a-1-b-2?',
result: [{data: 'a-1-b-2?', mode: Mode.BYTE}]
result: [{ data: 'a-1-b-2?', mode: Mode.BYTE }]
},
{
input: 'AB123456CDF',
result: [{data: 'AB123456CDF', mode: Mode.ALPHANUMERIC}]
result: [{ data: 'AB123456CDF', mode: Mode.ALPHANUMERIC }]
},
{
input: 'aABC000000-?-----a',
result: [
{data: 'aABC', mode: Mode.BYTE},
{data: '000000', mode: Mode.NUMERIC},
{data: '-?-----a', mode: Mode.BYTE}
{ data: 'aABC', mode: Mode.BYTE },
{ data: '000000', mode: Mode.NUMERIC },
{ data: '-?-----a', mode: Mode.BYTE }
]
},
{
input: 'aABC000000A?',
result: [
{data: 'aABC', mode: Mode.BYTE},
{data: '000000', mode: Mode.NUMERIC},
{data: 'A?', mode: Mode.BYTE}
{ data: 'aABC', mode: Mode.BYTE },
{ data: '000000', mode: Mode.NUMERIC },
{ data: 'A?', mode: Mode.BYTE }
]
},
{
input: 'a1234ABCDEF?',
result: [
{data: 'a', mode: Mode.BYTE},
{data: '1234ABCDEF', mode: Mode.ALPHANUMERIC},
{data: '?', mode: Mode.BYTE}
{ data: 'a', mode: Mode.BYTE },
{ data: '1234ABCDEF', mode: Mode.ALPHANUMERIC },
{ data: '?', mode: Mode.BYTE }
]
},
{
input: '12345A12345',
result: [
{data: '12345A12345', mode: Mode.ALPHANUMERIC}
{ data: '12345A12345', mode: Mode.ALPHANUMERIC }
]
},
{
input: 'aABCDEFGHILMNa',
result: [
{data: 'a', mode: Mode.BYTE},
{data: 'ABCDEFGHILMN', mode: Mode.ALPHANUMERIC},
{data: 'a', mode: Mode.BYTE}
{ data: 'a', mode: Mode.BYTE },
{ data: 'ABCDEFGHILMN', mode: Mode.ALPHANUMERIC },
{ data: 'a', mode: Mode.BYTE }
]
},
{
input: 'Aa12345',
result: [
{data: 'Aa', mode: Mode.BYTE},
{data: '12345', mode: Mode.NUMERIC}
{ data: 'Aa', mode: Mode.BYTE },
{ data: '12345', mode: Mode.NUMERIC }
]
},
{
input: 'a1A2B3C4D5E6F4G7',
result: [
{data: 'a', mode: Mode.BYTE},
{data: '1A2B3C4D5E6F4G7', mode: Mode.ALPHANUMERIC}
{ data: 'a', mode: Mode.BYTE },
{ data: '1A2B3C4D5E6F4G7', mode: Mode.ALPHANUMERIC }
]
},
{
input: '123456789QWERTYUIOPASD',
result: [
{data: '123456789', mode: Mode.NUMERIC},
{data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC}
{ data: '123456789', mode: Mode.NUMERIC },
{ data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC }
]
},
{
input: 'QWERTYUIOPASD123456789',
result: [
{data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC},
{data: '123456789', mode: Mode.NUMERIC}
{ data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC },
{ data: '123456789', mode: Mode.NUMERIC }
]
},
{
input: 'ABCDEF123456a',
result: [
{data: 'ABCDEF123456', mode: Mode.ALPHANUMERIC},
{data: 'a', mode: Mode.BYTE}
{ data: 'ABCDEF123456', mode: Mode.ALPHANUMERIC },
{ data: 'a', mode: Mode.BYTE }
]
},
{
input: 'abcdefABCDEF',
result: [
{data: 'abcdef', mode: Mode.BYTE},
{data: 'ABCDEF', mode: Mode.ALPHANUMERIC}
{ data: 'abcdef', mode: Mode.BYTE },
{ data: 'ABCDEF', mode: Mode.ALPHANUMERIC }
]
},
{
input: 'a123456ABCDEa',
result: [
{data: 'a', mode: Mode.BYTE},
{data: '123456ABCDE', mode: Mode.ALPHANUMERIC},
{data: 'a', mode: Mode.BYTE}
{ data: 'a', mode: Mode.BYTE },
{ data: '123456ABCDE', mode: Mode.ALPHANUMERIC },
{ data: 'a', mode: Mode.BYTE }
]
},
{
input: 'AAAAA12345678?A1A',
result: [
{data: 'AAAAA', mode: Mode.ALPHANUMERIC},
{data: '12345678', mode: Mode.NUMERIC},
{data: '?A1A', mode: Mode.BYTE}
{ data: 'AAAAA', mode: Mode.ALPHANUMERIC },
{ data: '12345678', mode: Mode.NUMERIC },
{ data: '?A1A', mode: Mode.BYTE }
]
},
{
input: 'Aaa',
result: [{data: 'Aaa', mode: Mode.BYTE}]
result: [{ data: 'Aaa', mode: Mode.BYTE }]
},
{
input: 'Aa12345A',
result: [
{data: 'Aa', mode: Mode.BYTE},
{data: '12345A', mode: Mode.ALPHANUMERIC}
{ data: 'Aa', mode: Mode.BYTE },
{ data: '12345A', mode: Mode.ALPHANUMERIC }
]
},
{
input: 'ABC\nDEF',
result: [
{data: 'ABC\nDEF', mode: Mode.BYTE}
{ data: 'ABC\nDEF', mode: Mode.BYTE }
]
}
]

var kanjiTestData = [
{
input: '乂ЁЖぞβ',
result: [{data: '乂ЁЖぞβ', mode: Mode.KANJI}]
result: [{ data: '乂ЁЖぞβ', mode: Mode.KANJI }]
},
{
input: 'ΑΒΓψωЮЯабв',
result: [{data: 'ΑΒΓψωЮЯабв', mode: Mode.KANJI}]
result: [{ data: 'ΑΒΓψωЮЯабв', mode: Mode.KANJI }]
},
{
input: '皿a晒三',
result: [
{data: '皿a', mode: Mode.BYTE},
{data: '晒三', mode: Mode.KANJI}
{ data: '皿a', mode: Mode.BYTE },
{ data: '晒三', mode: Mode.KANJI }
]
},
{
input: '皿a\n晒三',
result: [
{data: '皿a\n', mode: Mode.BYTE},
{data: '晒三', mode: Mode.KANJI}
{ data: '皿a\n', mode: Mode.BYTE },
{ data: '晒三', mode: Mode.KANJI }
]
}
]

testData = testData.concat(kanjiTestData)

test('Segments from array', function (t) {
t.deepEqual(Segments.fromArray(['abcdef', '12345']),
t.deepEqual(
Segments.fromArray(['abcdef', '12345']),
[new ByteData('abcdef'), new NumericData('12345')],
'Should return correct segment from array of string')

t.deepEqual(Segments.fromArray(
[{ data: 'abcdef', mode: Mode.BYTE }, { data: '12345', mode: Mode.NUMERIC }]),
t.deepEqual(
Segments.fromArray([{ data: 'abcdef', mode: Mode.BYTE }, { data: '12345', mode: Mode.NUMERIC }]),
[new ByteData('abcdef'), new NumericData('12345')],
'Should return correct segment from array of objects')

t.deepEqual(Segments.fromArray(
[{ data: 'abcdef', mode: 'byte' }, { data: '12345', mode: 'numeric' }]),
t.deepEqual(
Segments.fromArray([{ data: 'abcdef', mode: 'byte' }, { data: '12345', mode: 'numeric' }]),
[new ByteData('abcdef'), new NumericData('12345')],
'Should return correct segment from array of objects if mode is specified as string')

t.deepEqual(Segments.fromArray(
[{ data: 'abcdef' }, { data: '12345' }]),
t.deepEqual(
Segments.fromArray([{ data: 'abcdef' }, { data: '12345' }]),
[new ByteData('abcdef'), new NumericData('12345')],
'Should return correct segment from array of objects if mode is not specified')

Expand All @@ -188,8 +189,8 @@ test('Segments from array', function (t) {
t.throw(function () { Segments.fromArray([{ data: 'ABCDE', mode: 'numeric' }]) },
'Should throw if segment cannot be encoded with specified mode')

t.deepEqual(Segments.fromArray(
[{ data: '0123', mode: Mode.KANJI }]), [new ByteData('0123')],
t.deepEqual(
Segments.fromArray([{ data: '0123', mode: Mode.KANJI }]), [new ByteData('0123')],
'Should use Byte mode if kanji support is disabled')

t.end()
Expand Down
Loading

0 comments on commit 48b4cdc

Please sign in to comment.