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 all commits
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"parserOptions": { "sourceType": "module" },
"env": {
"browser": false,
"es6": true,
Expand Down
50 changes: 32 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

'use strict';

var lib = require('./lib/');
import lib from './lib/index.js';
// TODO: import only when required
import Handlebars from 'handlebars';

/**
* Expose helpers
*/

module.exports = function helpers(groups, options) {
export default function helpers(groups, options) {
if (typeof groups === 'string') {
groups = [groups];
} else if (!Array.isArray(groups)) {
Expand All @@ -22,17 +24,16 @@ module.exports = function helpers(groups, options) {
}

options = options || {};
var hbs = options.handlebars || options.hbs || require('handlebars');
module.exports.handlebars = hbs;
var hbs = options.handlebars || options.hbs || Handlebars;

if (groups) {
groups.forEach(function(key) {
hbs.registerHelper(lib[key]);
hbs.registerHelper(Object.assign({}, lib[key]));
});
} else {
for (const key in lib) {
const group = lib[key];
hbs.registerHelper(group);
hbs.registerHelper(Object.assign({}, group));
}
}

Expand All @@ -42,20 +43,33 @@ module.exports = function helpers(groups, options) {
/**
* Expose helper groups
*/
for (const key in lib) {
const group = lib[key];

module.exports[key] = function(options) {
function exportGroup(group) {
group = Object.assign({}, group);
return function(options) {
options = options || {};
var hbs = options.handlebars || options.hbs || require('handlebars');
module.exports.handlebars = hbs;
var hbs = options.handlebars || options.hbs || Handlebars;
hbs.registerHelper(group);
return group;
};
}
};
};

/**
* Expose `utils`
*/
export const array = exportGroup(lib.array);
export const code = exportGroup(lib.code);
export const collection = exportGroup(lib.collection);
export const comparison = exportGroup(lib.comparison);
export const html = exportGroup(lib.html);
export const i18n = exportGroup(lib.i18n);
export const inflection = exportGroup(lib.inflection);
export const match = exportGroup(lib.match);
export const math = exportGroup(lib.math);
export const misc = exportGroup(lib.misc);
export const number = exportGroup(lib.number);
export const object = exportGroup(lib.object);
export const path = exportGroup(lib.path);
export const regex = exportGroup(lib.regex);
export const string = exportGroup(lib.string);
export const url = exportGroup(lib.url);
export const uuid = exportGroup(lib.uuid);

module.exports.utils = require('./lib/utils');
import * as _utils from './lib/utils/index.js';
export const utils = _utils;
Loading