Skip to content

Commit

Permalink
Replace vars with let and const
Browse files Browse the repository at this point in the history
  • Loading branch information
hakatashi committed Oct 19, 2015
1 parent 2b457fd commit 0436c78
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/kana.es6
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ module.exports = function (japanese) {
'𛀁': 'エ',
};

var chr = String.fromCharCode;
var ord = function (char) {
const chr = String.fromCharCode;
const ord = function (char) {
return char.charCodeAt(0);
};

Expand Down
36 changes: 18 additions & 18 deletions src/numbers.es6
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict';

var extend = require('extend');
var Big = require('big.js');
const extend = require('extend');
const Big = require('big.js');

// Get nth bit from buffer
function getBit(buffer, position) {
var byteIndex = Math.floor(position / 8);
var byte = buffer[byteIndex] || 0;
let byteIndex = Math.floor(position / 8);
let byte = buffer[byteIndex] || 0;

return !!(byte & (1 << (7 - position % 8)));
}

// Get bits of buffer from a to b
function getBits(buffer, from, length) {
var ret = new Big(0);
let ret = new Big(0);

for (var ptr = from; ptr < from + length; ptr++) {
for (let ptr = from; ptr < from + length; ptr++) {
ret = ret.times(2);
if (getBit(buffer, ptr)) {
ret = ret.plus(1);
Expand Down Expand Up @@ -406,13 +406,13 @@ module.exports = function (japanese) {
number = number.toString();
} else {
// Paste number into binary form
var buf = new Buffer(8);
const buf = new Buffer(8);
buf.writeDoubleBE(number, 0);

var sign = getBit(buf, 0);
var exponent = getBits(buf, 1, 11);
var mantissa = getBits(buf, 12, 52);
var fraction = null;
let sign = getBit(buf, 0);
let exponent = getBits(buf, 1, 11);
let mantissa = getBits(buf, 12, 52);
let fraction = null;

exponent = parseInt(exponent.toString());

Expand All @@ -433,12 +433,12 @@ module.exports = function (japanese) {
throw new ReferenceError('Type of `number` is unsupported');
}

var length = number.length;
let length = number.length;

// Main convertion starts here

var lit = '';
var restoreZero = false;
let lit = '';
let restoreZero = false;
if (config.unitNames.lit && length > config.unitNames.lit) {
lit = number.slice(0, -config.unitNames.lit).split('').map(function (digit) {
return config.digits[digit];
Expand All @@ -457,14 +457,14 @@ module.exports = function (japanese) {
return config.digits[0];
}

var transcription = '';
let transcription = '';

if (number.slice(-1) !== '0') {
transcription += config.digits[number.slice(-1)];
}

// Get sanitized unit name keys
var keysOfUnitNames = Object.keys(config.unitNames).map(function (key) {
let keysOfUnitNames = Object.keys(config.unitNames).map(function (key) {
// convert to int
return parseInt(key);
}).filter(function (key, index, self) {
Expand All @@ -479,9 +479,9 @@ module.exports = function (japanese) {
});

keysOfUnitNames.forEach(function (key, index) {
var nextKey = keysOfUnitNames[index + 1] || Infinity;
let nextKey = keysOfUnitNames[index + 1] || Infinity;
// slice the digits spaned by the unit name
var token = number.slice(Math.max(length - nextKey, 0), Math.max(length - key, 0));
let token = number.slice(Math.max(length - nextKey, 0), Math.max(length - key, 0));

if (token.length > 0) {
// check if every number in the token is zero
Expand Down
12 changes: 6 additions & 6 deletions src/romanize.es6
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var extend = require('extend');
const extend = require('extend');

module.exports = function (japanese) {
japanese.romanizationTable = {
Expand Down Expand Up @@ -325,7 +325,7 @@ module.exports = function (japanese) {
throw new Error('You specified unknown config to japanese.romanize');
}

var table = extend({}, japanese.romanizationTable);
const table = extend({}, japanese.romanizationTable);

if (config['し'] === 'shi') {
extend(table, {
Expand Down Expand Up @@ -480,11 +480,11 @@ module.exports = function (japanese) {

string = japanese.hiraganize(string);

var dest = '';
var previousToken = '';
let dest = '';
let previousToken = '';

while (string.length > 0) {
var token = '';
let token = '';

// assuming we have only one or two letter token in table
if (table[string.slice(0, 2)]) {
Expand All @@ -501,7 +501,7 @@ module.exports = function (japanese) {
continue;
}

var tokenDest = table[token] || '';
let tokenDest = table[token] || '';

// small tsu
if (previousToken === 'っ') {
Expand Down

0 comments on commit 0436c78

Please sign in to comment.