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

Convert to esm #26

Draft
wants to merge 47 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
94d2439
Allow mocha running for mjs
adrinr Dec 3, 2024
657466e
Convert uuid to mjs
adrinr Dec 3, 2024
c2cce12
Migrate array and match tests
adrinr Dec 3, 2024
879c1ca
Migrate more tests
adrinr Dec 3, 2024
30d3271
Migrate more tests
adrinr Dec 3, 2024
eb075d2
Migrate more tests
adrinr Dec 3, 2024
997ac36
Migrate more tests
adrinr Dec 3, 2024
b9da189
Migrate more tests
adrinr Dec 3, 2024
15c26c1
Lint
adrinr Dec 3, 2024
b534380
lint
adrinr Dec 3, 2024
18165dd
Remove index.js
adrinr Dec 3, 2024
275949e
Remove unnecessary "integration" tests
adrinr Dec 3, 2024
4406a27
Update lib/index
adrinr Dec 3, 2024
d0d041b
Convert uuid
adrinr Dec 3, 2024
8623487
More migrations
adrinr Dec 3, 2024
b9d8538
Migrate "code"
adrinr Dec 3, 2024
24ace03
Convert "comparison"
adrinr Dec 3, 2024
4f92a79
Fix linting
adrinr Dec 3, 2024
6cfdc1f
Convert number
adrinr Dec 3, 2024
81d68f8
Migrate i18n
adrinr Dec 3, 2024
9a2c3b1
Migrate html
adrinr Dec 3, 2024
7ae8256
More conversions
adrinr Dec 3, 2024
51ad523
More conversions
adrinr Dec 3, 2024
a22f487
Migrate and fix math
adrinr Dec 3, 2024
fccb815
Remove sinon
adrinr Dec 3, 2024
78a43f1
More conversions
adrinr Dec 3, 2024
0ddfa00
Migrate url
adrinr Dec 3, 2024
2a1f618
Migrate utils/index
adrinr Dec 3, 2024
ed65721
More conversions
adrinr Dec 3, 2024
be1cda5
More conversions
adrinr Dec 3, 2024
434bbd6
Migrate html
adrinr Dec 4, 2024
620af13
More conversions
adrinr Dec 4, 2024
2dad80f
More conversions
adrinr Dec 4, 2024
86f9002
More conversions
adrinr Dec 4, 2024
50b09cf
Migrate inverse
adrinr Dec 4, 2024
1b996d3
Convert options
adrinr Dec 4, 2024
564f0a2
Convert indexOf
adrinr Dec 4, 2024
922d0d6
Convert identity
adrinr Dec 4, 2024
f87949f
More conversions
adrinr Dec 4, 2024
4c7e859
More conversions
adrinr Dec 4, 2024
90d5b96
Migrate isString
adrinr Dec 4, 2024
c27570a
Final conversion
adrinr Dec 4, 2024
3233c20
Rename back from mjs to js
adrinr Dec 4, 2024
7dc5a25
Undo
adrinr Dec 4, 2024
e277fa9
Lint
adrinr Dec 4, 2024
fa4a6e4
Merge branch 'master' into convert-to-esm
adrinr Dec 4, 2024
4f9f81f
Support es5
adrinr Dec 4, 2024
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
Prev Previous commit
Next Next commit
Convert options
  • Loading branch information
adrinr committed Dec 4, 2024
commit 1b996d3a5aded15bea5d39a927781c8d80c680f3
8 changes: 4 additions & 4 deletions lib/i18n.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import handlebarsUtils from './utils/handlebarsUtils.js';
import * as utils from './utils/index.mjs';
import getValue from 'get-value';

/**
Expand All @@ -15,16 +15,16 @@ import getValue from 'get-value';
*/

