Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: fix style issues standard is complaining about #123

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#! /usr/bin/env node

var program = require('commander')
var version = require('./package').version
var coap = require('coap')
var request = coap.request
var URL = require('url')
var through = require('through2')
var method = 'GET' // default
var url
var req
var coapOptionSeperator = ','
const program = require('commander')
const version = require('./package').version
const coap = require('coap')
const request = coap.request
const URL = require('url')
const through = require('through2')
let method = 'GET' // default
let url
const coapOptionSeperator = ','

function collectOptions (val, memo) {
var coapOptionRegex = new RegExp('\\d{1}\\' + coapOptionSeperator + '\\w+')
const coapOptionRegex = new RegExp('\\d{1}\\' + coapOptionSeperator + '\\w+')
if (coapOptionRegex.test(val)) {
memo.push(val)
} else {
Expand Down Expand Up @@ -77,22 +76,22 @@ if (program.block2 && (program.block2 < 1 || program.block2 > 6)) {
process.exit(-1)
}

var startTime = new Date()
req = request(url)
const startTime = new Date()
const req = request(url)
if (program.block2) {
req.setOption('Block2', Buffer.from([program.block2]))
}

if (typeof program.coapOption !== 'undefined' && program.coapOption.length > 0) {
program.coapOption.forEach(function (singleOption) {
var kvPair = singleOption.split(coapOptionSeperator, 2)
var optionValueBuffer = kvPair[1].startsWith('0x') ? Buffer.from(kvPair[1].substr(2), 'hex') : Buffer.from(kvPair[1])
const kvPair = singleOption.split(coapOptionSeperator, 2)
const optionValueBuffer = kvPair[1].startsWith('0x') ? Buffer.from(kvPair[1].substr(2), 'hex') : Buffer.from(kvPair[1])
req.setOption(kvPair[0], optionValueBuffer)
})
}

req.on('response', function (res) {
var endTime = new Date()
const endTime = new Date()
if (program.showTiming) {
console.log('Request took ' + (endTime.getTime() - startTime.getTime()) + ' ms')
}
Expand Down
28 changes: 14 additions & 14 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'
/* global describe, before, after, it */

var expect = require('chai').expect
var coap = require('coap')
var concat = require('concat-stream')
var spawn = require('child_process').spawn
var replace = require('event-stream').replace
const expect = require('chai').expect
const coap = require('coap')
const concat = require('concat-stream')
const spawn = require('child_process').spawn
const replace = require('event-stream').replace

describe('coap', function () {
var server
let server

before(function (done) {
server = coap.createServer()
Expand All @@ -22,7 +22,7 @@ describe('coap', function () {
})

function call () {
var child = spawn('node', ['index.js'].concat(Array.prototype.slice.call(arguments)))
const child = spawn('node', ['index.js'].concat(Array.prototype.slice.call(arguments)))

// piping child.stderr to stdout but filtering out the status codes
child.stderr
Expand All @@ -48,7 +48,7 @@ describe('coap', function () {
})

it('should GET a given resource by default', function (done) {
var child = call('coap://localhost')
const child = call('coap://localhost')

child.stderr.pipe(concat(function (data) {
expect(data.toString()).to.eql('\x1b[1m(2.05)\x1b[0m\t')
Expand All @@ -64,7 +64,7 @@ describe('coap', function () {
})

it('should GET a given resource by default (bis)', function (done) {
var child = call('coap://localhost')
const child = call('coap://localhost')

child.stderr.pipe(concat(function (data) {
expect(data.toString()).to.eql('\x1b[1m(2.05)\x1b[0m\t')
Expand All @@ -80,7 +80,7 @@ describe('coap', function () {
})

it('should GET not adding a newline (short)', function (done) {
var child = call('-n', 'coap://localhost')
const child = call('-n', 'coap://localhost')

child.stderr.pipe(concat(function (data) {
expect(data.toString()).to.eql('\x1b[1m(2.05)\x1b[0m\t')
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('coap', function () {
})

it('should only emit status code if the response was a 4.04', function (done) {
var child = call('coap://localhost')
const child = call('coap://localhost')

child.stderr.pipe(concat(function (data) {
expect(data.toString()).to.eql('\x1b[1m(4.04)\x1b[0m\n')
Expand All @@ -145,7 +145,7 @@ describe('coap', function () {
})

it('should GET a given resource by specifying the verb', function (done) {
var child = call('get', 'coap://localhost')
const child = call('get', 'coap://localhost')

child.stderr.pipe(concat(function (data) {
expect(data.toString()).to.eql('\x1b[1m(2.05)\x1b[0m\t')
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('coap', function () {
})

it('should observe the given resource and emit the values', function (done) {
var child = call('-o', 'coap://localhost')
const child = call('-o', 'coap://localhost')

child.stderr.once('data', function (data) {
expect(data.toString()).to.eql('\x1b[1m(2.05)\x1b[0m\t')
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('coap', function () {
})

it('should observe the given resource and emit the values without a new line', function (done) {
var child = call('-o', '-n', 'coap://localhost')
const child = call('-o', '-n', 'coap://localhost')

child.stderr.once('data', function (data) {
expect(data.toString()).to.eql('\x1b[1m(2.05)\x1b[0m\t')
Expand Down