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
Migrate html
  • Loading branch information
adrinr committed Dec 3, 2024
commit 9a2c3b1722ad365950d0658531e72a67e7532c28
40 changes: 18 additions & 22 deletions lib/fs.js → lib/fs.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
'use strict';

var fs = require('fs');
var path = require('path');
var util = require('./utils/handlebarsUtils');
var number = require('./number');
var helpers = module.exports;
const kindOf = require('kind-of');
const isGlob = require('is-glob');
const micromatch = require('micromatch');
import { readFileSync, readdirSync, statSync } from 'fs';
import { join } from 'path';
import { isOptions } from './utils/handlebarsUtils';
import { bytes } from './number';

/**
* Helper `fileSize` is deprecated. Use `helper.prettyBytes` instead.
*/
import kindOf from 'kind-of';
import isGlob from 'is-glob';
import { matcher } from 'micromatch';

helpers.fileSize = number.bytes;
export const fileSize = bytes;

/**
* Read a file from the file system. This is useful in composing
Expand All @@ -28,9 +24,9 @@ helpers.fileSize = number.bytes;
* @api public
*/

helpers.read = function(filepath, options) {
return fs.readFileSync(filepath, 'utf8');
};
export function read(filepath, options) {
return readFileSync(filepath, 'utf8');
}

/**
* Return an array of files from the given
Expand All @@ -41,12 +37,12 @@ helpers.read = function(filepath, options) {
* @api public
*/

helpers.readdir = function(dir, filter) {
var files = fs.readdirSync(dir);
export function readdir(dir, filter) {
var files = readdirSync(dir);
files = files.map(function(fp) {
return path.join(dir, fp);
return join(dir, fp);
});
if (util.isOptions(filter)) {
if (isOptions(filter)) {
return files;
}
if (typeof filter === 'function') {
Expand All @@ -58,13 +54,13 @@ helpers.readdir = function(dir, filter) {
});
}
if (isGlob(filter)) {
return files.filter(micromatch.matcher(filter));
return files.filter(matcher(filter));
}
if (['isFile', 'isDirectory'].indexOf(filter) !== -1) {
return files.filter(function(fp) {
var stat = fs.statSync(fp);
var stat = statSync(fp);
return stat[filter]();
});
}
return files;
};
}
56 changes: 29 additions & 27 deletions lib/html.js → lib/html.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';

var path = require('path');
var util = require('./utils/handlebarsUtils');
var html = require('./utils/html');
var parseAttr = html.parseAttributes;
var helpers = module.exports;
const htmlTag = require('html-tag');
import { extname, posix } from 'path';
import handlebarsUtils from './utils/handlebarsUtils.js';
import { parseAttributes, sanitize as htmlSanitize } from './utils/html.js';
var parseAttr = parseAttributes;

import htmlTag from 'html-tag';

const { arrayify } = handlebarsUtils;

/**
* Stringify attributes on the options `hash`.
Expand All @@ -20,10 +22,10 @@ const htmlTag = require('html-tag');
* @api public
*/

helpers.attr = function(options) {
export function attr(options) {
var val = parseAttr((options && options.hash) || {});
return val.trim() ? ' ' + val : '';
};
}

/**
* Add an array of `<link>` tags. Automatically resolves
Expand All @@ -42,37 +44,37 @@ helpers.attr = function(options) {
* @api public
*/

helpers.css = function(list, options) {
export function css(list, options) {
if (arguments.length < 2) {
options = list;
list = [];
}

var styles = util.arrayify(list);
var styles = arrayify(list);
var assets = '';

if (this && this.options) {
assets = this.options.assets || '';
}

if (options.hash.href) {
styles = util.arrayify(options.hash.href);
styles = arrayify(options.hash.href);
}

return styles.map(function(item) {
var ext = path.extname(item);
var ext = extname(item);
var fp = item;

if (!/(^\/\/)|(:\/\/)/.test(item)) {
fp = path.posix.join(assets, item);
fp = posix.join(assets, item);
}

if (ext === '.less') {
return `<link type="text/css" rel="stylesheet/less" href="${fp}">`;
}
return `<link type="text/css" rel="stylesheet" href="${fp}">`;
}).join('\n');
};
}

/**
* Generate one or more `<script></script>` tags with paths/urls to
Expand All @@ -86,7 +88,7 @@ helpers.css = function(list, options) {
* @api public
*/

helpers.js = function(context) {
export function js(context) {
if (typeof context === 'object' && context.hash) {
var attr = parseAttr(context.hash);
return `<script${attr ? ' ' + attr : ''}></script>`;
Expand All @@ -96,13 +98,13 @@ helpers.js = function(context) {
return `<script src="${context}"></script>`;
}

context = util.arrayify(context);
context = arrayify(context);
return context.map(function(fp) {
return (path.extname(fp) === '.coffee')
return (extname(fp) === '.coffee')
? htmlTag('script', { type: 'text/coffeescript', src: fp })
: htmlTag('script', { src: fp });
}).join('\n');
};
}

/**
* Strip HTML tags from a string, so that only the text nodes
Expand All @@ -118,9 +120,9 @@ helpers.js = function(context) {
* @api public
*/

helpers.sanitize = function(str) {
return html.sanitize(str);
};
export function sanitize(str) {
return htmlSanitize(str);
}

/**
* Block helper for creating unordered lists (`<ul></ul>`)
Expand All @@ -132,14 +134,14 @@ helpers.sanitize = function(str) {
* @api public
*/

helpers.ul = function(context, options) {
export function ul(context, options) {
return ('<ul ' + (parseAttr(options.hash)) + '>') + context.map(function(item) {
if (typeof item !== 'string') {
item = options.fn(item);
}
return '<li>' + item + '</li>';
}).join('\n') + '</ul>';
};
}

/**
* Block helper for creating ordered lists (`<ol></ol>`)
Expand All @@ -151,14 +153,14 @@ helpers.ul = function(context, options) {
* @api public
*/

helpers.ol = function(context, options) {
export function ol(context, options) {
return ('<ol ' + (parseAttr(options.hash)) + '>') + context.map(function(item) {
if (typeof item !== 'string') {
item = options.fn(item);
}
return '<li>' + item + '</li>';
}).join('\n') + '</ol>';
};
}

/**
* Returns a `<figure>` with a thumbnail linked to a full picture
Expand All @@ -173,7 +175,7 @@ helpers.ol = function(context, options) {
* @api public
*/

helpers.thumbnailImage = function(context) {
export function thumbnailImage(context) {
var figure = '';
var image = '';

Expand Down Expand Up @@ -215,4 +217,4 @@ helpers.thumbnailImage = function(context) {

figure += '</figure>';
return figure;
};
}
2 changes: 1 addition & 1 deletion lib/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as array from './array.mjs';
import * as code from './code.mjs';
import * as collection from './collection.mjs';
import * as comparison from './comparison.mjs';
import html from './html.js';
import * as html from './html.mjs';
import * as i18n from './i18n.mjs';
import inflection from './inflection.js';
import match from './match.js';
Expand Down