Skip to content

Commit

Permalink
More migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Dec 2, 2024
1 parent 89afc66 commit ce58668
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 93 deletions.
6 changes: 3 additions & 3 deletions lib/comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

var has = require('has-value');
var util = {
value: require('./utils/value'),
isOptions: require('./utils/isOptions'),
value: require('./utils/value').default,
isOptions: require('./utils/isOptions').default,
isString: require('./utils/isString'),
fn: require('./utils/fn'),
isObject: require('./utils/isObject'),
isObject: require('./utils/isObject').default,
inverse: require('./utils/inverse')
};
var utils = require('./utils');
Expand Down
16 changes: 8 additions & 8 deletions lib/number.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var util = {
isUndefined: require('./utils/isUndefined')
isUndefined: require('./utils/isUndefined').default
};
var helpers = module.exports;

Expand Down Expand Up @@ -41,8 +41,8 @@ helpers.bytes = function(number, precision, options) {
var len = abbr.length - 1;
while (len-- >= 0) {
var size = Math.pow(10, len * 3);
if (size <= (number + 1)) {
number = Math.round(number * precision / size) / precision;
if (size <= number + 1) {
number = Math.round((number * precision) / size) / precision;
number += ' ' + abbr[len];
break;
}
Expand Down Expand Up @@ -77,9 +77,9 @@ helpers.addCommas = function(num) {
helpers.phoneNumber = function(num) {
num = num.toString();

return '(' + num.substr(0, 3) + ') '
+ num.substr(3, 3) + '-'
+ num.substr(6, 4);
return (
'(' + num.substr(0, 3) + ') ' + num.substr(3, 3) + '-' + num.substr(6, 4)
);
};

/**
Expand Down Expand Up @@ -109,8 +109,8 @@ helpers.toAbbr = function(number, precision) {

while (len >= 0) {
var size = Math.pow(10, (len + 1) * 3);
if (size <= (number + 1)) {
number = Math.round(number * precision / size) / precision;
if (size <= number + 1) {
number = Math.round((number * precision) / size) / precision;
number += abbr[len];
break;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/regex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var util = { options: require('./utils/options') };
var util = { options: require('./utils/options').default };
var helpers = module.exports;
const kindOf = require('kind-of');

Expand All @@ -9,7 +9,7 @@ const kindOf = require('kind-of');
*
* ```handlebars
* {{toRegex 'foo'}}
* <!-- results in: /foo/ -->
* <!-- results in: /foo/ -->
* ```
* @param {String} `str`
* @return {RegExp}
Expand All @@ -29,11 +29,11 @@ helpers.toRegex = function(str, locals, options) {
*
* ```handlebars
* {{test 'bar' (toRegex 'foo')}}
* <!-- results in: false -->
* <!-- results in: false -->
* {{test 'foobar' (toRegex 'foo')}}
* <!-- results in: true -->
* <!-- results in: true -->
* {{test 'foobar' (toRegex '^foo$')}}
* <!-- results in: false -->
* <!-- results in: false -->
* ```
* @param {String} `str`
* @return {RegExp}
Expand All @@ -42,7 +42,7 @@ helpers.toRegex = function(str, locals, options) {
*/

helpers.test = function(str, regex) {
if (typeof(str) !== 'string') {
if (typeof str !== 'string') {
return false;
}
if (kindOf(regex) !== 'regexp') {
Expand Down
4 changes: 2 additions & 2 deletions lib/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

var util = {
isString: require('./utils/isString'),
isObject: require('./utils/isObject'),
options: require('./utils/options')
isObject: require('./utils/isObject').default,
options: require('./utils/options').default
};
var utils = require('./utils');
let lorem = require('./lorem.js');
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/fn.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

const isBlock = require('./isBlock');
const isOptions = require('./isOptions');
const isBlock = require('./isBlock').default;
const isOptions = require('./isOptions').default;
const fn = require('./fn');

/**
* This code was taken directly from handlebars-helpers,
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
Expand Down
68 changes: 42 additions & 26 deletions lib/utils/handlebarsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
/**
* This code was taken directly from handlebars-helpers, (extracting some utils to its own file)
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
* Copyright (C) 2011-2016 by Yehuda Katz
*/

var util = require('util');
var type = require('typeof-article');
var utils = exports = module.exports;
import { inspect } from 'util';
import type, { types } from 'typeof-article';
var utils = (exports = module.exports);

utils.extend = extend;
utils.escapeExpression = escapeExpression;
Expand All @@ -21,17 +21,17 @@ utils.createFrame = createFrame;
utils.blockParams = blockParams;
utils.appendContextPath = appendContextPath;

utils.isObject = require('./isObject');
utils.isOptions = require('./isOptions');
utils.isUndefined = require('./isUndefined');
utils.result = require('./result');
utils.indexOf = require('./indexOf');
utils.isBlock = require('./isBlock');
utils.isObject = require('./isObject').default;
utils.isOptions = require('./isOptions').default;
utils.isUndefined = require('./isUndefined').default;
utils.result = require('./result').default;
utils.indexOf = require('./indexOf').default;
utils.isBlock = require('./isBlock').default;
utils.fn = require('./fn');
utils.inverse = require('./inverse');
utils.value = require('./value');
utils.options = require('./options');
utils.identity = require('./identity');
utils.value = require('./value').default;
utils.options = require('./options').default;
utils.identity = require('./identity').default;
utils.isString = require('./isString');

var escape = {
Expand Down Expand Up @@ -76,19 +76,24 @@ var isFunction = function isFunction(value) {
/* istanbul ignore next */
if (isFunction(/x/)) {
utils.isFunction = isFunction = function(value) {
return typeof value === 'function' && toString.call(value) === '[object Function]';
return (
typeof value === 'function' &&
toString.call(value) === '[object Function]'
);
};
}
utils.isFunction = isFunction;

/* eslint-enable func-style */

/* istanbul ignore next */
var isArray = Array.isArray || function(value) {
return value && typeof value === 'object'
? toString.call(value) === '[object Array]'
: false;
};
var isArray =
Array.isArray ||
function(value) {
return value && typeof value === 'object'
? toString.call(value) === '[object Array]'
: false;
};

utils.isArray = isArray;

Expand Down Expand Up @@ -136,9 +141,18 @@ function appendContextPath(contextPath, id) {
//

utils.expectedType = function(param, expected, actual) {
var exp = type.types[expected];
var val = util.inspect(actual);
return 'expected ' + param + ' to be ' + exp + ' but received ' + type(actual) + ': ' + val;
var exp = types[expected];
var val = inspect(actual);
return (
'expected ' +
param +
' to be ' +
exp +
' but received ' +
type(actual) +
': ' +
val
);
};

/**
Expand All @@ -161,9 +175,11 @@ utils.expectedType = function(param, expected, actual) {
*/

utils.isApp = function(thisArg) {
return utils.isObject(thisArg)
&& utils.isObject(thisArg.options)
&& utils.isObject(thisArg.app);
return (
utils.isObject(thisArg) &&
utils.isObject(thisArg.options) &&
utils.isObject(thisArg.app)
);
};

/**
Expand Down Expand Up @@ -270,6 +286,6 @@ utils.arrayify = function(val) {
utils.tryParse = function(str) {
try {
return JSON.parse(str);
} catch (err) { }
} catch (err) {}
return {};
};
6 changes: 3 additions & 3 deletions lib/utils/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This code was taken directly from handlebars-helpers,
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
Expand All @@ -26,6 +26,6 @@
* @api public
*/

module.exports = function(val) {
export default function(val) {
return val;
};
}
6 changes: 3 additions & 3 deletions lib/utils/indexOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This code was taken directly from handlebars-helpers,
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
Expand All @@ -12,11 +12,11 @@

// Older IE versions do not directly support indexOf so we must implement our own, sadly.

module.exports = function(array, value) {
export default function(array, value) {
for (var i = 0, len = array.length; i < len; i++) {
if (array[i] === value) {
return i;
}
}
return -1;
};
}
8 changes: 4 additions & 4 deletions lib/utils/inverse.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const inverse = require('./inverse');
const identity = require('./identity');
const isBlock = require('./isBlock');
const isOptions = require('./isOptions');
const identity = require('./identity').default;
const isBlock = require('./isBlock').default;
const isOptions = require('./isOptions').default;

/**
* This code was taken directly from handlebars-helpers,
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
Expand Down
18 changes: 9 additions & 9 deletions lib/utils/isBlock.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

const isOptions = require('./isOptions');
import isOptions from './isOptions';

/**
* This code was taken directly from handlebars-helpers,
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
Expand All @@ -29,10 +29,10 @@ const isOptions = require('./isOptions');
* @api public
*/

module.exports =

function(options) {
return isOptions(options)
&& typeof options.fn === 'function'
&& typeof options.inverse === 'function';
};
export default function(options) {
return (
isOptions(options) &&
typeof options.fn === 'function' &&
typeof options.inverse === 'function'
);
}
6 changes: 3 additions & 3 deletions lib/utils/isObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This code was taken directly from handlebars-helpers,
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
Expand All @@ -28,6 +28,6 @@
* @api public
*/

module.exports = function(val) {
export default function(val) {
return !!val && typeof val === 'object';
};
}
8 changes: 4 additions & 4 deletions lib/utils/isOptions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

const isObject = require('./isObject');
import isObject from './isObject';

/**
* This code was taken directly from handlebars-helpers,
* https://github.com/helpers/handlebars-utils/blob/master/index.js#L398
*
*
* that was taken directly from handlebars.
* https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE
* Released under the MIT License
Expand All @@ -29,6 +29,6 @@ const isObject = require('./isObject');
* @api public
*/

module.exports = function(val) {
export default function(val) {
return isObject(val) && isObject(val.hash);
};
}
5 changes: 1 addition & 4 deletions lib/utils/isString.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
* @api public
*/

module.exports = function(val) {
return typeof val === 'string' && val !== '';
};
export function isString(val) {
export default function isString(val) {
return typeof val === 'string' && val !== '';
}
Loading

0 comments on commit ce58668

Please sign in to comment.