Skip to content

Commit

Permalink
chore(src): Remove babel
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Jun 16, 2016
1 parent f6df6a9 commit 0fbab71
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
24 changes: 3 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
"name": "meitrack-parser",
"version": "0.3.2",
"description": "Parse raw data from Meitrack devices",
"main": "lib",
"main": "src",
"scripts": {
"prepublish": "npm run build -s",
"prebuild": "npm run lint -s && npm run clean -s",
"build": "babel src --out-dir lib --source-maps",
"lint": "eslint src",
"clean": "rimraf lib",
"pretest": "npm run build -s",
"test": "babel-node ./node_modules/.bin/isparta cover _mocha",
"test": "mocha",
"coveralls": "coveralls < coverage/lcov.info"
},
"engines": {
Expand Down Expand Up @@ -39,15 +34,10 @@
"pad": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.7.7",
"babel-core": "^6.7.7",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.5.0",
"coveralls": "^2.11.9",
"eslint": "2.10.1",
"isparta": "^4.0.0",
"mocha": "^2.4.5",
"rimraf": "^2.5.2"
"mocha": "^2.4.5"
},
"eslintConfig": {
"env": {
Expand All @@ -56,9 +46,6 @@
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": [
2,
Expand All @@ -78,10 +65,5 @@
]
}
},
"babel": {
"presets": [
"es2015"
]
},
"tonicExampleFilename": "example.js"
}
24 changes: 13 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

import crc from 'crc';
import pad from 'pad';
import moment from 'moment';
const crc = require('crc');
const pad = require('pad');
const moment = require('moment');

const patterns = {
mvt380: /^\$\$([\x41-\x7A])(\d{1,3}),(\d{15}),([0-9A-F]{3}),(\d{1,3}),([-]?\d+\.\d+),([-]?\d+\.\d+),(\d{12}),([AV]),(\d{1,3}),(\d{1,2}),(\d+(\.\d+)?),(\d+(\.\d+)?),(\d+(\.\d+)?),(\d+(\.\d+)?),(\d+(\.\d+)?),(\d+),(\d{3})\|(\d{1,3})\|([0-9A-F]{4})\|([0-9A-F]{4}),([0-9A-F]{4}),([0-9A-F]{1,4})?\|([0-9A-F]{1,4})?\|([0-9A-F]{1,4})?\|([0-9A-F]{1,4})\|([0-9A-F]{1,4}),([0-9A-F]{8})?,?([0-9A-F]+)?,?(\d{1,2})?,?([0-9A-F]{4})?,?([0-9A-F]{6})?\|?([0-9A-F]{6})?\|?([0-9A-F]{6})?\|?\*([0-9A-F]{2})\r\n$/,
ok: /^\$\$([\x41-\x7A])(\d{1,3}),(\d{15}),([0-9A-F]{3}),OK\*([0-9A-F]{2})\r\n$/
};

const parseAlrm = (event) => {
const parseAlrm = event => {
const alarms = {
'1': {type: 'SOS_Button'},
'2': {type: 'DI', number: 2, status: true},
Expand Down Expand Up @@ -72,7 +72,7 @@ const parseAlrm = (event) => {
return event in alarms ? alarms[event] : null;
};

const getMvt380 = (raw) => {
const getMvt380 = raw => {
const match = patterns.mvt380.exec(raw);
const status = match[27].split('').map(x => pad(4, parseInt(x, 10).toString(2), '0')).join('');
const data = {
Expand Down Expand Up @@ -133,7 +133,7 @@ const getMvt380 = (raw) => {
return data;
};

const parseCode = (raw) => {
const parseCode = raw => {
const match = patterns.ok.exec(raw);
const code = match[4];
const codes = {
Expand All @@ -149,7 +149,7 @@ const parseCode = (raw) => {
return data;
};

const parse = (raw) => {
const parse = raw => {
let result = {type: 'UNKNOWN', raw: raw.toString()};
if (patterns.mvt380.test(raw)) {
result = getMvt380(raw);
Expand All @@ -159,7 +159,7 @@ const parse = (raw) => {
return result;
};

const isMeitrack = (raw) => {
const isMeitrack = raw => {
let result = false;
if (patterns.mvt380.test(raw)) {
result = true;
Expand All @@ -181,10 +181,12 @@ const getCommand = (imei, command) => {
return `${raw2}${pad(2, crc.crc1(raw2).toString(16).toUpperCase(), '0')}\r\n`;
};

const parseCommand = (data) => {
const parseCommand = data => {
let raw, state, port, speed, interval;
if (/^[1-5]{1}_(on|off|status)$/.test(data.instruction)) {
[port, state] = data.instruction.split('_');
let _data = data.instruction.split('_');
port = _data[0];
state = _data[1];
let initial = [0, 0, 0, 0, 0];
const states = {off: 0, on: 1, status: 2};
initial[port - 1] = states[state];
Expand Down Expand Up @@ -213,7 +215,7 @@ const parseCommand = (data) => {
return getCommand(data.imei, raw);
};

const getRebootCommand = (imei) => {
const getRebootCommand = imei => {
return getCommand(imei, 'F02');
};

Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import meitrack from '../lib';
import {expect} from 'chai';
const meitrack = require('../src');
const expect = require('chai').expect;

describe('meitrack-parser', () => {
it('should return the raw data parsed', () => {
Expand Down

0 comments on commit 0fbab71

Please sign in to comment.