export function i18n(prop, locals, options) {
if (handlebarsUtils.isOptions(locals)) {
if (utils.isOptions(locals)) {
options = locals;
locals = {};
}

if (!handlebarsUtils.isString(prop)) {
if (!utils.isString(prop)) {
throw new Error('{{i18n}} helper expected "key" to be a string');
}

var opts = handlebarsUtils.options(this, locals, options);
var opts = utils.options(this, locals, options);
var context = Object.assign({}, this, opts);

var lang = context.language || context.lang;
Expand Down
6 changes: 3 additions & 3 deletions lib/match.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import handlebarsUtils from './utils/handlebarsUtils.js';
import * as utils from './utils/index.mjs';

import micromatch from 'micromatch';

Expand All @@ -21,7 +21,7 @@ import micromatch from 'micromatch';
*/

export function match(files, patterns, locals, options) {
var opts = handlebarsUtils.options(this, locals, options);
var opts = utils.options(this, locals, options);
if (typeof patterns === 'string') {
patterns = patterns.split(/, */);
}
Expand All @@ -45,7 +45,7 @@ export function match(files, patterns, locals, options) {
*/

export function isMatch(files, patterns, locals, options) {
var opts = handlebarsUtils.options(this, locals, options);
var opts = utils.options(this, locals, options);
return micromatch.isMatch(files, patterns, opts);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/misc.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

import handlebarsUtils from './utils/handlebarsUtils.js';
const { options: _options } = handlebarsUtils;
import {options as _options} from './utils/index.mjs';

import getValue from 'get-value';
import createFrame from './utils/createFrame.mjs';
Expand Down
2 changes: 1 addition & 1 deletion lib/path.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import util from './utils/handlebarsUtils.js';
import * as util from './utils/index.mjs';
import path from 'path';
import _relative from 'relative';

Expand Down
44 changes: 18 additions & 26 deletions lib/string.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
'use strict';

import utilIsString from './utils/isString.js';
import utilIsObject from './utils/isObject.js';
import utilOptions from './utils/options.js';
const util = {
isString: utilIsString,
isObject: utilIsObject,
options: utilOptions
};
import * as utils from './utils/index.mjs';
import loremText from './utils/lorem.mjs';

Expand Down Expand Up @@ -86,7 +78,7 @@ export const capitalize = function(str) {

export const capitalizeAll = function(str) {
if (typeof(str) !== 'string') return '';
if (util.isString(str)) {
if (utils.isString(str)) {
return str.replace(/\w\S*/g, function(word) {
return capitalize(word);
});
Expand Down Expand Up @@ -217,7 +209,7 @@ export const downcase = function() {
*/

export const ellipsis = function(str, limit) {
if (util.isString(str)) {
if (utils.isString(str)) {
if (str.length <= limit) {
return str;
}
Expand Down Expand Up @@ -274,7 +266,7 @@ export const isString = function(value) {
*/

export const lowercase = function(str) {
if (util.isObject(str) && str.fn) {
if (utils.isObject(str) && str.fn) {
return str.fn(this).toLowerCase();
}
if (typeof(str) !== 'string') return '';
Expand Down Expand Up @@ -366,7 +358,7 @@ export const pathcase = function(str) {

export const plusify = function(str, ch) {
if (typeof(str) !== 'string') return '';
if (!util.isString(ch)) ch = ' ';
if (!utils.isString(ch)) ch = ' ';
return str.split(ch).join('+');
};

Expand Down Expand Up @@ -410,7 +402,7 @@ export const prepend = function(str, prefix) {

export const raw = function(options) {
var str = options.fn();
var opts = util.options(this, options);
var opts = utils.options(this, options);
if (opts.escape !== false) {
var idx = 0;
while (((idx = str.indexOf('{{', idx)) !== -1)) {
Expand Down Expand Up @@ -439,7 +431,7 @@ export const raw = function(options) {

export const remove = function(str, ch) {
if (typeof(str) !== 'string') return '';
if (!util.isString(ch)) return str;
if (!utils.isString(ch)) return str;
return str.split(ch).join('');
};

Expand All @@ -459,7 +451,7 @@ export const remove = function(str, ch) {

export const removeFirst = function(str, ch) {
if (typeof(str) !== 'string') return '';
if (!util.isString(ch)) return str;
if (!utils.isString(ch)) return str;
return str.replace(ch, '');
};

Expand All @@ -480,8 +472,8 @@ export const removeFirst = function(str, ch) {

export const replace = function(str, a, b) {
if (typeof(str) !== 'string') return '';
if (!util.isString(a)) return str;
if (!util.isString(b)) b = '';
if (!utils.isString(a)) return str;
if (!utils.isString(b)) b = '';
return str.split(a).join(b);
};

Expand All @@ -502,8 +494,8 @@ export const replace = function(str, a, b) {

export const replaceFirst = function(str, a, b) {
if (typeof(str) !== 'string') return '';
if (!util.isString(a)) return str;
if (!util.isString(b)) b = '';
if (!utils.isString(a)) return str;
if (!utils.isString(b)) b = '';
return str.replace(a, b);
};

Expand Down Expand Up @@ -577,7 +569,7 @@ export const snakecase = function(str) {

export const split = function(str, ch) {
if (typeof(str) !== 'string') return '';
if (!util.isString(ch)) ch = ',';
if (!utils.isString(ch)) ch = ',';
return str.split(ch);
};

Expand All @@ -604,7 +596,7 @@ export const split = function(str, ch) {
export const startsWith = function(prefix, str, options) {
var args = [].slice.call(arguments);
options = args.pop();
if (util.isString(str) && str.indexOf(prefix) === 0) {
if (utils.isString(str) && str.indexOf(prefix) === 0) {
return options.fn(this);
}
if (typeof options.inverse === 'function') {
Expand Down Expand Up @@ -672,7 +664,7 @@ export const trim = function(str) {
*/

export const trimLeft = function(str) {
if (util.isString(str)) {
if (utils.isString(str)) {
return str.replace(/^\s+/, '');
}
};
Expand All @@ -691,7 +683,7 @@ export const trimLeft = function(str) {
*/

export const trimRight = function(str) {
if (util.isString(str)) {
if (utils.isString(str)) {
return str.replace(/\s+$/, '');
}
};
Expand All @@ -715,7 +707,7 @@ export const trimRight = function(str) {
*/

export const truncate = function(str, limit, suffix) {
if (util.isString(str)) {
if (utils.isString(str)) {
if (typeof suffix !== 'string') {
suffix = '';
}
Expand Down Expand Up @@ -748,7 +740,7 @@ export const truncate = function(str, limit, suffix) {
*/

export const truncateWords = function(str, count, suffix) {
if (util.isString(str) && !isNaN(count)) {
if (utils.isString(str) && !isNaN(count)) {
if (typeof suffix !== 'string') {
suffix = '…';
}
Expand Down Expand Up @@ -803,7 +795,7 @@ export const upcase = function() {
*/

export const uppercase = function(str) {
if (util.isObject(str) && str.fn) {
if (utils.isObject(str) && str.fn) {
return str.fn(this).toUpperCase();
}
if (typeof(str) !== 'string') return '';
Expand Down
1 change: 0 additions & 1 deletion lib/utils/handlebarsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ utils.isUndefined = require('./isUndefined');
utils.indexOf = require('./indexOf');
utils.isBlock = require('./isBlock');
utils.fn = require('./fn');
utils.options = require('./options');
utils.identity = require('./identity');
utils.isString = require('./isString');

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import _fn from './fn.js';
import _isObject from './isObject.js';
import _inverse from './inverse.mjs';
import _isUndefined from './isUndefined.js';
import _options from './options.js';
import _options from './options.mjs';

export const isOptions = _isOptions;
export const value = _value;
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/options.js → lib/utils/options.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

/**
* This code was taken directly from handlebars-helpers,
Expand Down Expand Up @@ -47,4 +47,4 @@ const _options = function(thisArg, locals, options) {
return opts;
};

module.exports = _options;
export default _options;