From 94d24390bfe0ab9c3168d5acc5a3107d108536b9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 11:30:27 +0100 Subject: [PATCH 01/46] Allow mocha running for mjs --- .mocharc.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.mocharc.json b/.mocharc.json index a97a2961..55d9531b 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,4 +1,7 @@ { - "extension": ["js"], - "spec": "test/**/*.js" + "extension": [ + "js", + "mjs" + ], + "spec": "test/**/*.{js,mjs}" } \ No newline at end of file From 657466ed17cedf7c66743b274b51b73fd2d74268 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 11:30:43 +0100 Subject: [PATCH 02/46] Convert uuid to mjs --- lib/uuid.js | 4 +--- test/match.js | 12 ++++++------ test/uuid.js | 13 ------------- test/uuid.mjs | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 22 deletions(-) delete mode 100644 test/uuid.js create mode 100644 test/uuid.mjs diff --git a/lib/uuid.js b/lib/uuid.js index 6c6a5bdd..be8d67cb 100644 --- a/lib/uuid.js +++ b/lib/uuid.js @@ -1,5 +1,4 @@ const uuid = require('uuid'); -const helpers = module.exports; /** * Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function). @@ -8,7 +7,6 @@ const helpers = module.exports; * @api public * @example {{ uuid }} -> f34ebc66-93bd-4f7c-b79b-92b5569138bc */ -helpers.uuid = function() { +module.exports.uuid = function() { return uuid.v4(); }; - diff --git a/test/match.js b/test/match.js index ec1f111c..7e9ff659 100644 --- a/test/match.js +++ b/test/match.js @@ -13,14 +13,14 @@ var rootFiles = fs.readdirSync(path.join(__dirname, '..')); describe('matching', function() { describe('match', function() { it('should use the main micromatch function to filter an array', function() { - var fn = hbs.compile('{{match files "(a|u)*.js"}}'); - assert.equal(fn({files: testFiles}), 'array.js,url.js,utils.js,uuid.js'); + var fn = hbs.compile('{{match files "(a|u)*.(mjs|js)"}}'); + assert.equal(fn({files: testFiles}), 'array.js,url.js,utils.js,uuid.mjs'); }); it('should take an array of patterns', function() { - var ctx = {files: testFiles, patterns: ['(a|u)*.js', 'f*.js']}; + var ctx = {files: testFiles, patterns: ['(a|u)*.(mjs|js)', 'f*.js']}; var fn = hbs.compile('{{match files patterns}}'); - assert.equal(fn(ctx), 'array.js,url.js,utils.js,uuid.js'); + assert.equal(fn(ctx), 'array.js,url.js,utils.js,uuid.mjs'); }); it('should take options from the "options[helper name]" object', function() { @@ -36,8 +36,8 @@ describe('matching', function() { }); it('should use return matching items', function() { - var fn = hbs.compile('{{match files "(a|u)*.js"}}'); - assert.equal(fn({files: testFiles}), 'array.js,url.js,utils.js,uuid.js'); + var fn = hbs.compile('{{match files "(a|u)*.(mjs|js)"}}'); + assert.equal(fn({files: testFiles}), 'array.js,url.js,utils.js,uuid.mjs'); }); it('should take options from the "options[helper name]" object', function() { diff --git a/test/uuid.js b/test/uuid.js deleted file mode 100644 index 5d845780..00000000 --- a/test/uuid.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -require('mocha'); -const assert = require('assert'); -const uuid = require('../lib/uuid'); - -describe('uuid', function() { - describe('generate', function() { - it('should generate a valid uuid', function() { - assert.match(uuid.uuid(), /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i); - }); - }); -}); diff --git a/test/uuid.mjs b/test/uuid.mjs new file mode 100644 index 00000000..af9de0d3 --- /dev/null +++ b/test/uuid.mjs @@ -0,0 +1,16 @@ +"use strict"; + +import "mocha"; +import { match } from "assert"; +import { uuid } from "../lib/uuid.js"; + +describe("uuid", function () { + describe("generate", function () { + it("should generate a valid uuid", function () { + match( + uuid(), + /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i + ); + }); + }); +}); From c2cce12c76f7dfb6cb36db15f3c332634da3c5b3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 12:20:09 +0100 Subject: [PATCH 03/46] Migrate array and match tests --- index.mjs | 78 +++++++++++++++ test/{array.js => array.mjs} | 178 ++++++++++++++++++----------------- test/{match.js => match.mjs} | 31 +++--- 3 files changed, 186 insertions(+), 101 deletions(-) create mode 100644 index.mjs rename test/{array.js => array.mjs} (75%) rename test/{match.js => match.mjs} (70%) diff --git a/index.mjs b/index.mjs new file mode 100644 index 00000000..b00f0c4a --- /dev/null +++ b/index.mjs @@ -0,0 +1,78 @@ +/*! + * handlebars-helpers + * + * Copyright (c) 2013-2017, Jon Schlinkert, Brian Woodward. + * Released under the MIT License. + */ + +'use strict'; + +import lib from './lib/index.js'; + +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); + + +/** + * Expose helpers + */ + +export default function helpers(groups, options) { + if (typeof groups === 'string') { + groups = [groups]; + } else if (!Array.isArray(groups)) { + options = groups; + groups = null; + } + + options = options || {}; + var hbs = options.handlebars || options.hbs || require('handlebars'); + module.exports.handlebars = hbs; + + if (groups) { + groups.forEach(function(key) { + hbs.registerHelper(lib[key]); + }); + } else { + for (const key in lib) { + const group = lib[key]; + hbs.registerHelper(group); + } + } + + return hbs.helpers; +}; + + + +/** + * Expose helper groups + */ +function exportGroup(group){ + return function(options) { + options = options || {}; + var hbs = options.handlebars || options.hbs || require('handlebars'); + hbs.registerHelper(group); + return group; +}}; + +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) + + +export * as utils from './lib/utils/index.js' diff --git a/test/array.js b/test/array.mjs similarity index 75% rename from test/array.js rename to test/array.mjs index c7da5c30..93e66d1c 100644 --- a/test/array.js +++ b/test/array.mjs @@ -1,97 +1,99 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.array({handlebars: hbs}); -helpers.string({handlebars: hbs}); +import 'mocha'; +import { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { array, string, object } from '../index.mjs'; +array({handlebars: hbs}); +string({handlebars: hbs}); +object({handlebars: hbs}); var context = {array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], duplicate: [ 'a', 'b', 'b', 'c', 'd', 'b', 'f', 'a', 'g']}; describe('array', function() { describe('after', function() { it('should return an empty string when undefined', function() { - assert.equal(hbs.compile('{{after}}')(), ''); + equal(hbs.compile('{{after}}')(), ''); }); it('should return all of the items in an array after the given index', function() { var fn = hbs.compile('{{after array 5}}'); - assert.equal(fn(context), 'f,g,h'); + equal(fn(context), 'f,g,h'); }); it('should return all of the items in an array after the specified count', function() { var fn = hbs.compile('{{after array 5}}'); - assert.equal(fn(context), 'f,g,h'); + equal(fn(context), 'f,g,h'); }); }); describe('arrayify', function() { it('should arrayify a value', function() { - assert.equal(hbs.compile('{{#each (arrayify .)}}{{.}}{{/each}}')('foo'), 'foo'); - assert.equal(hbs.compile('{{#each (arrayify .)}}{{.}}{{/each}}')(['foo']), 'foo'); + equal(hbs.compile('{{#each (arrayify .)}}{{.}}{{/each}}')('foo'), 'foo'); + equal(hbs.compile('{{#each (arrayify .)}}{{.}}{{/each}}')(['foo']), 'foo'); }); }); describe('before', function() { it('should return an empty string when undefined', function() { - assert.equal(hbs.compile('{{before}}')(), ''); + equal(hbs.compile('{{before}}')(), ''); }); it('should return all of the items in an array before the given index', function() { var fn = hbs.compile('{{before array 5}}'); - assert.equal(fn(context), 'a,b,c,d'); + equal(fn(context), 'a,b,c,d'); }); }); describe('each', function() { it('should use the key and value of each property in an object inside a block', function() { var fn = hbs.compile('{{#each obj}}{{@key}}: {{this}} {{/each}}'); - assert.equal(fn({obj: {fry: 3, bender: 120 }}), 'fry: 3 bender: 120 '); + equal(fn({obj: {fry: 3, bender: 120 }}), 'fry: 3 bender: 120 '); }); }); describe('eachIndex', function() { it('should render the block using the array and each item\'s index', function() { var fn = hbs.compile('{{#eachIndex array}} {{item}} is {{index}} {{/eachIndex}}'); - assert.equal(fn(context), ' a is 0 b is 1 c is 2 d is 3 e is 4 f is 5 g is 6 h is 7 '); + equal(fn(context), ' a is 0 b is 1 c is 2 d is 3 e is 4 f is 5 g is 6 h is 7 '); }); }); describe('first', function() { it('should return the first item in a collection', function() { var fn = hbs.compile('{{first foo}}'); - assert.equal(fn({foo: ['a', 'b', 'c']}), 'a'); + equal(fn({foo: ['a', 'b', 'c']}), 'a'); }); it('should return an array with the first two items in a collection', function() { var fn = hbs.compile('{{first foo 2}}'); - assert.equal(fn({foo: ['a', 'b', 'c']}), 'a,b'); + equal(fn({foo: ['a', 'b', 'c']}), 'a,b'); }); it('should return an empty string when undefined', function() { - assert.equal(hbs.compile('{{first}}')(), ''); + equal(hbs.compile('{{first}}')(), ''); }); it('should return the first item in an array', function() { var fn = hbs.compile('{{first foo}}'); - assert.equal(fn({foo: ['a', 'b', 'c']}), 'a'); + equal(fn({foo: ['a', 'b', 'c']}), 'a'); }); it('should return an array with the first two items in an array', function() { var fn = hbs.compile('{{first foo 2}}'); - assert.equal(fn({foo: ['a', 'b', 'c']}), 'a,b'); + equal(fn({foo: ['a', 'b', 'c']}), 'a,b'); }); }); describe('filter', function() { it('should render the block if the given string is in the array', function() { var source = '{{#filter array "d"}}AAA{{else}}BBB{{/filter}}'; - assert.equal(hbs.compile(source)(context), 'AAA'); + equal(hbs.compile(source)(context), 'AAA'); }); it('should render the inverse block if the string is not in the array:', function() { var source = '{{#filter array "foo"}}AAA{{else}}BBB{{/filter}}'; - assert.equal(hbs.compile(source)(context), 'BBB'); + equal(hbs.compile(source)(context), 'BBB'); }); it('should render a block for each object that has a "first" property with the value "d"', function() { @@ -111,7 +113,7 @@ describe('array', function() { var source = '{{#filter collection "d" property="first"}}{{this.first}}{{else}}ZZZ{{/filter}}'; var fn = hbs.compile(source); - assert.equal(fn(ctx), 'd'); + equal(fn(ctx), 'd'); }); }); @@ -120,57 +122,57 @@ describe('array', function() { var arr = [{name: 'a'}, {name: 'b'}, {name: 'c'}]; var fn = hbs.compile('{{#forEach arr}}{{name}}{{/forEach}}'); - assert.equal(fn({arr: arr}), 'abc'); + equal(fn({arr: arr}), 'abc'); }); it('should expose `index`', function() { var arr = [{name: 'a'}, {name: 'b'}, {name: 'c'}]; var fn = hbs.compile('{{#forEach arr}}{{index}}{{/forEach}}'); - assert.equal(fn({arr: arr}), '123'); + equal(fn({arr: arr}), '123'); }); it('should expose `total`', function() { var arr = [{name: 'a'}, {name: 'b'}, {name: 'c'}]; var fn = hbs.compile('{{#forEach arr}}{{total}}{{/forEach}}'); - assert.equal(fn({arr: arr}), '333'); + equal(fn({arr: arr}), '333'); }); it('should expose `isFirst`', function() { var arr = [{name: 'a'}, {name: 'b'}, {name: 'c'}]; var fn = hbs.compile('{{#forEach arr}}{{isFirst}}{{/forEach}}'); - assert.equal(fn({arr: arr}), 'truefalsefalse'); + equal(fn({arr: arr}), 'truefalsefalse'); }); it('should expose `isLast`', function() { var arr = [{name: 'a'}, {name: 'b'}, {name: 'c'}]; var fn = hbs.compile('{{#forEach arr}}{{isLast}}{{/forEach}}'); - assert.equal(fn({arr: arr}), 'falsefalsetrue'); + equal(fn({arr: arr}), 'falsefalsetrue'); }); }); describe('inArray', function() { it('should render the first block when a value exists in the array', function() { var fn = hbs.compile('{{#inArray array "d"}}AAA{{else}}BBB{{/inArray}}'); - assert.equal(fn(context), 'AAA'); + equal(fn(context), 'AAA'); }); it('should render the inverse block when a value does not exist', function() { var fn = hbs.compile('{{#inArray array "foo"}}AAA{{else}}BBB{{/inArray}}'); - assert.equal(fn(context), 'BBB'); + equal(fn(context), 'BBB'); }); }); describe('isArray', function() { it('should return true if the value is an array', function() { - assert.equal(hbs.compile('{{isArray "foo"}}')(), 'false'); - assert.equal(hbs.compile('{{isArray \'["foo"]\'}}')(), 'false'); - assert.equal(hbs.compile('{{isArray foo}}')({foo: ['foo']}), 'true'); - assert.equal(hbs.compile('{{isArray (arrayify "foo")}}')(), 'true'); - assert.equal(hbs.compile('{{isArray (arrayify ["foo"])}}')(), 'true'); + equal(hbs.compile('{{isArray "foo"}}')(), 'false'); + equal(hbs.compile('{{isArray \'["foo"]\'}}')(), 'false'); + equal(hbs.compile('{{isArray foo}}')({foo: ['foo']}), 'true'); + equal(hbs.compile('{{isArray (arrayify "foo")}}')(), 'true'); + equal(hbs.compile('{{isArray (arrayify ["foo"])}}')(), 'true'); }); }); @@ -178,89 +180,89 @@ describe('array', function() { var ctx = {array: ['foo', 'bar', 'baz']}; it('should return a null value for undefined array', function() { - assert.equal(hbs.compile('{{#if (itemAt)}}exists{{else}}notfound{{/if}}')(), 'notfound'); + equal(hbs.compile('{{#if (itemAt)}}exists{{else}}notfound{{/if}}')(), 'notfound'); }); it('should return a null value for empty array', function() { var fn = hbs.compile('{{#if (itemAt array)}}exists{{else}}notfound{{/if}}'); - assert.equal(fn({array: []}), 'notfound'); + equal(fn({array: []}), 'notfound'); }); it('should return a null value for exceed bound', function() { var fn = hbs.compile('{{#if (itemAt array 999)}}exists{{else}}notfound{{/if}}'); - assert.equal(fn(ctx), 'notfound'); + equal(fn(ctx), 'notfound'); }); it('should return a first value of array for undefined index', function() { var fn = hbs.compile('{{itemAt array}}'); - assert.equal(fn(ctx), 'foo'); + equal(fn(ctx), 'foo'); }); it('should return a first value of array for zero index', function() { var fn = hbs.compile('{{itemAt array 0}}'); - assert.equal(fn(ctx), 'foo'); + equal(fn(ctx), 'foo'); }); it('should return a second value of array', function() { var fn = hbs.compile('{{itemAt array 1}}'); - assert.equal(fn(ctx), 'bar'); + equal(fn(ctx), 'bar'); }); it('should return a last value of array', function() { var fn = hbs.compile('{{itemAt array -1}}'); - assert.equal(fn(ctx), 'baz'); + equal(fn(ctx), 'baz'); }); it('should return a last before value of array', function() { var fn = hbs.compile('{{itemAt array -2}}'); - assert.equal(fn(ctx), 'bar'); + equal(fn(ctx), 'bar'); }); }); describe('join', function() { it('should return an empty string when undefined', function() { - assert.equal(hbs.compile('{{join}}')(), ''); + equal(hbs.compile('{{join}}')(), ''); }); it('should join items by the default separator', function() { - assert.equal(hbs.compile('{{join array}}')(context), 'a, b, c, d, e, f, g, h'); + equal(hbs.compile('{{join array}}')(context), 'a, b, c, d, e, f, g, h'); }); it('should join by a custom separator', function() { var fn = hbs.compile('{{join array " | "}}'); - assert.equal(fn(context), 'a | b | c | d | e | f | g | h'); + equal(fn(context), 'a | b | c | d | e | f | g | h'); }); }); describe('last', function() { it('should return an empty string when undefined', function() { - assert.equal(hbs.compile('{{last}}')(), ''); + equal(hbs.compile('{{last}}')(), ''); }); it('should return the last item in an array', function() { - assert.equal(hbs.compile('{{last array}}')(context), 'h'); + equal(hbs.compile('{{last array}}')(context), 'h'); }); it('should return an array with the last two items in an array', function() { - assert.equal(hbs.compile('{{last array 2}}')(context), 'g,h'); + equal(hbs.compile('{{last array 2}}')(context), 'g,h'); }); }); describe('lengthEqual', function() { it('should render the first block if length is the given number', function() { var fn = hbs.compile('{{#lengthEqual array 8}}AAA{{else}}BBB{{/lengthEqual}}'); - assert.equal(fn(context), 'AAA'); + equal(fn(context), 'AAA'); }); it('should render the inverse block if length is not the given number', function() { var fn = hbs.compile('{{#lengthEqual array 3}}AAA{{else}}BBB{{/lengthEqual}}'); - assert.equal(fn(context), 'BBB'); + equal(fn(context), 'BBB'); }); }); describe('map', function() { it('should return an empty string when undefined', function() { - assert.equal(hbs.compile('{{map}}')(), ''); + equal(hbs.compile('{{map}}')(), ''); }); it('should map the items in the array and return new values', function() { @@ -269,7 +271,7 @@ describe('array', function() { return str + str; }; var fn = hbs.compile('{{map array double}}'); - assert.equal(fn(locals), 'aa,bb,cc'); + equal(fn(locals), 'aa,bb,cc'); }); it('should work with subexpressions:', function() { @@ -278,17 +280,17 @@ describe('array', function() { return str + str; }; var fn = hbs.compile('{{map (split "a,b,c" ",") double}}'); - assert.equal(fn(locals), 'aa,bb,cc'); + equal(fn(locals), 'aa,bb,cc'); }); it('should return the value when not an array', function() { var fn = hbs.compile('{{map (split "b,c,a" ",") reverse}}'); - assert.equal(fn(context), 'b,c,a'); + equal(fn(context), 'b,c,a'); }); it('should return the value when no function is passed', function() { var fn = hbs.compile('{{map (split "b,c,a" ",")}}'); - assert.equal(fn(context), 'b,c,a'); + equal(fn(context), 'b,c,a'); }); }); @@ -296,7 +298,7 @@ describe('array', function() { it('should get the given value from objects on an array', function() { var ctx = {array: [{a: 'x'}, {a: 'y'}, {a: 'z'}]}; var fn = hbs.compile('{{pluck array "a"}}'); - assert.equal(fn(ctx), 'x,y,z'); + equal(fn(ctx), 'x,y,z'); }); }); @@ -307,12 +309,12 @@ describe('array', function() { return typeof val === 'string'; }; var fn = hbs.compile('{{#some array isString}}AAA{{else}}BBB{{/some}}'); - assert.equal(fn(ctx), 'AAA'); + equal(fn(ctx), 'AAA'); }); it('should render the inverse block if the array is undefined', function() { var fn = hbs.compile('{{#some array isString}}AAA{{else}}BBB{{/some}}'); - assert.equal(fn(), 'BBB'); + equal(fn(), 'BBB'); }); it('should render the inverse block if falsey', function() { @@ -321,7 +323,7 @@ describe('array', function() { return typeof val === 'string'; }; var fn = hbs.compile('{{#some array isString}}AAA{{else}}BBB{{/some}}'); - assert.equal(fn(ctx), 'BBB'); + equal(fn(ctx), 'BBB'); }); }); @@ -329,52 +331,52 @@ describe('array', function() { it('should return an empty string when an invalid value is passed:', function() { var fn = hbs.compile('{{sort}}'); var res = fn(); - assert.equal(res, ''); + equal(res, ''); }); it('should sort the items in the array', function() { var fn = hbs.compile('{{sort array}}'); var res = fn({array: ['c', 'a', 'b']}); - assert.equal(res, 'a,b,c'); + equal(res, 'a,b,c'); }); it('should sort the items in a frozen array', function() { var fn = hbs.compile('{{sort array}}'); var res = fn({array: Object.freeze(['c', 'a', 'b'])}); - assert.equal(res, 'a,b,c'); + equal(res, 'a,b,c'); }); it('should return all items in an array sorted in lexicographical order', function() { var fn = hbs.compile('{{sort array}}'); - assert.equal(fn(context), 'a,b,c,d,e,f,g,h'); + equal(fn(context), 'a,b,c,d,e,f,g,h'); }); it('should sort the items in the array in reverse order:', function() { var fn = hbs.compile('{{sort array reverse="true"}}'); var res = fn({array: ['c', 'a', 'b']}); - assert.equal(res, 'c,b,a'); + equal(res, 'c,b,a'); }); it('should sort the items in a frozen array in reverse order:', function() { var fn = hbs.compile('{{sort array reverse="true"}}'); var res = fn({array: Object.freeze(['c', 'a', 'b'])}); - assert.equal(res, 'c,b,a'); + equal(res, 'c,b,a'); }); }); describe('sortBy', function() { it('should return an empty string when undefined', function() { - assert.equal(hbs.compile('{{sortBy}}')(), ''); + equal(hbs.compile('{{sortBy}}')(), ''); }); it('should sort the items in an array', function() { var fn = hbs.compile('{{sortBy array}}'); - assert.equal(fn({array: ['b', 'c', 'a']}), 'a,b,c'); + equal(fn({array: ['b', 'c', 'a']}), 'a,b,c'); }); it('should return an empty string when the array is invalid:', function() { var fn = hbs.compile('{{sortBy foo}}'); - assert.equal(fn(context), ''); + equal(fn(context), ''); }); it('should take a compare function', function() { @@ -383,42 +385,42 @@ describe('array', function() { return b.localeCompare(a); }; var fn = hbs.compile('{{sortBy array compare}}'); - assert.equal(fn(locals), 'c,b,a'); + equal(fn(locals), 'c,b,a'); }); it('should sort based on object key:', function() { var ctx = {arr: [{a: 'zzz'}, {a: 'aaa'}]}; - hbs.registerHelper(helpers.object()); + hbs.registerHelper(object()); var fn = hbs.compile('{{{stringify (sortBy arr "a") 0}}}'); - assert.equal(fn(ctx), '[{"a":"aaa"},{"a":"zzz"}]'); + equal(fn(ctx), '[{"a":"aaa"},{"a":"zzz"}]'); }); }); describe('withAfter', function() { it('should use all of the items in an array after the specified count', function() { var fn = hbs.compile('{{#withAfter array 5}}<{{this}}>{{/withAfter}}'); - assert.equal(fn(context), ''); + equal(fn(context), ''); }); }); describe('withBefore', function() { it('should use all of the items in an array before the specified count', function() { var fn = hbs.compile('{{#withBefore array 5}}<{{this}}>{{/withBefore}}'); - assert.equal(fn(context), ''); + equal(fn(context), ''); }); }); describe('withFirst', function() { it('should use the first item in an array', function() { var fn = hbs.compile('{{#withFirst array}}{{this}} is smart.{{/withFirst}}'); - assert.equal(fn(context), 'a is smart.'); + equal(fn(context), 'a is smart.'); }); it('should return an empty string when no array is passed:', function() { - assert.equal(hbs.compile('{{#withFirst}}{{/withFirst}}')(), ''); + equal(hbs.compile('{{#withFirst}}{{/withFirst}}')(), ''); }); it('should use the first two items in an array', function() { var fn = hbs.compile('{{#withFirst array 2}}{{this}} is smart.{{/withFirst}}'); - assert.equal(fn(context), 'a is smart.b is smart.'); + equal(fn(context), 'a is smart.b is smart.'); }); }); @@ -428,38 +430,38 @@ describe('array', function() { var res = fn({ collection: [ {name: 'a'}, {name: 'b'}, {name: 'c'}, {name: 'd'}, {name: 'e'}, {name: 'f'}, {name: 'g'}, {name: 'h'}] }); - assert.equal(res, 'abcd
efgh
'); + equal(res, 'abcd
efgh
'); }); }); describe('withLast', function() { it('should return an empty string when undefined', function() { - assert.equal(hbs.compile('{{withLast}}')(), ''); + equal(hbs.compile('{{withLast}}')(), ''); }); it('should use the last item in an array', function() { var fn = hbs.compile('{{#withLast array}}{{this}} is dumb.{{/withLast}}'); - assert.equal(fn(context), 'h is dumb.'); + equal(fn(context), 'h is dumb.'); }); it('should use the last two items in an array', function() { var fn = hbs.compile('{{#withLast array 2}}{{this}} is dumb.{{/withLast}}'); - assert.equal(fn(context), 'g is dumb.h is dumb.'); + equal(fn(context), 'g is dumb.h is dumb.'); }); }); describe('withSort', function() { it('should return an empty string when array is undefined', function() { var fn = hbs.compile('{{#withSort}}{{this}}{{/withSort}}'); - assert.equal(fn(context), ''); + equal(fn(context), ''); }); it('should sort the array in lexicographical order', function() { var fn = hbs.compile('{{#withSort array}}{{this}}{{/withSort}}'); - assert.equal(fn(context), 'abcdefgh'); + equal(fn(context), 'abcdefgh'); }); it('should sort the array in reverse order', function() { var fn = hbs.compile('{{#withSort array reverse="true"}}{{this}}{{/withSort}}'); - assert.equal(fn(context), 'hgfedcba'); + equal(fn(context), 'hgfedcba'); }); it('should sort the array by deliveries', function() { @@ -471,7 +473,7 @@ describe('array', function() { {name: 'd', deliveries: -12 } ] }); - assert.equal(res, 'd: -12
b: 239
f: 8021
'); + equal(res, 'd: -12
b: 239
f: 8021
'); }); it('should sort the array by deliveries in reverse order', function() { @@ -483,18 +485,18 @@ describe('array', function() { {name: 'd', deliveries: -12 } ] }); - assert.equal(res, 'f: 8021
b: 239
d: -12
'); + equal(res, 'f: 8021
b: 239
d: -12
'); }); }); describe('unique', function() { it('should return empty string when the array is null', function() { var fn = hbs.compile('{{#unique}}{{this}}{{/unique}}'); - assert.equal(fn(context), ''); + equal(fn(context), ''); }); it('should return array with unique items', function() { var fn = hbs.compile('{{#unique duplicate}}{{this}}{{/unique}}'); - assert.equal(fn(context).toString(), 'a,b,c,d,f,g'); + equal(fn(context).toString(), 'a,b,c,d,f,g'); }); }); diff --git a/test/match.js b/test/match.mjs similarity index 70% rename from test/match.js rename to test/match.mjs index 7e9ff659..36a3cbc8 100644 --- a/test/match.js +++ b/test/match.mjs @@ -1,32 +1,37 @@ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); +import { readdirSync } from 'fs'; +import assert, { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import helpers from '../index.js'; helpers.match({handlebars: hbs}); -var testFiles = fs.readdirSync(__dirname); -var rootFiles = fs.readdirSync(path.join(__dirname, '..')); +import { fileURLToPath } from 'url'; +import path from 'path'; +const __filename = fileURLToPath(import.meta.url); + +const __dirname = path.dirname(__filename); +var testFiles = readdirSync(__dirname); +var rootFiles = readdirSync(path.join(__dirname, '..')); describe('matching', function() { describe('match', function() { it('should use the main micromatch function to filter an array', function() { var fn = hbs.compile('{{match files "(a|u)*.(mjs|js)"}}'); - assert.equal(fn({files: testFiles}), 'array.js,url.js,utils.js,uuid.mjs'); + equal(fn({files: testFiles}), 'array.mjs,url.js,utils.js,uuid.mjs'); }); it('should take an array of patterns', function() { var ctx = {files: testFiles, patterns: ['(a|u)*.(mjs|js)', 'f*.js']}; var fn = hbs.compile('{{match files patterns}}'); - assert.equal(fn(ctx), 'array.js,url.js,utils.js,uuid.mjs'); + equal(fn(ctx), 'array.mjs,url.js,utils.js,uuid.mjs'); }); it('should take options from the "options[helper name]" object', function() { var ctx = {files: testFiles, options: {match: {dot: true}}}; var fn = hbs.compile('{{match files "*"}}'); - assert(/array\.js/.test(fn(ctx))); + assert(/array\.mjs/.test(fn(ctx))); }); it('should take options from the hash', function() { @@ -37,7 +42,7 @@ describe('matching', function() { it('should use return matching items', function() { var fn = hbs.compile('{{match files "(a|u)*.(mjs|js)"}}'); - assert.equal(fn({files: testFiles}), 'array.js,url.js,utils.js,uuid.mjs'); + equal(fn({files: testFiles}), 'array.mjs,url.js,utils.js,uuid.mjs'); }); it('should take options from the "options[helper name]" object', function() { @@ -60,8 +65,8 @@ describe('matching', function() { describe('isMatch', function() { it('should return true if the given value matches the glob', function() { - assert.equal(hbs.compile('{{isMatch "foo.js" "*.js"}}')(), 'true'); - assert.equal(hbs.compile('{{isMatch "foo.js" "*.json"}}')(), 'false'); + equal(hbs.compile('{{isMatch "foo.js" "*.js"}}')(), 'true'); + equal(hbs.compile('{{isMatch "foo.js" "*.json"}}')(), 'false'); }); }); }); From 879c1ca1ab949781d1530f11e0430b700e657e5b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 12:23:11 +0100 Subject: [PATCH 04/46] Migrate more tests --- index.mjs | 1 - test/{object.js => object.mjs} | 85 +++++++------- test/path.js | 89 --------------- test/path.mjs | 90 +++++++++++++++ test/{string.js => string.mjs} | 197 +++++++++++++++++---------------- test/support/index.js | 16 +-- 6 files changed, 237 insertions(+), 241 deletions(-) rename test/{object.js => object.mjs} (71%) delete mode 100644 test/path.js create mode 100644 test/path.mjs rename test/{string.js => string.mjs} (74%) diff --git a/index.mjs b/index.mjs index b00f0c4a..c3611576 100644 --- a/index.mjs +++ b/index.mjs @@ -27,7 +27,6 @@ export default function helpers(groups, options) { options = options || {}; var hbs = options.handlebars || options.hbs || require('handlebars'); - module.exports.handlebars = hbs; if (groups) { groups.forEach(function(key) { diff --git a/test/object.js b/test/object.mjs similarity index 71% rename from test/object.js rename to test/object.mjs index 2f5a246f..03795773 100644 --- a/test/object.js +++ b/test/object.mjs @@ -1,13 +1,14 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var support = require('./support'); -var expected = support.expected('object'); -var helpers = require('..'); -var hbs = require('handlebars').create(); -helpers.math({handlebars: hbs}); -helpers.object({handlebars: hbs}); +import 'mocha'; +import { equal, deepEqual } from 'assert'; +import { expected as _expected } from './support/index.js'; +var expected = _expected('object'); +import helpers, { math, object as _object } from '../index.mjs'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +math({handlebars: hbs}); +_object({handlebars: hbs}); var context = {object: {a: 'b', c: 'd', e: 'f'}}; @@ -16,46 +17,46 @@ describe('object', function() { it('should extend multiple objects into one:', function() { var fn = hbs.compile('{{{stringify (extend a d g)}}}'); var actual = fn({a: {b: 'c'}, d: {e: 'f'}, g: {h: 'i'}}); - assert.equal(actual, expected('extend.txt')); + equal(actual, expected('extend.txt')); }); it('should work as a non-helper util:', function() { var actual = helpers().extend({a: {b: 'c'}}, {d: {e: 'f'}}, {g: {h: 'i'}}); - assert.deepEqual(actual, { a: { b: 'c' }, d: { e: 'f' }, g: { h: 'i' } }); + deepEqual(actual, { a: { b: 'c' }, d: { e: 'f' }, g: { h: 'i' } }); }); it('should skip over sparse objects', function() { var actual = helpers().extend({a: {b: 'c'}}, null, {g: {h: 'i'}}); - assert.deepEqual(actual, { a: { b: 'c' }, g: { h: 'i' } }); + deepEqual(actual, { a: { b: 'c' }, g: { h: 'i' } }); }); }); describe('forIn', function() { it('should iterate over each property in an object:', function() { var fn = hbs.compile('{{#forIn this}} {{@key}} {{.}} {{/forIn}}'); - assert.equal(fn(context.object), ' a b c d e f '); + equal(fn(context.object), ' a b c d e f '); }); it('should return the inverse block if no object is passed:', function() { var fn = hbs.compile('{{#forIn}} {{.}} {{else}} Nada. {{/forIn}}'); - assert.equal(fn(context.object), ' Nada. '); + equal(fn(context.object), ' Nada. '); }); it('should expose private variables:', function() { var fn = hbs.compile('{{#forIn this abc=object}} {{@abc.a}} {{/forIn}}'); - assert.equal(fn(context), ' b '); + equal(fn(context), ' b '); }); }); describe('forOwn', function() { it('should iterate over each property in an object:', function() { var fn = hbs.compile('{{#forOwn this}} {{@key}} {{.}} {{/forOwn}}'); - assert.equal(fn(context.object), ' a b c d e f '); + equal(fn(context.object), ' a b c d e f '); }); it('should return the inverse block if no object is passed:', function() { var fn = hbs.compile('{{#forOwn}} {{.}} {{else}} Nada. {{/forOwn}}'); - assert.equal(fn(context.object), ' Nada. '); + equal(fn(context.object), ' Nada. '); }); it('should only expose "own" keys:', function() { @@ -65,61 +66,61 @@ describe('object', function() { } Foo.prototype.c = 'd'; var fn = hbs.compile('{{#forOwn this}} {{.}} {{/forOwn}}'); - assert.equal(fn(new Foo()), ' b c '); + equal(fn(new Foo()), ' b c '); }); it('should expose private variables:', function() { var fn = hbs.compile('{{#forOwn this abc=object}} {{@abc.c}} {{/forOwn}}'); - assert.equal(fn(context), ' d '); + equal(fn(context), ' d '); }); }); describe('getObject', function() { it('should get an object from the context', function() { var one = hbs.compile('{{{stringify (getObject "a" this)}}}')({a: 'b'}); - assert.equal(one, '{"a":"b"}'); + equal(one, '{"a":"b"}'); var two = hbs.compile('{{{stringify (getObject "c" this)}}}')({c: 'd'}); - assert.equal(two, '{"c":"d"}'); + equal(two, '{"c":"d"}'); }); }); describe('toPath', function() { it('should return a path from provided arguments', function() { - assert.equal(hbs.compile('{{toPath "a" "b" "c"}}')(), 'a.b.c'); + equal(hbs.compile('{{toPath "a" "b" "c"}}')(), 'a.b.c'); }); it('should return a path from calculated arguments', function() { var t = hbs.compile('{{toPath "a" (add 1 1) "b"}}')(); - assert.equal(t, 'a.2.b'); + equal(t, 'a.2.b'); }); it('should return a `get` compatible path', function() { var fn = hbs.compile('{{get (toPath "a" (add 1 1) "j") this}}'); - assert.equal(fn({a: [{b: 'c', d: 'e'}, {f: 'g', h: 'i'}, {j: 'k', l: 'm'}]}), 'k'); + equal(fn({a: [{b: 'c', d: 'e'}, {f: 'g', h: 'i'}, {j: 'k', l: 'm'}]}), 'k'); }); }); describe('get', function() { it('should get a value from the context', function() { - assert.equal(hbs.compile('{{get "a" this}}')({a: 'b'}), 'b'); - assert.equal(hbs.compile('{{get "c" this}}')({c: 'd'}), 'd'); + equal(hbs.compile('{{get "a" this}}')({a: 'b'}), 'b'); + equal(hbs.compile('{{get "c" this}}')({c: 'd'}), 'd'); }); it('should get a nested value from the context', function() { var fn = hbs.compile('{{get "a.b.c.d" this}}'); - assert.equal(fn({a: {b: {c: {d: 'e'}}}}), 'e'); + equal(fn({a: {b: {c: {d: 'e'}}}}), 'e'); }); it('should work as a block helper', function() { var fn1 = hbs.compile('{{#get "a" this}} {{.}} {{/get}}'); - assert.equal(fn1(context.object), ' b '); + equal(fn1(context.object), ' b '); var fn2 = hbs.compile('{{#get "c" this}} {{.}} {{/get}}'); - assert.equal(fn2(context.object), ' d '); + equal(fn2(context.object), ' d '); }); it('should get the inverse block if not found', function() { var fn = hbs.compile('{{#get "foo" this}} {{.}} {{else}}Nope.{{/get}}'); - assert.equal(fn(context.object), 'Nope.'); + equal(fn(context.object), 'Nope.'); }); }); @@ -132,24 +133,24 @@ describe('object', function() { it('should return true if object has own property:', function() { var fn = hbs.compile('{{hasOwn this "a"}}'); - assert.equal(fn(new Foo()), 'true'); + equal(fn(new Foo()), 'true'); }); it('should return false if object does not have own property:', function() { var fn = hbs.compile('{{hasOwn this "c"}}'); - assert.equal(fn(new Foo()), 'false'); + equal(fn(new Foo()), 'false'); }); }); describe('isObject', function() { it('should return true if value is an object:', function() { var fn = hbs.compile('{{isObject this}}'); - assert.equal(fn({a: 'b'}), 'true'); + equal(fn({a: 'b'}), 'true'); }); it('should return false if value is not an object:', function() { var fn = hbs.compile('{{isObject this}}'); - assert.equal(fn('foo'), 'false'); + equal(fn('foo'), 'false'); }); }); @@ -157,42 +158,42 @@ describe('object', function() { it('should deeply merge objects passed on the context:', function() { var fn = hbs.compile('{{{stringify (merge a b c)}}}'); var actual = fn({a: {one: 'two'}, b: {one: 'three'}, c: {two: 'four'}}); - assert.equal(actual, '{"one":"three","two":"four"}'); + equal(actual, '{"one":"three","two":"four"}'); }); }); describe('JSONparse', function() { it('should parse a JSON string:', function() { var fn = hbs.compile('{{lookup (JSONparse string) "name"}}'); - assert.equal(fn({string: '{"name": "Fry"}'}), 'Fry'); + equal(fn({string: '{"name": "Fry"}'}), 'Fry'); }); }); describe('pick', function() { it('should pick a value from the context', function() { var one = hbs.compile('{{{stringify (pick "a" this)}}}')({a: 'b'}); - assert.equal(one, '{"a":"b"}'); + equal(one, '{"a":"b"}'); var two = hbs.compile('{{{stringify (pick "c" this)}}}')({c: 'd'}); - assert.equal(two, '{"c":"d"}'); + equal(two, '{"c":"d"}'); }); it('should pick a nested value from the context', function() { var fn = hbs.compile('{{{stringify (pick "a.b.c" this)}}}'); - assert.equal(fn({a: {b: {c: {d: 'e'}}}}), '{"c":{"d":"e"}}'); + equal(fn({a: {b: {c: {d: 'e'}}}}), '{"c":{"d":"e"}}'); }); it('should work as a block helper', function() { var fn1 = hbs.compile('{{#pick "a" this}} {{{stringify .}}} {{/pick}}'); - assert.equal(fn1(context.object), ' {"a":"b"} '); + equal(fn1(context.object), ' {"a":"b"} '); var fn2 = hbs.compile('{{#pick "c" this}} {{{stringify .}}} {{/pick}}'); - assert.equal(fn2(context.object), ' {"c":"d"} '); + equal(fn2(context.object), ' {"c":"d"} '); }); it('should pick the inverse block if not found', function() { var fn = hbs.compile('{{#pick "foo" this}} {{.}} {{else}}Nope.{{/pick}}'); - assert.equal(fn(context.object), 'Nope.'); + equal(fn(context.object), 'Nope.'); }); }); @@ -200,7 +201,7 @@ describe('object', function() { it('should stringify an object:', function() { var fn = hbs.compile('{{{stringify data}}}'); var res = fn({data: {name: 'Halle', age: 4, userid: 'Nicole'}}); - assert.equal(res, '{"name":"Halle","age":4,"userid":"Nicole"}'); + equal(res, '{"name":"Halle","age":4,"userid":"Nicole"}'); }); }); }); diff --git a/test/path.js b/test/path.js deleted file mode 100644 index e3d54b1c..00000000 --- a/test/path.js +++ /dev/null @@ -1,89 +0,0 @@ -'use strict'; - -require('mocha'); -var os = require('os'); -var assert = require('assert'); -var path = require('path'); -var hbs = require('handlebars').create(); -var gm = require('global-modules'); -var helpers = require('..'); -helpers.path({handlebars: hbs}); - -describe('assemble', function() { - describe('absolute', function() { - it('should create an absolute file path', function() { - assert.equal(hbs.compile('{{absolute "a/b/c/package.json"}}')(), path.resolve('a/b/c/package.json')); - assert.equal(hbs.compile('{{absolute "a/b/c/docs/toc.md"}}')(), path.resolve('a/b/c/docs/toc.md')); - }); - - it('should use the cwd on locals', function() { - assert.equal(hbs.compile('{{absolute "a/b/c/package.json"}}')({cwd: os.homedir()}), path.resolve(os.homedir(), 'a/b/c/package.json')); - assert.equal(hbs.compile('{{absolute "a/b/c/docs/toc.md"}}')({cwd: gm}), path.resolve(gm, 'a/b/c/docs/toc.md')); - }); - }); - - describe('dirname', function() { - it('should get the dirname of a file path', function() { - assert.equal(hbs.compile('{{dirname "a/b/c/package.json"}}')(), 'a/b/c'); - assert.equal(hbs.compile('{{dirname "a/b/c/docs/toc.md"}}')(), 'a/b/c/docs'); - }); - }); - - describe('relative', function() { - it('should return the relative path from file A to file B', function() { - var fn = hbs.compile('{{relative "dist/docs.html" "index.html"}}'); - assert.equal(fn(), path.join('..', 'index.html')); - }); - it('should return the relative path from file A to folder B', function() { - var fn = hbs.compile('{{relative "examples/result/md/path.md" "examples/assets"}}'); - assert.equal(fn(), path.join('..', '..', 'assets')); - }); - it('should use the cwd passed on options', function() { - var fn = hbs.compile('{{relative "examples/result/md/path.md" "examples/assets"}}'); - assert.equal(fn({cwd: gm}), path.join('..', '..', 'assets')); - }); - }); - - describe('basename', function() { - it('should get the basename of a file path', function() { - assert.equal(hbs.compile('{{basename "a/b/c/package.json"}}')(), 'package.json'); - assert.equal(hbs.compile('{{basename "a/b/c/docs/toc.md"}}')(), 'toc.md'); - }); - it('should get the basename when a path has no extension', function() { - var fn = hbs.compile('{{basename "a/b/c/CHANGELOG"}}'); - assert.equal(fn(), 'CHANGELOG'); - }); - }); - - describe('stem', function() { - it('should get the stem of a file path', function() { - assert.equal(hbs.compile('{{stem "a/b/c/package.json"}}')(), 'package'); - assert.equal(hbs.compile('{{stem "a/b/c/docs/toc.md"}}')(), 'toc'); - }); - it('should get the stem when a path has no extension', function() { - var fn = hbs.compile('{{stem "CHANGELOG"}}'); - assert.equal(fn(), 'CHANGELOG'); - }); - }); - - describe('extname', function() { - it('should get the extname of a file path', function() { - assert.equal(hbs.compile('{{extname "a/b/c/package.json"}}')(), '.json'); - assert.equal(hbs.compile('{{extname "a/b/c/docs/toc.md"}}')(), '.md'); - }); - it('should not blow up when a path has no extension', function() { - var fn = hbs.compile('{{extname "a/b/c/CHANGELOG"}}'); - assert.equal(fn(), ''); - }); - }); - - describe('segments', function() { - it('should return specified path segments:', function() { - assert.equal(hbs.compile('{{segments "a/b/c/e.js" 1 3}}')(), 'b/c'); - assert.equal(hbs.compile('{{segments "a/b/c/e.js" 1 2}}')(), 'b'); - assert.equal(hbs.compile('{{segments "a/b/c/e.js" 0 3}}')(), 'a/b/c'); - assert.equal(hbs.compile('{{segments "a/b/c/e.js" 2 3}}')(), 'c'); - assert.equal(hbs.compile('{{segments "a/b/c/e.js" 0 3}}')(), 'a/b/c'); - }); - }); -}); diff --git a/test/path.mjs b/test/path.mjs new file mode 100644 index 00000000..599afdb8 --- /dev/null +++ b/test/path.mjs @@ -0,0 +1,90 @@ +'use strict'; + +import 'mocha'; +import { homedir } from 'os'; +import { equal } from 'assert'; +import { resolve, join } from 'path'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import gm from 'global-modules'; +import { path as _path } from '../index.mjs'; +_path({handlebars: hbs}); + +describe('assemble', function() { + describe('absolute', function() { + it('should create an absolute file path', function() { + equal(hbs.compile('{{absolute "a/b/c/package.json"}}')(), resolve('a/b/c/package.json')); + equal(hbs.compile('{{absolute "a/b/c/docs/toc.md"}}')(), resolve('a/b/c/docs/toc.md')); + }); + + it('should use the cwd on locals', function() { + equal(hbs.compile('{{absolute "a/b/c/package.json"}}')({cwd: homedir()}), resolve(homedir(), 'a/b/c/package.json')); + equal(hbs.compile('{{absolute "a/b/c/docs/toc.md"}}')({cwd: gm}), resolve(gm, 'a/b/c/docs/toc.md')); + }); + }); + + describe('dirname', function() { + it('should get the dirname of a file path', function() { + equal(hbs.compile('{{dirname "a/b/c/package.json"}}')(), 'a/b/c'); + equal(hbs.compile('{{dirname "a/b/c/docs/toc.md"}}')(), 'a/b/c/docs'); + }); + }); + + describe('relative', function() { + it('should return the relative path from file A to file B', function() { + var fn = hbs.compile('{{relative "dist/docs.html" "index.html"}}'); + equal(fn(), join('..', 'index.html')); + }); + it('should return the relative path from file A to folder B', function() { + var fn = hbs.compile('{{relative "examples/result/md/path.md" "examples/assets"}}'); + equal(fn(), join('..', '..', 'assets')); + }); + it('should use the cwd passed on options', function() { + var fn = hbs.compile('{{relative "examples/result/md/path.md" "examples/assets"}}'); + equal(fn({cwd: gm}), join('..', '..', 'assets')); + }); + }); + + describe('basename', function() { + it('should get the basename of a file path', function() { + equal(hbs.compile('{{basename "a/b/c/package.json"}}')(), 'package.json'); + equal(hbs.compile('{{basename "a/b/c/docs/toc.md"}}')(), 'toc.md'); + }); + it('should get the basename when a path has no extension', function() { + var fn = hbs.compile('{{basename "a/b/c/CHANGELOG"}}'); + equal(fn(), 'CHANGELOG'); + }); + }); + + describe('stem', function() { + it('should get the stem of a file path', function() { + equal(hbs.compile('{{stem "a/b/c/package.json"}}')(), 'package'); + equal(hbs.compile('{{stem "a/b/c/docs/toc.md"}}')(), 'toc'); + }); + it('should get the stem when a path has no extension', function() { + var fn = hbs.compile('{{stem "CHANGELOG"}}'); + equal(fn(), 'CHANGELOG'); + }); + }); + + describe('extname', function() { + it('should get the extname of a file path', function() { + equal(hbs.compile('{{extname "a/b/c/package.json"}}')(), '.json'); + equal(hbs.compile('{{extname "a/b/c/docs/toc.md"}}')(), '.md'); + }); + it('should not blow up when a path has no extension', function() { + var fn = hbs.compile('{{extname "a/b/c/CHANGELOG"}}'); + equal(fn(), ''); + }); + }); + + describe('segments', function() { + it('should return specified path segments:', function() { + equal(hbs.compile('{{segments "a/b/c/e.js" 1 3}}')(), 'b/c'); + equal(hbs.compile('{{segments "a/b/c/e.js" 1 2}}')(), 'b'); + equal(hbs.compile('{{segments "a/b/c/e.js" 0 3}}')(), 'a/b/c'); + equal(hbs.compile('{{segments "a/b/c/e.js" 2 3}}')(), 'c'); + equal(hbs.compile('{{segments "a/b/c/e.js" 0 3}}')(), 'a/b/c'); + }); + }); +}); diff --git a/test/string.js b/test/string.mjs similarity index 74% rename from test/string.js rename to test/string.mjs index 493c366d..091a179c 100644 --- a/test/string.js +++ b/test/string.mjs @@ -1,400 +1,401 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.string({ handlebars: hbs }); +import 'mocha'; +import { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { string } from '../index.mjs'; +string({ handlebars: hbs }); describe('string', function() { describe('camelcase', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{camelcase}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in camelcase', function() { var fn = hbs.compile('{{camelcase "foo bar baz qux"}}'); - assert.equal(fn(), 'fooBarBazQux'); + equal(fn(), 'fooBarBazQux'); }); it('should lowercase a single character', function() { - assert.equal(hbs.compile('{{camelcase "f"}}')(), 'f'); - assert.equal(hbs.compile('{{camelcase "A"}}')(), 'a'); + equal(hbs.compile('{{camelcase "f"}}')(), 'f'); + equal(hbs.compile('{{camelcase "A"}}')(), 'a'); }); }); describe('capitalize', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{capitalize}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should capitalize a word.', function() { var fn = hbs.compile('{{capitalize "foo"}}'); - assert.equal(fn(), 'Foo'); + equal(fn(), 'Foo'); }); }); describe('capitalizeAll', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{capitalizeAll}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string with the every word capitalized.', function() { var fn = hbs.compile('{{capitalizeAll "bender should not bE allowed on tV"}}'); - assert.equal(fn(), 'Bender Should Not BE Allowed On TV'); + equal(fn(), 'Bender Should Not BE Allowed On TV'); }); }); describe('center', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{center}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string centered by using non-breaking spaces.', function() { var fn = hbs.compile('{{center "Bender should not be allowed on tv." 2}}'); - assert.equal(fn(), '&nbsp;&nbsp;Bender should not be allowed on tv.&nbsp;&nbsp;'); + equal(fn(), '&nbsp;&nbsp;Bender should not be allowed on tv.&nbsp;&nbsp;'); }); }); describe('chop', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{chop}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should remove non-word characters from start of string', function() { var fn = hbs.compile('{{chop "- foo bar baz"}}'); - assert.equal(fn(), 'foo bar baz'); + equal(fn(), 'foo bar baz'); }); it('should remove non-word characters from end of string', function() { var fn = hbs.compile('{{chop "foo bar baz _- "}}'); - assert.equal(fn(), 'foo bar baz'); + equal(fn(), 'foo bar baz'); }); }); describe('dashcase', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{dashcase}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in dashcase', function() { var fn = hbs.compile('{{dashcase "foo bar baz qux"}}'); - assert.equal(fn(), 'foo-bar-baz-qux'); + equal(fn(), 'foo-bar-baz-qux'); }); it('should lowercase a single character', function() { - assert.equal(hbs.compile('{{dashcase "f"}}')(), 'f'); - assert.equal(hbs.compile('{{dashcase "A"}}')(), 'a'); + equal(hbs.compile('{{dashcase "f"}}')(), 'f'); + equal(hbs.compile('{{dashcase "A"}}')(), 'a'); }); }); describe('dotcase', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{dotcase}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in dotcase', function() { var fn = hbs.compile('{{dotcase "foo bar baz qux"}}'); - assert.equal(fn(), 'foo.bar.baz.qux'); + equal(fn(), 'foo.bar.baz.qux'); }); it('should lowercase a single character', function() { - assert.equal(hbs.compile('{{dotcase "f"}}')(), 'f'); - assert.equal(hbs.compile('{{dotcase "A"}}')(), 'a'); + equal(hbs.compile('{{dotcase "f"}}')(), 'f'); + equal(hbs.compile('{{dotcase "A"}}')(), 'a'); }); }); describe('ellipsis', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{ellipsis}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return then string truncated by a specified length.', function() { var fn = hbs.compile('{{ellipsis "Bender should not be allowed on tv." 31}}'); - assert.equal(fn(), 'Bender should not be allowed on…'); + equal(fn(), 'Bender should not be allowed on…'); }); it('should return the string if shorter than the specified length.', function() { var fn = hbs.compile('{{ellipsis "Bender should not be allowed on tv." 100}}'); - assert.equal(fn(), 'Bender should not be allowed on tv.'); + equal(fn(), 'Bender should not be allowed on tv.'); }); }); describe('hyphenate', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{hyphenate}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string with spaces replaced with hyphens.', function() { var fn = hbs.compile('{{hyphenate "Bender should not be allowed on tv."}}'); - assert.equal(fn(), 'Bender-should-not-be-allowed-on-tv.'); + equal(fn(), 'Bender-should-not-be-allowed-on-tv.'); }); }); describe('isString', function() { it('should return true for string', function() { - assert.equal(hbs.compile('{{isString "foo"}}')(), 'true'); + equal(hbs.compile('{{isString "foo"}}')(), 'true'); }); it('should return true for empty string', function() { - assert.equal(hbs.compile('{{isString ""}}')(), 'true'); + equal(hbs.compile('{{isString ""}}')(), 'true'); }); it('should return false for number', function() { - assert.equal(hbs.compile('{{isString 123}}')(), 'false'); + equal(hbs.compile('{{isString 123}}')(), 'false'); }); it('should return false for null', function() { - assert.equal(hbs.compile('{{isString null}}')(), 'false'); + equal(hbs.compile('{{isString null}}')(), 'false'); }); it('should return false when undefined', function() { - assert.equal(hbs.compile('{{isString}}')(), 'false'); + equal(hbs.compile('{{isString}}')(), 'false'); }); }); describe('lowercase', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{lowercase}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in lowercase', function() { var fn = hbs.compile('{{lowercase "BENDER SHOULD NOT BE ALLOWED ON TV"}}'); - assert.equal(fn(), 'bender should not be allowed on tv'); + equal(fn(), 'bender should not be allowed on tv'); }); }); describe('occurrences', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{occurrences}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the number of occurrences of a string, within a string.', function() { var fn = hbs.compile('{{occurrences "Jar-Jar Binks" "Jar"}}'); - assert.equal(fn(), '2'); + equal(fn(), '2'); }); }); describe('pascalcase', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{pascalcase}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in pascalcase', function() { var fn = hbs.compile('{{pascalcase "foo bar baz qux"}}'); - assert.equal(fn(), 'FooBarBazQux'); + equal(fn(), 'FooBarBazQux'); }); it('should uppercase a single character', function() { - assert.equal(hbs.compile('{{pascalcase "f"}}')(), 'F'); - assert.equal(hbs.compile('{{pascalcase "A"}}')(), 'A'); + equal(hbs.compile('{{pascalcase "f"}}')(), 'F'); + equal(hbs.compile('{{pascalcase "A"}}')(), 'A'); }); }); describe('pathcase', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{pathcase}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in pathcase', function() { var fn = hbs.compile('{{pathcase "foo bar baz qux"}}'); - assert.equal(fn(), 'foo/bar/baz/qux'); + equal(fn(), 'foo/bar/baz/qux'); }); it('should lowercase a single character', function() { - assert.equal(hbs.compile('{{pathcase "f"}}')(), 'f'); - assert.equal(hbs.compile('{{pathcase "A"}}')(), 'a'); + equal(hbs.compile('{{pathcase "f"}}')(), 'f'); + equal(hbs.compile('{{pathcase "A"}}')(), 'a'); }); }); describe('plusify', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{plusify}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the empty string with no change.', function() { var fn = hbs.compile('{{plusify ""}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string with no change.', function() { var fn = hbs.compile('{{plusify "BenderShouldNotBeAllowedOnTv."}}'); - assert.equal(fn(), 'BenderShouldNotBeAllowedOnTv.'); + equal(fn(), 'BenderShouldNotBeAllowedOnTv.'); }); it('should return the string with spaces replaced with pluses.', function() { var fn = hbs.compile('{{plusify "Bender should not be allowed on tv."}}'); - assert.equal(fn(), 'Bender+should+not+be+allowed+on+tv.'); + equal(fn(), 'Bender+should+not+be+allowed+on+tv.'); }); }); describe('replace', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{replace}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should replace occurrences of string "A" with string "B"', function() { var fn = hbs.compile('{{replace "Bender Bending Rodriguez" "B" "M"}}'); - assert.equal(fn(), 'Mender Mending Rodriguez'); + equal(fn(), 'Mender Mending Rodriguez'); }); it('should return the string if `a` is undefined', function() { var fn = hbs.compile('{{replace "a b c"}}'); - assert.equal(fn(), 'a b c'); + equal(fn(), 'a b c'); }); it('should replace the string with `""` if `b` is undefined', function() { var fn = hbs.compile('{{replace "a b c" "a"}}'); - assert.equal(fn(), ' b c'); + equal(fn(), ' b c'); }); }); describe('reverse', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{reverse}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in reverse.', function() { var fn = hbs.compile('{{reverse "bender should NOT be allowed on TV."}}'); - assert.equal(fn(), '.VT no dewolla eb TON dluohs redneb'); + equal(fn(), '.VT no dewolla eb TON dluohs redneb'); }); }); describe('sentence', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{sentence}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should capitalize the first word of each sentence in a string and convert the rest of the sentence to lowercase.', function() { var fn = hbs.compile('{{sentence "bender should NOT be allowed on TV. fry SHOULD be allowed on TV."}}'); - assert.equal(fn(), 'Bender should not be allowed on tv. Fry should be allowed on tv.'); + equal(fn(), 'Bender should not be allowed on tv. Fry should be allowed on tv.'); }); }); describe('snakecase', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{snakecase}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should lowercase a single character', function() { - assert.equal(hbs.compile('{{snakecase "a"}}')(), 'a'); - assert.equal(hbs.compile('{{snakecase "A"}}')(), 'a'); + equal(hbs.compile('{{snakecase "a"}}')(), 'a'); + equal(hbs.compile('{{snakecase "A"}}')(), 'a'); }); it('should return the string in snakecase', function() { var fn = hbs.compile('{{snakecase "foo bar baz qux"}}'); - assert.equal(fn(), 'foo_bar_baz_qux'); + equal(fn(), 'foo_bar_baz_qux'); }); }); describe('split', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{split}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should split the string with the default character', function() { var fn = hbs.compile('{{#each (split "a,b,c")}}<{{.}}>{{/each}}'); - assert.equal(fn(), '
'); + equal(fn(), ''); }); it('should split the string on the given character', function() { var fn = hbs.compile('{{#each (split "a|b|c" "|")}}<{{.}}>{{/each}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); }); describe('startsWith', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{startsWith}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should render "Yes he is", from inside the block.', function() { var fn = hbs.compile('{{#startsWith "Bender" "Bender is great"}}Yes he is{{/startsWith}}'); - assert.equal(fn(), 'Yes he is'); + equal(fn(), 'Yes he is'); }); it('should render the Inverse block.', function() { var fn = hbs.compile('{{#startsWith "Goodbye" "Hello, world!"}}Whoops{{else}}Bro, do you even hello world?{{/startsWith}}'); - assert.equal(fn(), 'Bro, do you even hello world?'); + equal(fn(), 'Bro, do you even hello world?'); }); it('should render the Inverse block when an undefined value is passed in..', function() { var fn = hbs.compile('{{#startsWith "myPrefix" undefined}}fn block{{else}}inverse block{{/startsWith}}'); - assert.equal(fn(), 'inverse block'); + equal(fn(), 'inverse block'); }); }); describe('titleize', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{titleize}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in title case.', function() { var fn = hbs.compile('{{titleize "Bender-should-Not-be-allowed_on_Tv"}}'); - assert.equal(fn(), 'Bender Should Not Be Allowed On Tv'); + equal(fn(), 'Bender Should Not Be Allowed On Tv'); }); }); describe('trim', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{trim}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should trim leading whitespace', function() { var fn = hbs.compile('{{trim " foo"}}'); - assert.equal(fn(), 'foo'); + equal(fn(), 'foo'); }); it('should trim trailing whitespace', function() { var fn = hbs.compile('{{trim "foo "}}'); - assert.equal(fn(), 'foo'); + equal(fn(), 'foo'); }); }); describe('truncate', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{truncate}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string truncated by a specified length.', function() { var fn = hbs.compile('{{truncate "Bender should not be allowed on tv." 31}}'); - assert.equal(fn(), 'Bender should not be allowed on'); + equal(fn(), 'Bender should not be allowed on'); }); it('should return the string if shorter than the specified length.', function() { var fn = hbs.compile('{{truncate "Bender should not be allowed on tv." 100}}'); - assert.equal(fn(), 'Bender should not be allowed on tv.'); + equal(fn(), 'Bender should not be allowed on tv.'); }); it('should return then string truncated by a specified length', function() { var fn = hbs.compile('{{truncate "foo bar baz qux" 7}}...'); - assert.equal(fn(), 'foo bar...'); + equal(fn(), 'foo bar...'); }); it('should return then string truncated by a specified length, providing a custom string to denote an omission.', function() { var fn = hbs.compile('{{truncate "foo bar baz qux" 7 "…"}}'); - assert.equal(fn(), 'foo ba…'); + equal(fn(), 'foo ba…'); }); }); describe('truncateWords', function() { it('should return then string truncated when the specified length is shorter than the word count', function() { var fn = hbs.compile('{{truncateWords "foo bar baz" 2}}'); - assert.equal(fn(), 'foo bar…'); + equal(fn(), 'foo bar…'); }); it('should be able to truncate a single word', function() { var fn = hbs.compile('{{truncateWords "foo bar baz" 1}}'); - assert.equal(fn(), 'foo…'); + equal(fn(), 'foo…'); }); it('should return the original string when the specified length matches the word count', function() { var fn = hbs.compile('{{truncateWords "foo bar baz" 3}}'); - assert.equal(fn(), 'foo bar baz'); + equal(fn(), 'foo bar baz'); }); it('should return the original string when the specified length is bigger than the word count', function() { var fn = hbs.compile('{{truncateWords "foo bar baz" 4}}'); - assert.equal(fn(), 'foo bar baz'); + equal(fn(), 'foo bar baz'); }); }); describe('uppercase', function() { it('should return an empty string if undefined', function() { var fn = hbs.compile('{{uppercase}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the string in uppercase', function() { var fn = hbs.compile('{{uppercase "bender should not be allowed on tv"}}'); - assert.equal(fn(), 'BENDER SHOULD NOT BE ALLOWED ON TV'); + equal(fn(), 'BENDER SHOULD NOT BE ALLOWED ON TV'); }); it('should work as a block helper', function() { var fn = hbs.compile('{{#uppercase}}bender should not be allowed on tv{{/uppercase}}'); - assert.equal(fn(), 'BENDER SHOULD NOT BE ALLOWED ON TV'); + equal(fn(), 'BENDER SHOULD NOT BE ALLOWED ON TV'); }); }); @@ -402,44 +403,44 @@ describe('string', function() { // Bad parameters it('Should return "Lorem ipsum" only, if passed no parameters', function() { var fn = hbs.compile('{{ lorem }}'); - assert.equal(fn(), 'Lorem ipsum'); + equal(fn(), 'Lorem ipsum'); }); it('Should return "Lorem ipsum" only, if passed a non-number (string)', function() { var fn = hbs.compile('{{ lorem a }}'); - assert.equal(fn(), 'Lorem ipsum'); + equal(fn(), 'Lorem ipsum'); }); it('Should return "Lorem ipsum" only, if passed a non-number (array)', function() { var fn = hbs.compile('{{ lorem [1,2,3] }}'); - assert.equal(fn(), 'Lorem ipsum'); + equal(fn(), 'Lorem ipsum'); }); it('Should return "Lorem ipsum" only, if passed a number less than 1', function() { var fn = hbs.compile('{{ lorem -1 }}'); - assert.equal(fn(), 'Lorem ipsum'); + equal(fn(), 'Lorem ipsum'); }); it('Should return "Lorem ipsum" only, if passed a number less than 1', function() { var fn = hbs.compile('{{ lorem 0 }}'); - assert.equal(fn(), 'Lorem ipsum'); + equal(fn(), 'Lorem ipsum'); }); it('Should return "Lorem ipsum" only, if passed a number less than 1', function() { var fn = hbs.compile('{{ lorem -999 }}'); - assert.equal(fn(), 'Lorem ipsum'); + equal(fn(), 'Lorem ipsum'); }); // Good parameters it('Should return a string of "Lorem ipsum" if passed 11', function() { var fn = hbs.compile('{{ lorem 11 }}'); - assert.equal(fn(), 'Lorem ipsum'); + equal(fn(), 'Lorem ipsum'); }); it('Should return a string of "Lorem" if passed 5', function() { var fn = hbs.compile('{{ lorem 5 }}'); - assert.equal(fn(), 'Lorem'); + equal(fn(), 'Lorem'); }); it('Should return a string of "Lorem ipsum dolor sit amet, consectetur adipiscing" if passed 50', function() { var fn = hbs.compile('{{ lorem 50 }}'); - assert.equal(fn(), 'Lorem ipsum dolor sit amet, consectetur adipiscing'); + equal(fn(), 'Lorem ipsum dolor sit amet, consectetur adipiscing'); }); it('Should return a string of length 8032 if passed 8032', function() { var fn = hbs.compile('{{ lorem 8032 }}'); - assert.equal(fn().length, 8032); + equal(fn().length, 8032); }); }); }); diff --git a/test/support/index.js b/test/support/index.js index 6d83709d..2d1a3447 100644 --- a/test/support/index.js +++ b/test/support/index.js @@ -2,12 +2,6 @@ var fs = require('fs'); -/** - * Expose `utils` - */ - -var utils = module.exports; - /** * Read a file at the given `filepath` * @@ -15,7 +9,7 @@ var utils = module.exports; * @return {String} */ -utils.read = function(fp) { +module.exports.read = function(fp) { return fs.readFileSync(fp, 'utf8'); }; @@ -28,9 +22,9 @@ utils.read = function(fp) { * @return {String} */ -utils.fixture = function(type) { +module.exports.fixture = function(type) { return function(fp) { - return utils.read('test/fixtures/' + type + '/' + fp); + return module.exports.read('test/fixtures/' + type + '/' + fp); }; }; @@ -43,8 +37,8 @@ utils.fixture = function(type) { * @return {String} */ -utils.expected = function(type) { +module.exports.expected = function(type) { return function(fp) { - return utils.read('test/expected/' + type + '/' + fp); + return module.exports.read('test/expected/' + type + '/' + fp); }; }; From 30d327168c484171ed29645f2b4215fc47604f93 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 12:24:14 +0100 Subject: [PATCH 05/46] Migrate more tests --- test/{math.js => math.mjs} | 41 ++++++++++----------- test/{misc.js => misc.mjs} | 35 +++++++++--------- test/{number.js => number.mjs} | 65 +++++++++++++++++----------------- 3 files changed, 72 insertions(+), 69 deletions(-) rename test/{math.js => math.mjs} (76%) rename test/{misc.js => misc.mjs} (68%) rename test/{number.js => number.mjs} (57%) diff --git a/test/math.js b/test/math.mjs similarity index 76% rename from test/math.js rename to test/math.mjs index f06d82ed..a841e14a 100644 --- a/test/math.js +++ b/test/math.mjs @@ -1,101 +1,102 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.math({handlebars: hbs}); +import 'mocha'; +import assert, { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { math } from '../index.mjs'; +math({handlebars: hbs}); describe('math', function() { describe('add', function() { it('should return the sum of two numbers.', function() { var fn = hbs.compile('{{add value 5}}'); - assert.equal(fn({value: 5}), '10'); + equal(fn({value: 5}), '10'); }); }); describe('average', function() { it('should return the average of a list of numbers:', function() { var fn = hbs.compile('{{avg 1 2 3 4}}'); - assert.equal(fn(), '2.5'); + equal(fn(), '2.5'); }); it('should return the average of an array of numbers:', function() { var fn = hbs.compile('{{avg array}}'); - assert.equal(fn({array: [1, 3, 6, 9]}), '4.75'); + equal(fn({array: [1, 3, 6, 9]}), '4.75'); }); }); describe('ceil', function() { it('should return the value rounded up to the nearest integer.', function() { var fn = hbs.compile('{{ceil value}}'); - assert.equal(fn({value: 5.6}), '6'); + equal(fn({value: 5.6}), '6'); }); }); describe('divide', function() { it('should return the division of two numbers.', function() { var fn = hbs.compile('{{divide value 5}}'); - assert.equal(fn({value: 5}), '1'); + equal(fn({value: 5}), '1'); }); }); describe('floor', function() { it('should return the value rounded down to the nearest integer.', function() { var fn = hbs.compile('{{floor value}}'); - assert.equal(fn({value: 5.6}), '5'); + equal(fn({value: 5.6}), '5'); }); }); describe('multiply', function() { it('should return the multiplication of two numbers.', function() { var fn = hbs.compile('{{multiply value 5}}'); - assert.equal(fn({value: 5}), '25'); + equal(fn({value: 5}), '25'); }); }); describe('remainder', function() { it('should return the remainder of two numbers.', function() { var fn = hbs.compile('{{remainder value 5}}'); - assert.equal(fn({value: 7}), '2'); + equal(fn({value: 7}), '2'); }); it('should take the sign of the dividend.', function() { var fn = hbs.compile('{{remainder 5 -3}}'); - assert.equal(fn(), '2'); + equal(fn(), '2'); }); }); describe('round', function() { it('should return the value rounded to the nearest integer.', function() { var fn = hbs.compile('{{round value}}'); - assert.equal(fn({value: 5.69}), '6'); + equal(fn({value: 5.69}), '6'); }); }); describe('subtract', function() { it('should return the difference of two numbers.', function() { var fn = hbs.compile('{{subtract value 5}}'); - assert.equal(fn({value: 5}), '0'); + equal(fn({value: 5}), '0'); }); }); describe('sum', function() { it('should return the sum of multiple numbers.', function() { var fn = hbs.compile('{{sum value 67 80}}'); - assert.equal(fn({value: 20}), '167'); + equal(fn({value: 20}), '167'); }); it('should return the sum of multiple numbers.', function() { var fn = hbs.compile('{{sum 1 2 3}}'); - assert.equal(fn(), '6'); + equal(fn(), '6'); }); it('should return the total sum of array.', function() { var fn = hbs.compile('{{sum value}}'); - assert.equal(fn({value: [1, 2, 3]}), '6'); + equal(fn({value: [1, 2, 3]}), '6'); }); it('should return the total sum of array and numbers.', function() { var fn = hbs.compile('{{sum value 5}}'); - assert.equal(fn({value: [1, 2, 3]}), '11'); + equal(fn({value: [1, 2, 3]}), '11'); }); }); diff --git a/test/misc.js b/test/misc.mjs similarity index 68% rename from test/misc.js rename to test/misc.mjs index 210a6947..e6ea11e4 100644 --- a/test/misc.js +++ b/test/misc.mjs @@ -1,37 +1,38 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); +import 'mocha'; +import { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { misc } from '../index.mjs'; describe('misc', function() { beforeEach(function() { - helpers.misc({handlebars: hbs}); + misc({handlebars: hbs}); }); describe('noop', function() { it('should be a noop', function() { var fn = hbs.compile('{{#noop}}{{message}}{{/noop}}'); - assert.equal(fn({message: 'This is a test'}), 'This is a test'); + equal(fn({message: 'This is a test'}), 'This is a test'); }); }); describe('option', function() { it('should get an option', function() { var fn = hbs.compile('{{option "a"}}'); - assert.equal(fn({options: {a: 'bbb'}}), 'bbb'); + equal(fn({options: {a: 'bbb'}}), 'bbb'); }); it('should return an empty string when no options are found', function() { - assert.equal(hbs.compile('{{option "a"}}')(), ''); + equal(hbs.compile('{{option "a"}}')(), ''); }); it('should get a nested option', function() { var fn = hbs.compile('{{option "a.b.c"}}'); - assert.equal(fn({options: {a: {b: {c: 'ddd'}}}}), 'ddd'); + equal(fn({options: {a: {b: {c: 'ddd'}}}}), 'ddd'); }); it('should work as a subexpression', function() { var fn = hbs.compile('{{option "a.b.c"}}'); - assert.equal(fn({options: {a: {b: {c: 'ddd'}}}}), 'ddd'); + equal(fn({options: {a: {b: {c: 'ddd'}}}}), 'ddd'); }); }); @@ -39,28 +40,28 @@ describe('misc', function() { it('should return an empty sting', function() { var fn = hbs.compile('{{#withHash}}{{message}}{{/withHash}}'); var actual = fn({message: 'This is a test'}); - assert.equal(typeof actual, 'string'); - assert.equal(actual, ''); + equal(typeof actual, 'string'); + equal(actual, ''); }); it('should not blow up when no hash is defined.', function() { var fn = hbs.compile('{{#withHash}}{{/withHash}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should return the inverse hash when defined and the value is falsy.', function() { var fn = hbs.compile('{{#withHash}}foo{{else}}bar{{/withHash}}'); - assert.equal(fn(), 'bar'); + equal(fn(), 'bar'); }); it('should return string from the newly created context', function() { var fn = hbs.compile('{{#withHash message="test"}}{{message}}{{/withHash}}'); - assert.equal(fn({message: 'This is a test'}), 'test'); + equal(fn({message: 'This is a test'}), 'test'); }); it('should return string from the parent context', function() { var fn = hbs.compile('{{#withHash message=this.message}}{{message}}{{/withHash}}'); - assert.equal(fn({message: 'This is a test'}), 'This is a test'); + equal(fn({message: 'This is a test'}), 'This is a test'); }); it('should add two attributes to the new context', function() { var fn = hbs.compile('{{#withHash subject="Feedback" message="Hello!"}}{{subject}} - {{message}}{{/withHash}}'); - assert.equal(fn({}), 'Feedback - Hello!'); + equal(fn({}), 'Feedback - Hello!'); }); }); }); diff --git a/test/number.js b/test/number.mjs similarity index 57% rename from test/number.js rename to test/number.mjs index ab1031fc..8c663a01 100644 --- a/test/number.js +++ b/test/number.mjs @@ -1,115 +1,116 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.number({handlebars: hbs}); +import 'mocha'; +import { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { number as _number } from '../index.mjs'; +_number({handlebars: hbs}); describe('number', function() { describe('bytes', function() { it('should format a number', function() { - assert.equal(hbs.compile('{{bytes num}}')({num: 13661855}), '13.66 MB'); - assert.equal(hbs.compile('{{bytes num}}')({num: 825399}), '825.4 kB'); - assert.equal(hbs.compile('{{bytes num}}')({num: 1396}), '1.4 kB'); - assert.equal(hbs.compile('{{bytes num}}')({num: 0}), '0 B'); - assert.equal(hbs.compile('{{bytes num}}')({num: 1}), '1 B'); - assert.equal(hbs.compile('{{bytes num}}')({num: 2}), '2 B'); + equal(hbs.compile('{{bytes num}}')({num: 13661855}), '13.66 MB'); + equal(hbs.compile('{{bytes num}}')({num: 825399}), '825.4 kB'); + equal(hbs.compile('{{bytes num}}')({num: 1396}), '1.4 kB'); + equal(hbs.compile('{{bytes num}}')({num: 0}), '0 B'); + equal(hbs.compile('{{bytes num}}')({num: 1}), '1 B'); + equal(hbs.compile('{{bytes num}}')({num: 2}), '2 B'); }); it('should return "0 B" when an invalid value is passed', function() { - assert.equal(hbs.compile('{{bytes num}}')({num: {}}), '0 B'); + equal(hbs.compile('{{bytes num}}')({num: {}}), '0 B'); }); it('should return string length when a string is passed', function() { - assert.equal(hbs.compile('{{bytes num}}')({num: 'foo'}), '3 B'); - assert.equal(hbs.compile('{{bytes num}}')({num: 'foobar'}), '6 B'); + equal(hbs.compile('{{bytes num}}')({num: 'foo'}), '3 B'); + equal(hbs.compile('{{bytes num}}')({num: 'foobar'}), '6 B'); }); }); describe('phoneNumber', function() { it('Format a phone number.', function() { var fn = hbs.compile('{{phoneNumber value}}'); - assert.equal(fn({value: '8005551212'}), '(800) 555-1212'); + equal(fn({value: '8005551212'}), '(800) 555-1212'); }); }); describe('toFixed', function() { it('should return the value rounded to the nearest integer.', function() { var fn = hbs.compile('{{toFixed value}}'); - assert.equal(fn({value: 5.53231 }), '6'); + equal(fn({value: 5.53231 }), '6'); }); it('should return the value rounded exactly n digits after the decimal place.', function() { var fn = hbs.compile('{{toFixed value 3}}'); - assert.equal(fn({value: 5.53231 }), '5.532'); + equal(fn({value: 5.53231 }), '5.532'); }); }); describe('toPrecision', function() { it('Returns the number in fixed-point or exponential notation rounded to n significant digits.', function() { var fn = hbs.compile('{{toPrecision value}}'); - assert.equal(fn({value: 555.322 }), '6e+2'); + equal(fn({value: 555.322 }), '6e+2'); }); it('should return the value rounded exactly n digits after the decimal place.', function() { var fn = hbs.compile('{{toPrecision value 4}}'); - assert.equal(fn({value: 555.322 }), '555.3'); + equal(fn({value: 555.322 }), '555.3'); }); }); describe('toExponential', function() { it('should return the number in fixed-point or exponential notation rounded to n significant digits.', function() { var fn = hbs.compile('{{toExponential value}}'); - assert.equal(fn({value: 5 }), '5e+0'); + equal(fn({value: 5 }), '5e+0'); }); it('should return the number in fixed-point or exponential notation rounded to exactly n significant digits.', function() { var fn = hbs.compile('{{toExponential value 5}}'); - assert.equal(fn({value: 5 }), '5.00000e+0'); + equal(fn({value: 5 }), '5.00000e+0'); }); }); describe('toInt', function() { it('should return an integer.', function() { var fn = hbs.compile('{{toInt value}}'); - assert.equal(fn({value: '3cc'}), '3'); + equal(fn({value: '3cc'}), '3'); }); }); describe('toFloat', function() { it('should return a floating point number.', function() { var fn = hbs.compile('{{toFloat value}}'); - assert.equal(fn({value: '3.1cc'}), '3.1'); + equal(fn({value: '3.1cc'}), '3.1'); }); }); describe('addCommas', function() { it('should add commas to a number.', function() { var fn = hbs.compile('{{addCommas value}}'); - assert.equal(fn({value: 2222222 }), '2,222,222'); + equal(fn({value: 2222222 }), '2,222,222'); }); }); describe('toAbbr', function() { it('should abbreviate the given number.', function() { var fn = hbs.compile('{{toAbbr number}}'); - assert.equal(fn({number: 123456789 }), '123.46m'); + equal(fn({number: 123456789 }), '123.46m'); }); it('should abbreviate a number with to the given decimal.', function() { var fn = hbs.compile('{{toAbbr number 3}}'); - assert.equal(fn({number: 123456789 }), '123.457m'); + equal(fn({number: 123456789 }), '123.457m'); }); it('should round up to the next increment', function() { var fn = hbs.compile('{{toAbbr number}}'); - assert.equal(fn({number: 999 }), '1k'); + equal(fn({number: 999 }), '1k'); }); it('should abbreviate a number based on a number and include decimal.', function() { - assert.equal(hbs.compile('{{toAbbr number 0}}')({number: 9999999 }), '10m'); - assert.equal(hbs.compile('{{toAbbr number}}')({number: 1000000000 }), '1b'); - assert.equal(hbs.compile('{{toAbbr number}}')({number: 1000000000000 }), '1t'); - assert.equal(hbs.compile('{{toAbbr number}}')({number: 1000000000000000 }), '1q'); - assert.equal(hbs.compile('{{toAbbr number}}')({number: 99393999393 }), '99.39b'); + equal(hbs.compile('{{toAbbr number 0}}')({number: 9999999 }), '10m'); + equal(hbs.compile('{{toAbbr number}}')({number: 1000000000 }), '1b'); + equal(hbs.compile('{{toAbbr number}}')({number: 1000000000000 }), '1t'); + equal(hbs.compile('{{toAbbr number}}')({number: 1000000000000000 }), '1q'); + equal(hbs.compile('{{toAbbr number}}')({number: 99393999393 }), '99.39b'); }); }); }); From eb075d2c749959202cdd86023f3e412472801eaf Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 12:27:13 +0100 Subject: [PATCH 06/46] Migrate more tests --- test/{code.js => code.mjs} | 25 +-- test/{collection.js => collection.mjs} | 57 +++--- test/{comparison.js => comparison.mjs} | 177 +++++++++--------- test/{html.js => html.mjs} | 65 +++---- test/{i18n.js => i18n.mjs} | 27 +-- test/inflection.js | 32 ---- test/inflection.mjs | 33 ++++ test/match.mjs | 6 +- test/object.mjs | 2 +- .../{subexpressions.js => subexpressions.mjs} | 17 +- test/support/{index.js => index.mjs} | 20 +- test/{url.js => url.mjs} | 35 ++-- 12 files changed, 252 insertions(+), 244 deletions(-) rename test/{code.js => code.mjs} (70%) rename test/{collection.js => collection.mjs} (75%) rename test/{comparison.js => comparison.mjs} (81%) rename test/{html.js => html.mjs} (81%) rename test/{i18n.js => i18n.mjs} (77%) delete mode 100644 test/inflection.js create mode 100644 test/inflection.mjs rename test/{subexpressions.js => subexpressions.mjs} (66%) rename test/support/{index.js => index.mjs} (61%) rename test/{url.js => url.mjs} (67%) diff --git a/test/code.js b/test/code.mjs similarity index 70% rename from test/code.js rename to test/code.mjs index e32bfbee..2f5a9920 100644 --- a/test/code.js +++ b/test/code.mjs @@ -1,15 +1,16 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.code({handlebars: hbs}); +import 'mocha'; +import { equal, throws } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { code } from '../index.mjs'; +code({handlebars: hbs}); describe('code', function() { describe('embed', function() { it('should embed markdown:', function() { - assert.equal(hbs.compile('{{{embed "test/fixtures/simple.md"}}}')(), [ + equal(hbs.compile('{{{embed "test/fixtures/simple.md"}}}')(), [ '```markdown', '## Some Markdown\n', ' - one', @@ -21,7 +22,7 @@ describe('code', function() { }); it('should determine the language from the file extension', function() { - assert.equal(hbs.compile('{{{embed "test/fixtures/embedded.md"}}}')(), [ + equal(hbs.compile('{{{embed "test/fixtures/embedded.md"}}}')(), [ '```markdown', '## Markdown', '', @@ -41,7 +42,7 @@ describe('code', function() { it('should use the language defined in the last argument', function() { var template = hbs.compile('{{{embed "test/fixtures/index.html" "hbs"}}}'); - assert.equal(template(), [ + equal(template(), [ '```hbs', '', ' ', @@ -62,7 +63,7 @@ describe('code', function() { describe('gist', function() { it('should return a gist script tag', function() { var fn = hbs.compile('{{{gist "abcdefg"}}}'); - assert.equal(fn(), ''); + equal(fn(), ''); }); }); @@ -70,11 +71,11 @@ describe('code', function() { it('should return a jsfiddle embed link, with default tabs assigned', function() { var source = '{{{jsfiddle id="UXbas"}}}'; var fn = hbs.compile(source); - assert.equal(fn(), ''); + equal(fn(), ''); }); it('should throw an error if id is missing', function() { - assert.throws(function() { + throws(function() { hbs.compile('{{jsfiddle}}')(); }); }); @@ -82,7 +83,7 @@ describe('code', function() { it('should return a jsfiddle embed link, with custom tabs assigned', function() { var source = '{{{jsfiddle id="UXbas" tabs="html,css"}}}'; var fn = hbs.compile(source); - assert.equal(fn(), ''); + equal(fn(), ''); }); }); }); diff --git a/test/collection.js b/test/collection.mjs similarity index 75% rename from test/collection.js rename to test/collection.mjs index ca3f8355..f9aba8d6 100644 --- a/test/collection.js +++ b/test/collection.mjs @@ -1,12 +1,13 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.array({handlebars: hbs}); -helpers.collection({handlebars: hbs}); -helpers.string({handlebars: hbs}); +import 'mocha'; +import { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { array as _array, collection, string } from '../index.mjs'; +_array({handlebars: hbs}); +collection({handlebars: hbs}); +string({handlebars: hbs}); var context = {array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']}; @@ -14,54 +15,54 @@ describe('collection', function() { describe('isEmpty block helper', function() { it('should render the first block when an array is empty', function() { var fn = hbs.compile('{{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}'); - assert.equal(fn({array: []}), 'AAA'); + equal(fn({array: []}), 'AAA'); }); it('should render the first block when the value is null', function() { var fn = hbs.compile('{{#isEmpty}}AAA{{else}}BBB{{/isEmpty}}'); - assert.equal(fn({array: []}), 'AAA'); + equal(fn({array: []}), 'AAA'); }); it('should render the second block when an array is not empty', function() { var fn = hbs.compile('{{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}'); - assert.equal(fn(context), 'BBB'); + equal(fn(context), 'BBB'); }); it('should render the second block when an object is not empty', function() { var fn = hbs.compile('{{#isEmpty object}}AAA{{else}}BBB{{/isEmpty}}'); - assert.equal(fn({object: {foo: 'bar'}}), 'BBB'); + equal(fn({object: {foo: 'bar'}}), 'BBB'); }); it('should render the first block when an object is empty', function() { var fn = hbs.compile('{{#isEmpty object}}AAA{{else}}BBB{{/isEmpty}}'); - assert.equal(fn({object: {}}), 'AAA'); + equal(fn({object: {}}), 'AAA'); }); }); describe('isEmpty inline helper', function() { it('should render the first block when an array is empty', function() { var fn = hbs.compile('{{isEmpty array}}'); - assert.equal(fn({array: []}), 'true'); + equal(fn({array: []}), 'true'); }); it('should render the first block when the value is null', function() { var fn = hbs.compile('{{isEmpty}}'); - assert.equal(fn({array: []}), 'true'); + equal(fn({array: []}), 'true'); }); it('should render the second block when an array is not empty', function() { var fn = hbs.compile('{{isEmpty array}}'); - assert.equal(fn(context), 'false'); + equal(fn(context), 'false'); }); it('should render the second block when an object is not empty', function() { var fn = hbs.compile('{{isEmpty object}}'); - assert.equal(fn({object: {foo: 'bar'}}), 'false'); + equal(fn({object: {foo: 'bar'}}), 'false'); }); it('should render the first block when an object is empty', function() { var fn = hbs.compile('{{isEmpty object}}'); - assert.equal(fn({object: {}}), 'true'); + equal(fn({object: {}}), 'true'); }); }); @@ -71,19 +72,19 @@ describe('collection', function() { var obj = {a: 'aaa', b: 'bbb', c: 'ccc'}; var fn = hbs.compile('{{#iterate obj}}{{.}}{{/iterate}}'); - assert.equal(fn({obj: obj}), 'aaabbbccc'); + equal(fn({obj: obj}), 'aaabbbccc'); }); it('should expose `@key`:', function() { var obj = {a: 'aaa', b: 'bbb', c: 'ccc'}; var fn = hbs.compile('{{#iterate obj}}{{@key}}{{/iterate}}'); - assert.equal(fn({obj: obj}), 'abc'); + equal(fn({obj: obj}), 'abc'); }); it('should render the inverse block when falsey:', function() { var fn = hbs.compile('{{#iterate obj}}A{{else}}B{{/iterate}}'); - assert.equal(fn(), 'B'); + equal(fn(), 'B'); }); }); @@ -92,14 +93,14 @@ describe('collection', function() { var arr = [{name: 'a'}, {name: 'b'}, {name: 'c'}]; var fn = hbs.compile('{{#iterate arr}}{{name}}{{/iterate}}'); - assert.equal(fn({arr: arr}), 'abc'); + equal(fn({arr: arr}), 'abc'); }); it('should expose `@index`:', function() { var arr = [{name: 'a'}, {name: 'b'}, {name: 'c'}]; var fn = hbs.compile('{{#iterate arr}}{{@index}}{{/iterate}}'); - assert.equal(fn({arr: arr}), '012'); + equal(fn({arr: arr}), '012'); }); }); }); @@ -107,31 +108,31 @@ describe('collection', function() { describe('length', function() { it('should return the length of the array', function() { var fn = hbs.compile('{{length array}}'); - assert.equal(fn(context), '8'); + equal(fn(context), '8'); }); it('should return zero when undefined', function() { - assert.equal(hbs.compile('{{length}}')(), '0'); + equal(hbs.compile('{{length}}')(), '0'); }); it('should return the length of a string', function() { var fn = hbs.compile('{{length "foo"}}'); - assert.equal(fn(context), '3'); + equal(fn(context), '3'); }); it('should work with arrays passed via subexpression', function() { var fn = hbs.compile('{{length (split "b,c,a")}}'); - assert.equal(fn(context), '3'); + equal(fn(context), '3'); }); it('should return 0 when the array is invalid:', function() { var fn = hbs.compile('{{length foo}}'); - assert.equal(fn(context), '0'); + equal(fn(context), '0'); }); it('should return 0 when the value is not an array:', function() { var fn = hbs.compile('{{length foo}}'); - assert.equal(fn({foo: {}}), '0'); + equal(fn({foo: {}}), '0'); }); }); }); diff --git a/test/comparison.js b/test/comparison.mjs similarity index 81% rename from test/comparison.js rename to test/comparison.mjs index a9d62b45..6d0193d6 100644 --- a/test/comparison.js +++ b/test/comparison.mjs @@ -1,39 +1,40 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.comparison({handlebars: hbs}); +import 'mocha'; +import assert, { equal, throws } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { comparison } from '../index.mjs'; +comparison({handlebars: hbs}); describe('comparison', function() { describe('and', function() { describe('block', function() { it('should render a block if both values are truthy.', function() { var fn = hbs.compile('{{#and great magnificent}}A{{else}}B{{/and}}'); - assert.equal(fn({great: true, magnificent: true}), 'A'); + equal(fn({great: true, magnificent: true}), 'A'); }); it('should render the inverse block if both values are not truthy.', function() { var fn = hbs.compile('{{#and great magnificent}}A{{else}}B{{/and}}'); - assert.equal(fn({great: true, magnificent: false}), 'B'); + equal(fn({great: true, magnificent: false}), 'B'); }); }); describe('inline or subexpression', function() { it('should render a block if both values are truthy.', function() { var fn = hbs.compile('{{and great magnificent}}'); - assert.equal(fn({great: true, magnificent: true}), 'true'); + equal(fn({great: true, magnificent: true}), 'true'); }); it('should render the inverse block if both values are not truthy.', function() { var fn = hbs.compile('{{and great magnificent}}'); - assert.equal(fn({great: true, magnificent: false}), 'false'); + equal(fn({great: true, magnificent: false}), 'false'); }); it('should work as subexpressions', function() { var fn = hbs.compile('{{and (and a b) (and great magnificent)}}'); - assert.equal(fn({great: true, magnificent: false}), 'false'); + equal(fn({great: true, magnificent: false}), 'false'); }); }); }); @@ -41,16 +42,16 @@ describe('comparison', function() { describe('compare', function() { describe('errors', function() { it('should throw an error when args are invalid', function() { - assert.throws(function() { + throws(function() { hbs.compile('{{#compare}}{{/compare}}')(); }, /expects 4 arguments/); - assert.throws(function() { + throws(function() { hbs.compile('{{#compare a b}}{{/compare}}')(); }, /expects 4 arguments/); }); it('should throw an error when the operator is invalid', function() { - assert.throws(function() { + throws(function() { hbs.compile('{{#compare a "~" b}}{{/compare}}')(); }); }); @@ -167,47 +168,47 @@ describe('comparison', function() { describe('contains', function() { it('should render a block if the condition is true.', function() { var fn = hbs.compile('{{#contains context "C"}}A{{else}}B{{/contains}}'); - assert.equal(fn({context: 'CCC'}), 'A'); + equal(fn({context: 'CCC'}), 'A'); }); it('should render the inverse block if false.', function() { var fn = hbs.compile('{{#contains context "zzz"}}A{{else}}B{{/contains}}'); - assert.equal(fn({context: 'CCC'}), 'B'); + equal(fn({context: 'CCC'}), 'B'); }); it('should work with arrays', function() { var fn = hbs.compile('{{#contains array "a"}}A{{else}}B{{/contains}}'); - assert.equal(fn({array: ['a', 'b', 'c']}), 'A'); + equal(fn({array: ['a', 'b', 'c']}), 'A'); }); it('should render the block when an index is passed:', function() { var fn = hbs.compile('{{#contains array "a" 0}}A{{else}}B{{/contains}}'); - assert.equal(fn({array: ['a', 'b', 'c']}), 'A'); + equal(fn({array: ['a', 'b', 'c']}), 'A'); }); it('should render the inverse block when false with index:', function() { var fn = hbs.compile('{{#contains array "a" 1}}A{{else}}B{{/contains}}'); - assert.equal(fn({array: ['a', 'b', 'c']}), 'B'); + equal(fn({array: ['a', 'b', 'c']}), 'B'); }); it('should not render the block when an undefined argument is passed:', function() { var fn = hbs.compile('{{#contains array nothing}}A{{/contains}}'); - assert.equal(fn({array: ['a', 'b', 'c']}), ''); + equal(fn({array: ['a', 'b', 'c']}), ''); }); it('should render the inverse block when an undefined argument is passed:', function() { var fn = hbs.compile('{{#contains array nothing}}A{{else}}B{{/contains}}'); - assert.equal(fn({array: ['a', 'b', 'c']}), 'B'); + equal(fn({array: ['a', 'b', 'c']}), 'B'); }); }); describe('default', function() { it('should use the given value:', function() { - assert.equal(hbs.compile('{{default title "A"}}')({title: 'B'}), 'B'); + equal(hbs.compile('{{default title "A"}}')({title: 'B'}), 'B'); }); it('should fallback to the default value when no value exists', function() { - assert.equal(hbs.compile('{{default title "A"}}')({title: null}), 'A'); - assert.equal(hbs.compile('{{default title "A"}}')(), 'A'); + equal(hbs.compile('{{default title "A"}}')({title: null}), 'A'); + equal(hbs.compile('{{default title "A"}}')(), 'A'); }); }); @@ -229,15 +230,15 @@ describe('comparison', function() { describe('compare hash', function() { it('should not render a block if the value is not equal to a given number.', function() { var fn = hbs.compile('{{#gt number compare=8}}A{{/gt}}'); - assert.equal(fn({number: 5}), ''); + equal(fn({number: 5}), ''); }); it('should render a block if the value is greater than a given number.', function() { var fn = hbs.compile('{{#gt number compare=8}}A{{/gt}}'); - assert.equal(fn({number: 10}), 'A'); + equal(fn({number: 10}), 'A'); }); it('should not render a block if the value is less than a given number.', function() { var fn = hbs.compile('{{#gt number compare=8}}A{{/gt}}'); - assert.equal(fn({number: 5}), ''); + equal(fn({number: 5}), ''); }); }); }); @@ -247,28 +248,28 @@ describe('comparison', function() { var fn = hbs.compile('{{#gte a b}}A{{else}}B{{/gte}}'); it('should render the first block if true.', function() { - assert.equal(fn({a: 20, b: 15}), 'A'); + equal(fn({a: 20, b: 15}), 'A'); }); it('should render the first block if equal.', function() { - assert.equal(fn({a: 15, b: 15}), 'A'); + equal(fn({a: 15, b: 15}), 'A'); }); it('should render the second block if false.', function() { - assert.equal(fn({a: 14, b: 15}), 'B'); + equal(fn({a: 14, b: 15}), 'B'); }); }); describe('hash compare', function() { it('should render a block if the value is greater than a given number.', function() { var fn = hbs.compile('{{#gte number compare=8}}A{{/gte}}'); - assert.equal(fn({number: 12}), 'A'); + equal(fn({number: 12}), 'A'); }); it('should render a block if the value is equal to a given number.', function() { var fn = hbs.compile('{{#gte number compare=8}}A{{/gte}}'); - assert.equal(fn({number: 8}), 'A'); + equal(fn({number: 8}), 'A'); }); it('should not render a block if the value is less than a given number.', function() { var fn = hbs.compile('{{#gte number compare=8}}A{{/gte}}'); - assert.equal(fn({number: 5}), ''); + equal(fn({number: 5}), ''); }); }); }); @@ -277,49 +278,49 @@ describe('comparison', function() { describe('inline', function() { it('should return true when the property exists', function() { var fn = hbs.compile('{{has "foo"}}'); - assert.equal(fn({foo: 'bar'}), 'true'); + equal(fn({foo: 'bar'}), 'true'); }); }); describe('block', function() { it('should render a block if the condition is true.', function() { var fn = hbs.compile('{{#has context "C"}}A{{else}}B{{/has}}'); - assert.equal(fn({context: 'CCC'}), 'A'); + equal(fn({context: 'CCC'}), 'A'); }); it('should render the inverse block if false.', function() { var fn = hbs.compile('{{#has context "zzz"}}A{{else}}B{{/has}}'); - assert.equal(fn({context: 'CCC'}), 'B'); + equal(fn({context: 'CCC'}), 'B'); }); it('should render the inverse block if value is undefined.', function() { var fn = hbs.compile('{{#has context}}A{{else}}B{{/has}}'); - assert.equal(fn({context: 'CCC'}), 'B'); + equal(fn({context: 'CCC'}), 'B'); }); it('should render the inverse block if context is undefined.', function() { var fn = hbs.compile('{{#has}}A{{else}}B{{/has}}'); - assert.equal(fn({context: 'CCC'}), 'B'); + equal(fn({context: 'CCC'}), 'B'); }); it('should work with arrays', function() { var fn = hbs.compile('{{#has array "a"}}A{{else}}B{{/has}}'); - assert.equal(fn({array: ['a', 'b', 'c']}), 'A'); + equal(fn({array: ['a', 'b', 'c']}), 'A'); }); it('should work with two strings', function() { var fn = hbs.compile('{{#has "abc" "a"}}A{{else}}B{{/has}}'); - assert.equal(fn(), 'A'); + equal(fn(), 'A'); }); it('should return the inverse when the second string is not found', function() { var fn = hbs.compile('{{#has "abc" "z"}}A{{else}}B{{/has}}'); - assert.equal(fn(), 'B'); + equal(fn(), 'B'); }); it('should work with object keys', function() { var fn = hbs.compile('{{#has object "a"}}A{{else}}B{{/has}}'); - assert.equal(fn({object: {a: 'b'}}), 'A'); + equal(fn({object: {a: 'b'}}), 'A'); }); }); }); @@ -327,41 +328,41 @@ describe('comparison', function() { describe('isFalsey', function() { it('should render block if given value is falsey.', function() { var fn = hbs.compile('{{#if (isFalsey value)}}A{{else}}B{{/if}}'); - assert.equal(fn({value: 'nope'}), 'A'); + equal(fn({value: 'nope'}), 'A'); }); it('should render inverse if given value is truthy', function() { var fn = hbs.compile('{{#if (isFalsey value)}}A{{else}}B{{/if}}'); - assert.equal(fn({value: 'CCC'}), 'B'); + equal(fn({value: 'CCC'}), 'B'); }); }); describe('isTruthy', function() { it('should render block if given value is truthy.', function() { var fn = hbs.compile('{{#if (isTruthy value)}}A{{else}}B{{/if}}'); - assert.equal(fn({value: 'CCC'}), 'A'); + equal(fn({value: 'CCC'}), 'A'); }); it('should render inverse if given value is not truthy', function() { var fn = hbs.compile('{{#if (isTruthy value)}}A{{else}}B{{/if}}'); - assert.equal(fn({value: 'nope'}), 'B'); + equal(fn({value: 'nope'}), 'B'); }); }); describe('eq', function() { it('should render a block if the value is equal to a given number.', function() { var fn = hbs.compile('{{#eq number compare=8}}A{{/eq}}'); - assert.equal(fn({number: 8}), 'A'); + equal(fn({number: 8}), 'A'); }); it('should render the inverse block if falsey.', function() { var fn = hbs.compile('{{#eq number compare=8}}A{{else}}B{{/eq}}'); - assert.equal(fn({number: 9}), 'B'); + equal(fn({number: 9}), 'B'); }); it('should compare first and second args', function() { var fn = hbs.compile('{{#eq number 8}}A{{else}}B{{/eq}}'); - assert.equal(fn({number: 9}), 'B'); + equal(fn({number: 9}), 'B'); }); }); @@ -373,7 +374,7 @@ describe('comparison', function() { it('should render the inverse block if the number is odd', function() { var fn = hbs.compile('{{#ifEven number}}A{{else}}B{{/ifEven}}'); - assert.equal(fn({number: 9}), 'B'); + equal(fn({number: 9}), 'B'); }); }); @@ -403,46 +404,46 @@ describe('comparison', function() { describe('ifOdd', function() { it('should render the block if the given value is an even number', function() { var fn = hbs.compile('{{#ifOdd number}}A{{else}}B{{/ifOdd}}'); - assert.equal(fn({number: 9}), 'A'); + equal(fn({number: 9}), 'A'); }); it('should render the inverse block if the number is odd', function() { var fn = hbs.compile('{{#ifOdd number}}A{{else}}B{{/ifOdd}}'); - assert.equal(fn({number: 8}), 'B'); + equal(fn({number: 8}), 'B'); }); }); describe('is', function() { it('should render a block if the condition is true.', function() { var fn = hbs.compile('{{#is value "CCC"}}A{{else}}B{{/is}}'); - assert.equal(fn({value: 'CCC'}), 'A'); + equal(fn({value: 'CCC'}), 'A'); }); it('should use the `compare` arg on the options hash', function() { var fn = hbs.compile('{{#is value compare="CCC"}}A{{else}}B{{/is}}'); - assert.equal(fn({value: 'CCC'}), 'A'); + equal(fn({value: 'CCC'}), 'A'); }); it('should render the inverse if the condition is false', function() { var fn = hbs.compile('{{#is value "FOO"}}A{{else}}B{{/is}}'); - assert.equal(fn({value: 'CCC'}), 'B'); + equal(fn({value: 'CCC'}), 'B'); }); }); describe('isnt', function() { it('should render a block if the condition is not true.', function() { var fn = hbs.compile('{{#isnt number 2}}A{{else}}B{{/isnt}}'); - assert.equal(fn({number: 3}), 'A'); + equal(fn({number: 3}), 'A'); }); it('should use the `compare` arg on the options hash', function() { var fn = hbs.compile('{{#isnt value compare="CCC"}}A{{else}}B{{/isnt}}'); - assert.equal(fn({value: 'CCC'}), 'B'); + equal(fn({value: 'CCC'}), 'B'); }); it('should render the inverse if the condition is false', function() { var fn = hbs.compile('{{#isnt value "FOO"}}A{{else}}B{{/isnt}}'); - assert.equal(fn({value: 'CCC'}), 'A'); + equal(fn({value: 'CCC'}), 'A'); }); }); @@ -451,24 +452,24 @@ describe('comparison', function() { var fn = hbs.compile('{{#lt a b}}A{{else}}B{{/lt}}'); it('should render the first block if true.', function() { - assert.equal(fn({a: 14, b: 15}), 'A'); + equal(fn({a: 14, b: 15}), 'A'); }); it('should render the second block if equal.', function() { - assert.equal(fn({a: 15, b: 15}), 'B'); + equal(fn({a: 15, b: 15}), 'B'); }); it('should render the second block if false.', function() { - assert.equal(fn({a: 20, b: 15}), 'B'); + equal(fn({a: 20, b: 15}), 'B'); }); }); describe('compare hash', function() { it('should render a block if the value is less than a given number.', function() { var fn = hbs.compile('{{#lt number compare=8}}A{{/lt}}'); - assert.equal(fn({number: 5}), 'A'); + equal(fn({number: 5}), 'A'); }); it('should not render a block if the value is greater than a given number.', function() { var fn = hbs.compile('{{#lt number compare=8}}A{{/lt}}'); - assert.equal(fn({number: 42}), ''); + equal(fn({number: 42}), ''); }); }); }); @@ -478,32 +479,32 @@ describe('comparison', function() { describe('second arg', function() { it('should render the first block if true.', function() { - assert.equal(fn({a: 14, b: 15}), 'A'); + equal(fn({a: 14, b: 15}), 'A'); }); it('should render the first block if equal.', function() { - assert.equal(fn({a: 15, b: 15}), 'A'); + equal(fn({a: 15, b: 15}), 'A'); }); it('should render the second block if false.', function() { - assert.equal(fn({a: 20, b: 15}), 'B'); + equal(fn({a: 20, b: 15}), 'B'); }); }); describe('compare hash', function() { it('should render a block if the value is less than a given number.', function() { var fn = hbs.compile('{{#lte number compare=8}}A{{/lte}}'); - assert.equal(fn({number: 1}), 'A'); + equal(fn({number: 1}), 'A'); }); it('should render a block if the value is equal to a given number.', function() { var fn = hbs.compile('{{#lte number compare=8}}A{{/lte}}'); - assert.equal(fn({number: 8}), 'A'); + equal(fn({number: 8}), 'A'); }); it('should not render a block if the value is greater than a given number.', function() { var fn = hbs.compile('{{#lte number compare=8}}A{{/lte}}'); - assert.equal(fn({number: 27}), ''); + equal(fn({number: 27}), ''); }); }); }); @@ -511,12 +512,12 @@ describe('comparison', function() { describe('neither', function() { it('should render a block if one of the values is truthy.', function() { var fn = hbs.compile('{{#neither great magnificent}}A{{else}}B{{/neither}}'); - assert.equal(fn({great: false, magnificent: false}), 'A'); + equal(fn({great: false, magnificent: false}), 'A'); }); it('should render the inverse block if neither are true.', function() { var fn = hbs.compile('{{#neither great magnificent}}A{{else}}B{{/neither}}'); - assert.equal(fn({great: true, magnificent: false}), 'B'); + equal(fn({great: true, magnificent: false}), 'B'); }); }); @@ -524,31 +525,31 @@ describe('comparison', function() { describe('block', function() { it('should render a block if one of the values is truthy.', function() { var fn = hbs.compile('{{#or great magnificent}}A{{else}}B{{/or}}'); - assert.equal(fn({great: false, magnificent: true}), 'A'); + equal(fn({great: false, magnificent: true}), 'A'); }); it('should render a block if any of the values are truthy.', function() { var fn = hbs.compile('{{#or great magnificent fantastic}}A{{else}}B{{/or}}'); - assert.equal(fn({great: false, magnificent: false, fantastic: true}), 'A'); + equal(fn({great: false, magnificent: false, fantastic: true}), 'A'); }); it('should render the inverse block if neither are true.', function() { var fn = hbs.compile('{{#or great magnificent}}A{{else}}B{{/or}}'); - assert.equal(fn({great: false, magnificent: false}), 'B'); + equal(fn({great: false, magnificent: false}), 'B'); }); it('should render the inverse block if none are true.', function() { var fn = hbs.compile('{{#or great magnificent fantastic}}A{{else}}B{{/or}}'); - assert.equal(fn({great: false, magnificent: false, fantastic: false}), 'B'); + equal(fn({great: false, magnificent: false, fantastic: false}), 'B'); }); }); describe('inline', function() { it('should return false none of the values is truthy.', function() { var fn = hbs.compile('{{or great magnificent}}'); - assert.equal(fn({great: false, magnificent: false}), 'false'); + equal(fn({great: false, magnificent: false}), 'false'); }); it('should return true if one of the values is truthy.', function() { var fn = hbs.compile('{{or great magnificent}}'); - assert.equal(fn({great: false, magnificent: true}), 'true'); + equal(fn({great: false, magnificent: true}), 'true'); }); }); }); @@ -556,63 +557,63 @@ describe('comparison', function() { describe('unlessEq', function() { it('should render a block unless the value is equal to a given number.', function() { var fn = hbs.compile('{{#unlessEq number compare=8}}A{{/unlessEq}}'); - assert.equal(fn({number: 10}), 'A'); + equal(fn({number: 10}), 'A'); }); it('should render a block unless the value is equal to a given number.', function() { var fn = hbs.compile('{{#unlessEq number compare=8}}A{{/unlessEq}}'); - assert.equal(fn({number: 8}), ''); + equal(fn({number: 8}), ''); }); }); describe('unlessGt', function() { it('should render a block unless the value is greater than a given number.', function() { var fn = hbs.compile('{{#unlessGt number compare=8}}A{{/unlessGt}}'); - assert.equal(fn({number: 5}), 'A'); + equal(fn({number: 5}), 'A'); }); it('should render a block unless the value is greater than a given number.', function() { var fn = hbs.compile('{{#unlessGt number compare=8}}A{{/unlessGt}}'); - assert.equal(fn({number: 10}), ''); + equal(fn({number: 10}), ''); }); }); describe('unlessLt', function() { it('should render a block unless the value is less than a given number.', function() { var fn = hbs.compile('{{#unlessLt number compare=8}}A{{/unlessLt}}'); - assert.equal(fn({number: 10}), 'A'); + equal(fn({number: 10}), 'A'); }); it('should render a block unless the value is less than a given number.', function() { var fn = hbs.compile('{{#unlessLt number compare=8}}A{{/unlessLt}}'); - assert.equal(fn({number: 5}), ''); + equal(fn({number: 5}), ''); }); }); describe('unlessGteq', function() { it('should render a block unless the value is greater than or equal to a given number.', function() { var fn = hbs.compile('{{#unlessGteq number compare=8}}A{{/unlessGteq}}'); - assert.equal(fn({number: 4}), 'A'); + equal(fn({number: 4}), 'A'); }); it('should render a block unless the value is greater than or equal to a given number.', function() { var fn = hbs.compile('{{#unlessGteq number compare=8}}A{{/unlessGteq}}'); - assert.equal(fn({number: 8}), ''); + equal(fn({number: 8}), ''); }); it('should not render a block unless the value is greater than or equal to a given number.', function() { var fn = hbs.compile('{{#unlessGteq number compare=8}}A{{/unlessGteq}}'); - assert.equal(fn({number: 34}), ''); + equal(fn({number: 34}), ''); }); }); describe('unlessLteq', function() { it('should render a block unless the value is less than or equal to a given number.', function() { var fn = hbs.compile('{{#unlessLteq number compare=8}}A{{/unlessLteq}}'); - assert.equal(fn({number: 10}), 'A'); + equal(fn({number: 10}), 'A'); }); it('should render a block unless the value is less than or equal to a given number.', function() { var fn = hbs.compile('{{#unlessLteq number compare=8}}A{{/unlessLteq}}'); - assert.equal(fn({number: 8}), ''); + equal(fn({number: 8}), ''); }); it('should not render a block unless the value is less than or equal to a given number.', function() { var fn = hbs.compile('{{#unlessLteq number compare=8}}A{{/unlessLteq}}'); - assert.equal(fn({number: 4}), ''); + equal(fn({number: 4}), ''); }); }); }); diff --git a/test/html.js b/test/html.mjs similarity index 81% rename from test/html.js rename to test/html.mjs index b8df111d..0630396d 100644 --- a/test/html.js +++ b/test/html.mjs @@ -1,10 +1,11 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.html({handlebars: hbs}); +import 'mocha'; +import { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { html } from '../index.mjs'; +html({handlebars: hbs}); var locals = {data: [{aaa: 'AAA', bbb: 'BBB'}, {aaa: 'CCC', bbb: 'DDD'}]}; var actual; @@ -13,47 +14,47 @@ describe('html', function() { describe('attr', function() { it('should strip html from a string.', function() { var actual = hbs.compile('')({foo: 'btn'}); - assert.equal(actual, '
'); - assert.equal(hbs.compile('{{attr}}')(), ''); + equal(actual, '
'); + equal(hbs.compile('{{attr}}')(), ''); }); }); describe('css', function() { it('should return an empty string when no context is passed:', function() { - assert.equal(hbs.compile('{{{css}}}')(), ''); + equal(hbs.compile('{{{css}}}')(), ''); }); it('should use a path passed as a string', function() { var actual = hbs.compile('{{{css "abc.css"}}}')(); - assert.equal(actual, ''); + equal(actual, ''); }); it('should use options.assets', function() { var actual = hbs.compile('{{{css "abc.css"}}}')({options: {assets: 'foo'}}); - assert.equal(actual, ''); + equal(actual, ''); }); it('should ensure that options.assets is a string', function() { var actual = hbs.compile('{{{css "abc.css"}}}')({options: {assets: null}}); - assert.equal(actual, ''); + equal(actual, ''); }); it('should not use options.assets when passing in an absolute url', function() { var actual = hbs.compile('{{{css "https://abc.com/bar.css"}}}')({options: {assets: 'foo'}}); - assert.equal(actual, ''); + equal(actual, ''); }); it('should use the `href` attribute on the hash', function() { actual = hbs.compile('{{{css href=""}}}')(); - assert.equal(actual, ''); + equal(actual, ''); actual = hbs.compile('{{{css href="abc.css"}}}')(); - assert.equal(actual, ''); + equal(actual, ''); }); it('should create multiple tags from an array passed on the context:', function() { var ctx = {styles: ['a.css', 'bcss', 'c.css'] }; - assert.equal(hbs.compile('{{{css styles}}}')(ctx), [ + equal(hbs.compile('{{{css styles}}}')(ctx), [ '', '', '' @@ -62,27 +63,27 @@ describe('html', function() { it('should create a less tag (TODO: only works with array format)', function() { var ctx = {styles: ['a.less'] }; - assert.equal(hbs.compile('{{{css styles}}}')(ctx), ''); + equal(hbs.compile('{{{css styles}}}')(ctx), ''); }); }); describe('js', function() { it('should create an empty script tag', function() { - assert.equal(hbs.compile('{{{js}}}')(), ''); + equal(hbs.compile('{{{js}}}')(), ''); }); it('should use a path passed as a string', function() { - assert.equal(hbs.compile('{{{js "abc.js"}}}')(), ''); + equal(hbs.compile('{{{js "abc.js"}}}')(), ''); }); it('should use the `src` attribute on the hash', function() { - assert.equal(hbs.compile('{{{js src=""}}}')(), ''); - assert.equal(hbs.compile('{{{js src="abc.js"}}}')(), ''); + equal(hbs.compile('{{{js src=""}}}')(), ''); + equal(hbs.compile('{{{js src="abc.js"}}}')(), ''); }); it('should create multiple tags from an array passed on the context:', function() { var ctx = {scripts: ['a.js', 'bjs', 'c.js'] }; - assert.equal(hbs.compile('{{{js scripts}}}')(ctx), [ + equal(hbs.compile('{{{js scripts}}}')(ctx), [ '', '', '' @@ -91,31 +92,31 @@ describe('html', function() { it('should create a coffeescript tag (TODO: only works with array format)', function() { var ctx = {scripts: ['a.coffee'] }; - assert.equal(hbs.compile('{{{js scripts}}}')(ctx), ''); + equal(hbs.compile('{{{js scripts}}}')(ctx), ''); }); }); describe('sanitize', function() { it('should return an empty string when undefined.', function() { - assert.equal(hbs.compile('{{sanitize}}')(), ''); + equal(hbs.compile('{{sanitize}}')(), ''); }); it('should strip html from a string.', function() { var actual = hbs.compile('{{sanitize "foo"}}')(); - assert.equal(actual, 'foo'); + equal(actual, 'foo'); }); }); describe('ul', function() { it('should should return an unordered list', function() { var fn = hbs.compile('{{#ul data class="names"}}{{aaa}} {{bbb}}{{/ul}}'); - assert.equal(fn(locals), '
  • AAA BBB
  • \n
  • CCC DDD
'); + equal(fn(locals), '
  • AAA BBB
  • \n
  • CCC DDD
'); }); }); describe('ol', function() { it('should should return an ordered list', function() { var fn = hbs.compile('{{#ol data class="names"}}{{aaa}} {{bbb}}{{/ol}}'); - assert.equal(fn(locals), '
  1. AAA BBB
  2. \n
  3. CCC DDD
'); + equal(fn(locals), '
  1. AAA BBB
  2. \n
  3. CCC DDD
'); }); }); @@ -144,7 +145,7 @@ describe('html', function() { '
My new caption!
', '' ].join('\n'); - assert.equal(fn(context), comparison); + equal(fn(context), comparison); }); it('should return figure with extra class "test"', function() { @@ -175,7 +176,7 @@ describe('html', function() { '
My new caption!
', '' ].join('\n'); - assert.equal(fn(context), comparison); + equal(fn(context), comparison); }); it('should return figure with image that has class "test"', function() { @@ -205,7 +206,7 @@ describe('html', function() { '
My new caption!
', '' ].join('\n'); - assert.equal(fn(context), comparison); + equal(fn(context), comparison); }); it('should return figure with link that has class "test"', function() { @@ -235,7 +236,7 @@ describe('html', function() { '
My new caption!
', '' ].join('\n'); - assert.equal(fn(context), comparison); + equal(fn(context), comparison); }); it('should return figure without link', function() { @@ -259,7 +260,7 @@ describe('html', function() { '
My new caption!
', '' ].join('\n'); - assert.equal(fn(context), comparison); + equal(fn(context), comparison); }); it('should return figure without caption', function() { @@ -284,7 +285,7 @@ describe('html', function() { '
', '' ].join('\n'); - assert.equal(fn(context), comparison); + equal(fn(context), comparison); }); }); }); diff --git a/test/i18n.js b/test/i18n.mjs similarity index 77% rename from test/i18n.js rename to test/i18n.mjs index cbc1805f..0637050f 100644 --- a/test/i18n.js +++ b/test/i18n.mjs @@ -1,35 +1,36 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.i18n({handlebars: hbs}); +import 'mocha'; +import { throws, equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { i18n } from '../index.mjs'; +i18n({handlebars: hbs}); var context = {language: 'en', en: {key: 'value', a: {b: 'c'}}, fr: {key: 'valeur'}}; describe('i18n', function() { it('should throw an error when key is not a string.', function() { - assert.throws(function() { + throws(function() { hbs.compile('{{#i18n}}{{/i18n}}')(); }); }); it('should throw an error when language parameter is not a string.', function() { - assert.throws(function() { + throws(function() { hbs.compile('{{#i18n "key"}}{{/i18n}}')(); }); }); it('should throw an error when the language is not found.', function() { - assert.throws(function() { + throws(function() { var ctx = {language: 'foo', en: {key: 'value'}, fr: {key: 'valeur'}}; hbs.compile('{{#i18n "key"}}{{/i18n}}')(ctx); }); }); it('should throw an error when a key is not found.', function() { - assert.throws(function() { + throws(function() { var ctx = {language: 'en', en: {key: 'value'}, fr: {key: 'valeur'}}; hbs.compile('{{#i18n "foo"}}{{/i18n}}')(ctx); }); @@ -37,23 +38,23 @@ describe('i18n', function() { it('should take a key and return for the default language', function() { var fn = hbs.compile('{{#i18n "key"}}{{/i18n}}'); - assert.equal(fn(context), 'value'); + equal(fn(context), 'value'); }); it('should use options passed on the context', function() { var fn = hbs.compile('{{#i18n "key"}}{{/i18n}}'); var context = {en: {key: 'value'}, fr: {key: 'valeur'}}; context.options = {language: 'en'}; - assert.equal(fn(context), 'value'); + equal(fn(context), 'value'); }); it('should take a key and return for the override language', function() { var fn = hbs.compile('{{#i18n "key" language="fr"}}{{/i18n}}'); - assert.equal(fn(context), 'valeur'); + equal(fn(context), 'valeur'); }); it('should support using dot notation for the key', function() { var fn = hbs.compile('{{#i18n "a.b"}}{{/i18n}}'); - assert.equal(fn(context), 'c'); + equal(fn(context), 'c'); }); }); diff --git a/test/inflection.js b/test/inflection.js deleted file mode 100644 index c0e1686f..00000000 --- a/test/inflection.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; - -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.inflection({handlebars: hbs}); - -describe('inflection', function() { - describe('inflect', function() { - it('should return the plural or singular form of a word based on a value.', function() { - var template = hbs.compile('{{inflect mail "junk" "mail"}}'); - assert.equal(template({mail: 3}), 'mail'); - }); - - it('should return the plural or singular form of a word based on a value and include the count.', function() { - var template = hbs.compile('{{inflect messages "message" "messages" true}}'); - assert.equal(template({messages: 1}), '1 message'); - }); - }); - - describe('ordinalize', function() { - it('should return an ordinalized string.', function() { - assert.equal(hbs.compile('{{ordinalize 1}}')(), '1st'); - assert.equal(hbs.compile('{{ordinalize 3}}')(), '3rd'); - assert.equal(hbs.compile('{{ordinalize 11}}')(), '11th'); - assert.equal(hbs.compile('{{ordinalize 21}}')(), '21st'); - assert.equal(hbs.compile('{{ordinalize 29}}')(), '29th'); - assert.equal(hbs.compile('{{ordinalize 22}}')(), '22nd'); - }); - }); -}); diff --git a/test/inflection.mjs b/test/inflection.mjs new file mode 100644 index 00000000..be198f3e --- /dev/null +++ b/test/inflection.mjs @@ -0,0 +1,33 @@ +'use strict'; + +import 'mocha'; +import { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { inflection } from '../index.mjs'; +inflection({handlebars: hbs}); + +describe('inflection', function() { + describe('inflect', function() { + it('should return the plural or singular form of a word based on a value.', function() { + var template = hbs.compile('{{inflect mail "junk" "mail"}}'); + equal(template({mail: 3}), 'mail'); + }); + + it('should return the plural or singular form of a word based on a value and include the count.', function() { + var template = hbs.compile('{{inflect messages "message" "messages" true}}'); + equal(template({messages: 1}), '1 message'); + }); + }); + + describe('ordinalize', function() { + it('should return an ordinalized string.', function() { + equal(hbs.compile('{{ordinalize 1}}')(), '1st'); + equal(hbs.compile('{{ordinalize 3}}')(), '3rd'); + equal(hbs.compile('{{ordinalize 11}}')(), '11th'); + equal(hbs.compile('{{ordinalize 21}}')(), '21st'); + equal(hbs.compile('{{ordinalize 29}}')(), '29th'); + equal(hbs.compile('{{ordinalize 22}}')(), '22nd'); + }); + }); +}); diff --git a/test/match.mjs b/test/match.mjs index 36a3cbc8..789076c1 100644 --- a/test/match.mjs +++ b/test/match.mjs @@ -19,13 +19,13 @@ describe('matching', function() { describe('match', function() { it('should use the main micromatch function to filter an array', function() { var fn = hbs.compile('{{match files "(a|u)*.(mjs|js)"}}'); - equal(fn({files: testFiles}), 'array.mjs,url.js,utils.js,uuid.mjs'); + equal(fn({files: testFiles}), 'array.mjs,url.mjs,utils.js,uuid.mjs'); }); it('should take an array of patterns', function() { var ctx = {files: testFiles, patterns: ['(a|u)*.(mjs|js)', 'f*.js']}; var fn = hbs.compile('{{match files patterns}}'); - equal(fn(ctx), 'array.mjs,url.js,utils.js,uuid.mjs'); + equal(fn(ctx), 'array.mjs,url.mjs,utils.js,uuid.mjs'); }); it('should take options from the "options[helper name]" object', function() { @@ -42,7 +42,7 @@ describe('matching', function() { it('should use return matching items', function() { var fn = hbs.compile('{{match files "(a|u)*.(mjs|js)"}}'); - equal(fn({files: testFiles}), 'array.mjs,url.js,utils.js,uuid.mjs'); + equal(fn({files: testFiles}), 'array.mjs,url.mjs,utils.js,uuid.mjs'); }); it('should take options from the "options[helper name]" object', function() { diff --git a/test/object.mjs b/test/object.mjs index 03795773..3902116d 100644 --- a/test/object.mjs +++ b/test/object.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal, deepEqual } from 'assert'; -import { expected as _expected } from './support/index.js'; +import { expected as _expected } from './support/index.mjs'; var expected = _expected('object'); import helpers, { math, object as _object } from '../index.mjs'; import handlebars from 'handlebars' diff --git a/test/subexpressions.js b/test/subexpressions.mjs similarity index 66% rename from test/subexpressions.js rename to test/subexpressions.mjs index 1129691f..6a7600f2 100644 --- a/test/subexpressions.js +++ b/test/subexpressions.mjs @@ -1,11 +1,12 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.array({handlebars: hbs}); -helpers.string({handlebars: hbs}); +import 'mocha'; +import { equal } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { array, string } from '../index.mjs'; +array({handlebars: hbs}); +string({handlebars: hbs}); var context = { one: ['A', 'B', 'C', 'D', 'E', 'F'], @@ -17,11 +18,11 @@ describe('subexpressions', function() { describe('strings', function() { it('Should return the first item in a collection, all lowercase.', function() { var fn = hbs.compile('{{lowercase (first one)}}'); - assert.equal(fn(context), 'a'); + equal(fn(context), 'a'); }); it('Should return the last item in a collection, all uppercase.', function() { var fn = hbs.compile('{{uppercase (last two)}}'); - assert.equal(fn(context), 'F'); + equal(fn(context), 'F'); }); }); }); diff --git a/test/support/index.js b/test/support/index.mjs similarity index 61% rename from test/support/index.js rename to test/support/index.mjs index 2d1a3447..c8377a19 100644 --- a/test/support/index.js +++ b/test/support/index.mjs @@ -1,6 +1,6 @@ 'use strict'; -var fs = require('fs'); +import { readFileSync } from 'fs'; /** * Read a file at the given `filepath` @@ -9,9 +9,9 @@ var fs = require('fs'); * @return {String} */ -module.exports.read = function(fp) { - return fs.readFileSync(fp, 'utf8'); -}; +export function read(fp) { + return readFileSync(fp, 'utf8'); +} /** * Returns a function for reading a test fixture @@ -22,11 +22,11 @@ module.exports.read = function(fp) { * @return {String} */ -module.exports.fixture = function(type) { +export function fixture(type) { return function(fp) { - return module.exports.read('test/fixtures/' + type + '/' + fp); + return read('test/fixtures/' + type + '/' + fp); }; -}; +} /** * Returns a function for reading a file @@ -37,8 +37,8 @@ module.exports.fixture = function(type) { * @return {String} */ -module.exports.expected = function(type) { +export function expected(type) { return function(fp) { - return module.exports.read('test/expected/' + type + '/' + fp); + return read('test/expected/' + type + '/' + fp); }; -}; +} diff --git a/test/url.js b/test/url.mjs similarity index 67% rename from test/url.js rename to test/url.mjs index 460caadc..69d35a5f 100644 --- a/test/url.js +++ b/test/url.mjs @@ -1,44 +1,45 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars').create(); -var helpers = require('..'); -helpers.object({handlebars: hbs}); -helpers.url({handlebars: hbs}); +import 'mocha'; +import { equal, deepEqual } from 'assert'; +import handlebars from 'handlebars' +const hbs = handlebars.create(); +import { object, url } from '../index.mjs'; +object({handlebars: hbs}); +url({handlebars: hbs}); describe('url', function() { describe('urlResolve', function() { it('should resolve a URL', function() { var fn1 = hbs.compile('{{urlResolve "/one/two/three" "four"}}'); - assert.equal(fn1(), '/one/two/four'); + equal(fn1(), '/one/two/four'); var fn2 = hbs.compile('{{urlResolve "http://example.com/" "/one"}}'); - assert.equal(fn2(), 'http://example.com/one'); + equal(fn2(), 'http://example.com/one'); var fn3 = hbs.compile('{{urlResolve "http://example.com/one" "/two"}}'); - assert.equal(fn3(), 'http://example.com/two'); + equal(fn3(), 'http://example.com/two'); }); }); describe('stripQuerystring', function() { it('should return a url without its query string.', function() { var fn = hbs.compile('{{stripQuerystring "http://example.com?tests=true"}}'); - assert.equal(fn(), 'http://example.com'); + equal(fn(), 'http://example.com'); }); }); describe('encodeURI', function() { it('should return an encoded uri string.', function() { var fn = hbs.compile('{{encodeURI "http://example.com?comment=Thyme &time=again"}}'); - assert.equal(fn(), 'http%3A%2F%2Fexample.com%3Fcomment%3DThyme%20%26time%3Dagain'); + equal(fn(), 'http%3A%2F%2Fexample.com%3Fcomment%3DThyme%20%26time%3Dagain'); }); }); describe('decodeURI', function() { it('should return an decoded uri string.', function() { var fn = hbs.compile('{{{decodeURI "http%3A%2F%2Fexample.com%3Fcomment%3DThyme%20%26time%3Dagain"}}}'); - assert.equal(fn(), 'http://example.com?comment=Thyme &time=again'); + equal(fn(), 'http://example.com?comment=Thyme &time=again'); }); }); @@ -46,7 +47,7 @@ describe('url', function() { it('should take a string, and return an object stringified to JSON.', function() { var fn = hbs.compile('{{{JSONstringify (urlParse "http://foo.com/bar/baz?key=value" "json")}}}'); - assert.deepEqual(fn(), '{"protocol":"http:","slashes":true,"auth":null,"host":"foo.com","port":null,"hostname":"foo.com","hash":null,"search":"?key=value","query":"key=value","pathname":"/bar/baz","path":"/bar/baz?key=value","href":"http://foo.com/bar/baz?key=value"}'); + deepEqual(fn(), '{"protocol":"http:","slashes":true,"auth":null,"host":"foo.com","port":null,"hostname":"foo.com","hash":null,"search":"?key=value","query":"key=value","pathname":"/bar/baz","path":"/bar/baz?key=value","href":"http://foo.com/bar/baz?key=value"}'); }); }); @@ -54,27 +55,27 @@ describe('url', function() { it('should take an http url and return without the protocol', function() { var data = { testUrl: 'http://foo.bar' }; var fn = hbs.compile('{{stripProtocol testUrl}}'); - assert.equal(fn(data), '//foo.bar/'); + equal(fn(data), '//foo.bar/'); }); it('strip https protocol', function() { var data = { testUrl: 'https://foo.bar' }; var fn = hbs.compile('{{stripProtocol testUrl}}'); - assert.equal(fn(data), '//foo.bar/'); + equal(fn(data), '//foo.bar/'); }); it('should leave a relative url unchanged', function() { var expected = 'path/to/file'; var data = { testUrl: expected }; var fn = hbs.compile('{{stripProtocol testUrl}}'); - assert.equal(fn(data), expected); + equal(fn(data), expected); }); it('should leave an absolute url unchanged', function() { var expected = '/path/to/file'; var data = { testUrl: expected }; var fn = hbs.compile('{{stripProtocol testUrl}}'); - assert.equal(fn(data), expected); + equal(fn(data), expected); }); }); }); From 997ac36d4bee5290f2f5ee7dde63f18ada2f50dc Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 12:29:15 +0100 Subject: [PATCH 07/46] Migrate more tests --- lib/utils/html.js | 16 +++++----------- test/match.mjs | 6 +++--- test/{utils.js => utils.mjs} | 30 +++++++++++++++--------------- 3 files changed, 23 insertions(+), 29 deletions(-) rename test/{utils.js => utils.mjs} (59%) diff --git a/lib/utils/html.js b/lib/utils/html.js index 75758c99..92b2a09b 100644 --- a/lib/utils/html.js +++ b/lib/utils/html.js @@ -3,12 +3,6 @@ var util = require('./handlebarsUtils'); var striptags = require('striptags'); -/** - * Expose `utils` - */ - -var html = module.exports; - /** * Remove extra newlines from HTML, respect indentation. * @@ -17,7 +11,7 @@ var html = module.exports; * @api public */ -html.condense = function(str) { +module.exports.condense = function(str) { return str.replace(/(\r\n|\r|\n|\u2028|\u2029) {2,}/g, '\n'); }; @@ -29,7 +23,7 @@ html.condense = function(str) { * @api public */ -html.padcomments = function(str) { +module.exports.padcomments = function(str) { return str.replace(/(\s*'), '\n'); + equal(padcomments(''), '\n'); }); }); describe('parseAttributes', function() { it('should parse attributes', function() { - assert.equal(HTML.parseAttributes({a: 'b', c: 200 }), 'a="b" c="200"'); + equal(parseAttributes({a: 'b', c: 200 }), 'a="b" c="200"'); }); }); describe('toAttributes', function() { it('should convert an object hash into html attributes', function() { var hash = {disabled: true, display: 'hidden', class: 'fade'}; - assert.equal(HTML.toAttributes(hash), ' disabled display="hidden" class="fade"'); + equal(toAttributes(hash), ' disabled display="hidden" class="fade"'); }); }); }); From b9da189943d4c922bbdf379ca3670cc1174830a5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 12:32:02 +0100 Subject: [PATCH 08/46] Migrate more tests --- test/{helpers.js => helpers.mjs} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename test/{helpers.js => helpers.mjs} (89%) diff --git a/test/helpers.js b/test/helpers.mjs similarity index 89% rename from test/helpers.js rename to test/helpers.mjs index fb9fee7c..859af6ad 100644 --- a/test/helpers.js +++ b/test/helpers.mjs @@ -1,9 +1,9 @@ 'use strict'; -require('mocha'); -var assert = require('assert'); -var hbs = require('handlebars'); -var helpers = require('..'); +import 'mocha'; +import assert from 'assert'; +import hbs from 'handlebars'; +import helpers, { math } from '../index.mjs'; describe('helpers', function() { it('should should return all helpers:', function() { @@ -43,19 +43,19 @@ describe('helpers', function() { it('should support passing an instance of handlebars:', function() { helpers({handlebars: hbs}); - hbs.registerHelper('foo', function() {}); + hbs. registerHelper('foo', function() {}); assert(hbs.helpers.hasOwnProperty('foo')); }); it('should return a single collection:', function() { - var res = helpers.math(); + var res = math(); assert(res.hasOwnProperty('add')); assert(res.hasOwnProperty('subtract')); assert(res.hasOwnProperty('divide')); }); it('should register collection helpers with handlebars:', function() { - helpers.math(); + math(); assert(hbs.helpers.hasOwnProperty('add')); assert(hbs.helpers.hasOwnProperty('subtract')); assert(hbs.helpers.hasOwnProperty('divide')); From 15c26c1e19412658b03227ea0ae3680a47d3ecbd Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 12:36:52 +0100 Subject: [PATCH 09/46] Lint --- .eslintrc.json | 1 + package.json | 2 +- test/array.mjs | 2 +- test/code.mjs | 2 +- test/collection.mjs | 2 +- test/comparison.mjs | 2 +- test/html.mjs | 2 +- test/i18n.mjs | 2 +- test/inflection.mjs | 2 +- test/math.mjs | 2 +- test/misc.mjs | 2 +- test/number.mjs | 2 +- test/object.mjs | 2 +- test/path.mjs | 2 +- test/string.mjs | 2 +- test/subexpressions.mjs | 2 +- test/url.mjs | 2 +- test/uuid.mjs | 14 +++++++------- 18 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 09c66550..c15096ec 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,5 @@ { + "parserOptions": { "sourceType": "module" }, "env": { "browser": false, "es6": true, diff --git a/package.json b/package.json index aba7f068..7135b3ed 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "node": ">=10.12.0" }, "scripts": { - "lint": "eslint --ext js .", + "lint": "eslint --ext js,mjs .", "test": "mocha", "update:readmemd": "verb" }, diff --git a/test/array.mjs b/test/array.mjs index 93e66d1c..1f1d7a1a 100644 --- a/test/array.mjs +++ b/test/array.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { array, string, object } from '../index.mjs'; array({handlebars: hbs}); diff --git a/test/code.mjs b/test/code.mjs index 2f5a9920..98ba9bd8 100644 --- a/test/code.mjs +++ b/test/code.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal, throws } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { code } from '../index.mjs'; code({handlebars: hbs}); diff --git a/test/collection.mjs b/test/collection.mjs index f9aba8d6..05d3e2a5 100644 --- a/test/collection.mjs +++ b/test/collection.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { array as _array, collection, string } from '../index.mjs'; _array({handlebars: hbs}); diff --git a/test/comparison.mjs b/test/comparison.mjs index 6d0193d6..e43fb5d4 100644 --- a/test/comparison.mjs +++ b/test/comparison.mjs @@ -2,7 +2,7 @@ import 'mocha'; import assert, { equal, throws } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { comparison } from '../index.mjs'; comparison({handlebars: hbs}); diff --git a/test/html.mjs b/test/html.mjs index 0630396d..84329426 100644 --- a/test/html.mjs +++ b/test/html.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { html } from '../index.mjs'; html({handlebars: hbs}); diff --git a/test/i18n.mjs b/test/i18n.mjs index 0637050f..858f01e2 100644 --- a/test/i18n.mjs +++ b/test/i18n.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { throws, equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { i18n } from '../index.mjs'; i18n({handlebars: hbs}); diff --git a/test/inflection.mjs b/test/inflection.mjs index be198f3e..ca213cd3 100644 --- a/test/inflection.mjs +++ b/test/inflection.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { inflection } from '../index.mjs'; inflection({handlebars: hbs}); diff --git a/test/math.mjs b/test/math.mjs index a841e14a..480b4ebc 100644 --- a/test/math.mjs +++ b/test/math.mjs @@ -2,7 +2,7 @@ import 'mocha'; import assert, { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { math } from '../index.mjs'; math({handlebars: hbs}); diff --git a/test/misc.mjs b/test/misc.mjs index e6ea11e4..9509a10b 100644 --- a/test/misc.mjs +++ b/test/misc.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { misc } from '../index.mjs'; diff --git a/test/number.mjs b/test/number.mjs index 8c663a01..1e0222e1 100644 --- a/test/number.mjs +++ b/test/number.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { number as _number } from '../index.mjs'; _number({handlebars: hbs}); diff --git a/test/object.mjs b/test/object.mjs index 3902116d..aae6d967 100644 --- a/test/object.mjs +++ b/test/object.mjs @@ -5,7 +5,7 @@ import { equal, deepEqual } from 'assert'; import { expected as _expected } from './support/index.mjs'; var expected = _expected('object'); import helpers, { math, object as _object } from '../index.mjs'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); math({handlebars: hbs}); _object({handlebars: hbs}); diff --git a/test/path.mjs b/test/path.mjs index 599afdb8..2d3361a2 100644 --- a/test/path.mjs +++ b/test/path.mjs @@ -4,7 +4,7 @@ import 'mocha'; import { homedir } from 'os'; import { equal } from 'assert'; import { resolve, join } from 'path'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import gm from 'global-modules'; import { path as _path } from '../index.mjs'; diff --git a/test/string.mjs b/test/string.mjs index 091a179c..ab340018 100644 --- a/test/string.mjs +++ b/test/string.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { string } from '../index.mjs'; string({ handlebars: hbs }); diff --git a/test/subexpressions.mjs b/test/subexpressions.mjs index 6a7600f2..4df3ba93 100644 --- a/test/subexpressions.mjs +++ b/test/subexpressions.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { array, string } from '../index.mjs'; array({handlebars: hbs}); diff --git a/test/url.mjs b/test/url.mjs index 69d35a5f..e8940927 100644 --- a/test/url.mjs +++ b/test/url.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal, deepEqual } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import { object, url } from '../index.mjs'; object({handlebars: hbs}); diff --git a/test/uuid.mjs b/test/uuid.mjs index af9de0d3..a0868c9e 100644 --- a/test/uuid.mjs +++ b/test/uuid.mjs @@ -1,12 +1,12 @@ -"use strict"; +'use strict'; -import "mocha"; -import { match } from "assert"; -import { uuid } from "../lib/uuid.js"; +import 'mocha'; +import { match } from 'assert'; +import { uuid } from '../lib/uuid.js'; -describe("uuid", function () { - describe("generate", function () { - it("should generate a valid uuid", function () { +describe('uuid', function() { + describe('generate', function() { + it('should generate a valid uuid', function() { match( uuid(), /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i From b534380616b686c8d8a613eecbe03aad03e56541 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 12:57:12 +0100 Subject: [PATCH 10/46] lint --- index.mjs | 63 +++---- package.json | 2 +- test/match.mjs | 11 +- yarn.lock | 500 +++++++++++++++++++++++++------------------------ 4 files changed, 288 insertions(+), 288 deletions(-) diff --git a/index.mjs b/index.mjs index c3611576..dfdb499d 100644 --- a/index.mjs +++ b/index.mjs @@ -8,10 +8,8 @@ 'use strict'; import lib from './lib/index.js'; - -import { createRequire } from 'module'; -const require = createRequire(import.meta.url); - +// TODO: import only when required +import Handlebars from 'handlebars'; /** * Expose helpers @@ -26,7 +24,7 @@ export default function helpers(groups, options) { } options = options || {}; - var hbs = options.handlebars || options.hbs || require('handlebars'); + var hbs = options.handlebars || options.hbs || Handlebars; if (groups) { groups.forEach(function(key) { @@ -42,36 +40,35 @@ export default function helpers(groups, options) { return hbs.helpers; }; - - /** * Expose helper groups */ -function exportGroup(group){ - return function(options) { - options = options || {}; - var hbs = options.handlebars || options.hbs || require('handlebars'); - hbs.registerHelper(group); - return group; -}}; - -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) +function exportGroup(group) { + return function(options) { + options = options || {}; + var hbs = options.handlebars || options.hbs || Handlebars; + hbs.registerHelper(group); + return group; + }; +}; +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); -export * as utils from './lib/utils/index.js' +import * as _utils from './lib/utils/index.js'; +export const utils = _utils; diff --git a/package.json b/package.json index 7135b3ed..40a27607 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ }, "devDependencies": { "engine-handlebars": "^0.8.2", - "eslint": "^7.26.0", + "eslint": "^8.57.0", "fs-exists-sync": "^0.1.0", "global-modules": "^2.0.0", "gulp": "^4.0.2", diff --git a/test/match.mjs b/test/match.mjs index be41e7ca..151ca759 100644 --- a/test/match.mjs +++ b/test/match.mjs @@ -2,18 +2,13 @@ import { readdirSync } from 'fs'; import assert, { equal } from 'assert'; -import handlebars from 'handlebars' +import handlebars from 'handlebars'; const hbs = handlebars.create(); import helpers from '../index.js'; helpers.match({handlebars: hbs}); -import { fileURLToPath } from 'url'; -import path from 'path'; -const __filename = fileURLToPath(import.meta.url); - -const __dirname = path.dirname(__filename); -var testFiles = readdirSync(__dirname); -var rootFiles = readdirSync(path.join(__dirname, '..')); +var testFiles = readdirSync('./test'); +var rootFiles = readdirSync('.'); describe('matching', function() { describe('match', function() { diff --git a/yarn.lock b/yarn.lock index f525e7cb..12a83b1b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,42 +2,78 @@ # yarn lockfile v1 -"@babel/code-frame@7.12.11": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" - integrity sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw== +"@eslint-community/eslint-utils@^4.2.0": + version "4.4.1" + resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz#d1145bf2c20132d6400495d6df4bf59362fd9d56" + integrity sha512-s3O3waFUrMV8P/XaF/+ZTp1X9XBZW1a4B97ZnjQF2KYWaFD2A8KyFBsrsfSjEmjn3RGWAIuvlneuZm3CUK3jbA== dependencies: - "@babel/highlight" "^7.10.4" - -"@babel/helper-validator-identifier@^7.14.5": - version "7.14.5" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.5.tgz#d0f0e277c512e0c938277faa85a3968c9a44c0e8" - integrity sha512-5lsetuxCLilmVGyiLEfoHBRX8UCFD+1m2x3Rj97WrW3V7H3u4RWRXA4evMjImCsin2J2YT0QaVDGf+z8ondbAg== + eslint-visitor-keys "^3.4.3" -"@babel/highlight@^7.10.4": - version "7.14.5" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.14.5.tgz#6861a52f03966405001f6aa534a01a24d99e8cd9" - integrity sha512-qf9u2WFWVV0MppaL877j2dBtQIDgmidgjGk5VIMw3OadXvYaXn66U1BFlH2t4+t3i+8PhedppRv+i40ABzd+gg== - dependencies: - "@babel/helper-validator-identifier" "^7.14.5" - chalk "^2.0.0" - js-tokens "^4.0.0" +"@eslint-community/regexpp@^4.6.1": + version "4.12.1" + resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.12.1.tgz#cfc6cffe39df390a3841cde2abccf92eaa7ae0e0" + integrity sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ== -"@eslint/eslintrc@^0.4.2": - version "0.4.2" - resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.2.tgz#f63d0ef06f5c0c57d76c4ab5f63d3835c51b0179" - integrity sha512-8nmGq/4ycLpIwzvhI4tNDmQztZ8sp+hI7cyG8i1nQDhkAbRzHpXPidRAHlNvCZQpJTKw5ItIpMw9RSToGF00mg== +"@eslint/eslintrc@^2.1.4": + version "2.1.4" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.4.tgz#388a269f0f25c1b6adc317b5a2c55714894c70ad" + integrity sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ== dependencies: ajv "^6.12.4" - debug "^4.1.1" - espree "^7.3.0" - globals "^13.9.0" - ignore "^4.0.6" + debug "^4.3.2" + espree "^9.6.0" + globals "^13.19.0" + ignore "^5.2.0" import-fresh "^3.2.1" - js-yaml "^3.13.1" - minimatch "^3.0.4" + js-yaml "^4.1.0" + minimatch "^3.1.2" strip-json-comments "^3.1.1" +"@eslint/js@8.57.1": + version "8.57.1" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.1.tgz#de633db3ec2ef6a3c89e2f19038063e8a122e2c2" + integrity sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q== + +"@humanwhocodes/config-array@^0.13.0": + version "0.13.0" + resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.13.0.tgz#fb907624df3256d04b9aa2df50d7aa97ec648748" + integrity sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw== + dependencies: + "@humanwhocodes/object-schema" "^2.0.3" + debug "^4.3.1" + minimatch "^3.0.5" + +"@humanwhocodes/module-importer@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz#af5b2691a22b44be847b0ca81641c5fb6ad0172c" + integrity sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA== + +"@humanwhocodes/object-schema@^2.0.3": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz#4a2868d75d6d6963e423bcf90b7fd1be343409d3" + integrity sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA== + +"@nodelib/fs.scandir@2.1.5": + version "2.1.5" + resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" + integrity sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g== + dependencies: + "@nodelib/fs.stat" "2.0.5" + run-parallel "^1.1.9" + +"@nodelib/fs.stat@2.0.5": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz#5bd262af94e9d25bd1e71b05deed44876a222e8b" + integrity sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A== + +"@nodelib/fs.walk@^1.2.8": + version "1.2.8" + resolved "https://registry.yarnpkg.com/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz#e95737e8bb6746ddedf69c556953494f196fe69a" + integrity sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg== + dependencies: + "@nodelib/fs.scandir" "2.1.5" + fastq "^1.6.0" + "@sinonjs/commons@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-2.0.0.tgz#fd4ca5b063554307e8327b4564bd56d3b73924a3" @@ -78,17 +114,22 @@ resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q== -acorn-jsx@^5.3.1: - version "5.3.1" - resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b" - integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng== +"@ungap/structured-clone@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406" + integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ== + +acorn-jsx@^5.3.2: + version "5.3.2" + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" + integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ== -acorn@^7.4.0: - version "7.4.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" - integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== +acorn@^8.9.0: + version "8.14.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.14.0.tgz#063e2c70cac5fb4f6467f0b11152e04c682795b0" + integrity sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA== -ajv@^6.10.0, ajv@^6.12.4: +ajv@^6.12.4: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== @@ -98,16 +139,6 @@ ajv@^6.10.0, ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ajv@^8.0.1: - version "8.6.0" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.6.0.tgz#60cc45d9c46a477d80d92c48076d972c342e5720" - integrity sha512-cnUG4NSBiM4YFBxgZIj/In3/6KX+rQ2l2YPRVcvAMQGWEPKuXoPIhxzwqh31jA3IPbI4qEOp/5ILI4ynioXsGQ== - dependencies: - fast-deep-equal "^3.1.1" - json-schema-traverse "^1.0.0" - require-from-string "^2.0.2" - uri-js "^4.2.2" - align-text@^0.1.1, align-text@^0.1.3: version "0.1.4" resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117" @@ -203,7 +234,7 @@ ansi-bold@^0.1.1: dependencies: ansi-wrap "0.1.0" -ansi-colors@4.1.1, ansi-colors@^4.1.1: +ansi-colors@4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== @@ -333,6 +364,11 @@ ansi-regex@^5.0.0: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== +ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== + ansi-reset@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/ansi-reset/-/ansi-reset-0.1.1.tgz#e7e71292c3c7ddcd4d62ef4a6c7c05980911c3b7" @@ -642,11 +678,6 @@ assign-symbols@^1.0.0: resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367" integrity sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c= -astral-regex@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" - integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== - async-array-reduce@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/async-array-reduce/-/async-array-reduce-0.1.0.tgz#c74b88651d5c7f46ce5203d150c3cc7eedca57f2" @@ -1070,7 +1101,7 @@ chalk@^1.0.0, chalk@^1.1.1: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.1: +chalk@^2.0.1, chalk@^2.3.1: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -1463,9 +1494,9 @@ core-util-is@~1.0.0: integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= cross-spawn@^7.0.2: - version "7.0.3" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" - integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0" @@ -1562,7 +1593,7 @@ dateformat@^2.0.0: resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-2.2.0.tgz#4065e2013cf9fb916ddfd82efb506ad4c6769062" integrity sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI= -debug@4.3.1, debug@^4.0.1, debug@^4.1.1: +debug@4.3.1: version "4.3.1" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ== @@ -1590,6 +1621,13 @@ debug@^3.1.0: dependencies: ms "^2.1.1" +debug@^4.3.1, debug@^4.3.2: + version "4.3.7" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" + integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== + dependencies: + ms "^2.1.3" + decamelize@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -1914,13 +1952,6 @@ engine@^0.1.10, engine@^0.1.11, engine@^0.1.12, engine@^0.1.5: object.omit "^2.0.0" set-value "^0.2.0" -enquirer@^2.3.5: - version "2.3.6" - resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d" - integrity sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg== - dependencies: - ansi-colors "^4.1.1" - error-ex@^1.2.0: version "1.3.2" resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf" @@ -1984,94 +2015,81 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= -eslint-scope@^5.1.1: - version "5.1.1" - resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" - integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== +eslint-scope@^7.2.2: + version "7.2.2" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.2.tgz#deb4f92563390f32006894af62a22dba1c46423f" + integrity sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg== dependencies: esrecurse "^4.3.0" - estraverse "^4.1.1" - -eslint-utils@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.1.0.tgz#d2de5e03424e707dc10c74068ddedae708741b27" - integrity sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg== - dependencies: - eslint-visitor-keys "^1.1.0" - -eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" - integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== - -eslint-visitor-keys@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303" - integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw== + estraverse "^5.2.0" -eslint@^7.26.0: - version "7.29.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.29.0.tgz#ee2a7648f2e729485e4d0bd6383ec1deabc8b3c0" - integrity sha512-82G/JToB9qIy/ArBzIWG9xvvwL3R86AlCjtGw+A29OMZDqhTybz/MByORSukGxeI+YPCR4coYyITKk8BFH9nDA== - dependencies: - "@babel/code-frame" "7.12.11" - "@eslint/eslintrc" "^0.4.2" - ajv "^6.10.0" +eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4.3: + version "3.4.3" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" + integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== + +eslint@^8.57.0: + version "8.57.1" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.57.1.tgz#7df109654aba7e3bbe5c8eae533c5e461d3c6ca9" + integrity sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA== + dependencies: + "@eslint-community/eslint-utils" "^4.2.0" + "@eslint-community/regexpp" "^4.6.1" + "@eslint/eslintrc" "^2.1.4" + "@eslint/js" "8.57.1" + "@humanwhocodes/config-array" "^0.13.0" + "@humanwhocodes/module-importer" "^1.0.1" + "@nodelib/fs.walk" "^1.2.8" + "@ungap/structured-clone" "^1.2.0" + ajv "^6.12.4" chalk "^4.0.0" cross-spawn "^7.0.2" - debug "^4.0.1" + debug "^4.3.2" doctrine "^3.0.0" - enquirer "^2.3.5" escape-string-regexp "^4.0.0" - eslint-scope "^5.1.1" - eslint-utils "^2.1.0" - eslint-visitor-keys "^2.0.0" - espree "^7.3.1" - esquery "^1.4.0" + eslint-scope "^7.2.2" + eslint-visitor-keys "^3.4.3" + espree "^9.6.1" + esquery "^1.4.2" esutils "^2.0.2" fast-deep-equal "^3.1.3" file-entry-cache "^6.0.1" - functional-red-black-tree "^1.0.1" - glob-parent "^5.1.2" - globals "^13.6.0" - ignore "^4.0.6" - import-fresh "^3.0.0" + find-up "^5.0.0" + glob-parent "^6.0.2" + globals "^13.19.0" + graphemer "^1.4.0" + ignore "^5.2.0" imurmurhash "^0.1.4" is-glob "^4.0.0" - js-yaml "^3.13.1" + is-path-inside "^3.0.3" + js-yaml "^4.1.0" json-stable-stringify-without-jsonify "^1.0.1" levn "^0.4.1" lodash.merge "^4.6.2" - minimatch "^3.0.4" + minimatch "^3.1.2" natural-compare "^1.4.0" - optionator "^0.9.1" - progress "^2.0.0" - regexpp "^3.1.0" - semver "^7.2.1" - strip-ansi "^6.0.0" - strip-json-comments "^3.1.0" - table "^6.0.9" + optionator "^0.9.3" + strip-ansi "^6.0.1" text-table "^0.2.0" - v8-compile-cache "^2.0.3" -espree@^7.3.0, espree@^7.3.1: - version "7.3.1" - resolved "https://registry.yarnpkg.com/espree/-/espree-7.3.1.tgz#f2df330b752c6f55019f8bd89b7660039c1bbbb6" - integrity sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g== +espree@^9.6.0, espree@^9.6.1: + version "9.6.1" + resolved "https://registry.yarnpkg.com/espree/-/espree-9.6.1.tgz#a2a17b8e434690a5432f2f8018ce71d331a48c6f" + integrity sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ== dependencies: - acorn "^7.4.0" - acorn-jsx "^5.3.1" - eslint-visitor-keys "^1.3.0" + acorn "^8.9.0" + acorn-jsx "^5.3.2" + eslint-visitor-keys "^3.4.1" esprima@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== -esquery@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.4.0.tgz#2148ffc38b82e8c7057dfed48425b3e61f0f24a5" - integrity sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w== +esquery@^1.4.2: + version "1.6.0" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.6.0.tgz#91419234f804d852a82dceec3e16cdc22cf9dae7" + integrity sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg== dependencies: estraverse "^5.1.0" @@ -2082,11 +2100,6 @@ esrecurse@^4.3.0: dependencies: estraverse "^5.2.0" -estraverse@^4.1.1: - version "4.3.0" - resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" - integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== - estraverse@^5.1.0, estraverse@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880" @@ -2316,6 +2329,13 @@ fast-levenshtein@^2.0.6: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= +fastq@^1.6.0: + version "1.17.1" + resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.17.1.tgz#2a523f07a4e7b1e81a42b91b8bf2254107753b47" + integrity sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w== + dependencies: + reusify "^1.0.4" + file-entry-cache@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027" @@ -2420,7 +2440,7 @@ find-pkg@^0.1.0, find-pkg@^0.1.2: dependencies: find-file-up "^0.1.2" -find-up@5.0.0: +find-up@5.0.0, find-up@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== @@ -2478,11 +2498,12 @@ flagged-respawn@^1.0.0: integrity sha512-lNaHNVymajmk0OJMBn8fVUAU1BtDeKIqKoVhk4xAALB57aALg6b4W0MfJ/cUE0g9YBXy5XhSlPIpYIJ7HaY/3Q== flat-cache@^3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11" - integrity sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg== + version "3.2.0" + resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.2.0.tgz#2c0c2d5040c99b1632771a9d105725c0115363ee" + integrity sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw== dependencies: - flatted "^3.1.0" + flatted "^3.2.9" + keyv "^4.5.3" rimraf "^3.0.2" flat@^5.0.2: @@ -2490,10 +2511,10 @@ flat@^5.0.2: resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== -flatted@^3.1.0: - version "3.1.1" - resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469" - integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA== +flatted@^3.2.9: + version "3.3.2" + resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.2.tgz#adba1448a9841bec72b42c532ea23dbbedef1a27" + integrity sha512-AiwGJM8YcNOaobumgtng+6NHuOqC3A7MixFeDafM3X9cIUM+xUXoS5Vfgf+OihAYe20fxqNM9yPBXJzRtZ/4eA== flush-write-stream@^1.0.2: version "1.1.1" @@ -2591,11 +2612,6 @@ function-bind@^1.1.1: resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== -functional-red-black-tree@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" - integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= - gaze@^0.5.1: version "0.5.2" resolved "https://registry.yarnpkg.com/gaze/-/gaze-0.5.2.tgz#40b709537d24d1d45767db5a908689dfe69ac44f" @@ -2848,7 +2864,14 @@ glob-parent@^3.1.0: is-glob "^3.1.0" path-dirname "^1.0.0" -glob-parent@^5.1.2, glob-parent@~5.1.0: +glob-parent@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-6.0.2.tgz#6d237d99083950c79290f24c7642a3de9a28f9e3" + integrity sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A== + dependencies: + is-glob "^4.0.3" + +glob-parent@~5.1.0: version "5.1.2" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== @@ -3027,10 +3050,10 @@ global-prefix@^3.0.0: kind-of "^6.0.2" which "^1.3.1" -globals@^13.6.0, globals@^13.9.0: - version "13.9.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-13.9.0.tgz#4bf2bf635b334a173fb1daf7c5e6b218ecdc06cb" - integrity sha512-74/FduwI/JaIrr1H8e71UbDE+5x7pIPs1C2rrwC52SszOo043CsWOZEMW7o2Y58xwm9b+0RBKDxY5n2sUpEFxA== +globals@^13.19.0: + version "13.24.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-13.24.0.tgz#8432a19d78ce0c1e833949c36adb345400bb1171" + integrity sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ== dependencies: type-fest "^0.20.2" @@ -3077,6 +3100,11 @@ graceful-fs@~1.2.0: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-1.2.3.tgz#15a4806a57547cb2d2dbf27f42e89a8c3451b364" integrity sha1-FaSAaldUfLLS2/J/QuiajDRRs2Q= +graphemer@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6" + integrity sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag== + gray-matter@^2.0.2, gray-matter@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-2.1.1.tgz#3042d9adec2a1ded6a7707a9ed2380f8a17a430e" @@ -3571,12 +3599,12 @@ html-tag@^2.0.0: is-self-closing "^1.0.1" kind-of "^6.0.0" -ignore@^4.0.6: - version "4.0.6" - resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" - integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== +ignore@^5.2.0: + version "5.3.2" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.2.tgz#3cd40e729f3643fd87cb04e50bf0eb722bc596f5" + integrity sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g== -import-fresh@^3.0.0, import-fresh@^3.2.1: +import-fresh@^3.2.1: version "3.3.0" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b" integrity sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw== @@ -3831,6 +3859,13 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: dependencies: is-extglob "^2.1.1" +is-glob@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" + integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== + dependencies: + is-extglob "^2.1.1" + is-match@^0.4.0: version "0.4.1" resolved "https://registry.yarnpkg.com/is-match/-/is-match-0.4.1.tgz#fb5f6c6709a1543b7c7efa7d9530e5b776f61f83" @@ -3880,6 +3915,11 @@ is-number@^7.0.0: resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== +is-path-inside@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.3.tgz#d231362e53a07ff2b0e0ea7fed049161ffd16283" + integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ== + is-plain-obj@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287" @@ -4128,11 +4168,6 @@ js-comments@^0.5.2, js-comments@^0.5.4: relative "^3.0.0" write "^0.2.0" -js-tokens@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" - integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== - js-yaml-lite@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/js-yaml-lite/-/js-yaml-lite-0.1.1.tgz#9a813e305de40789c1a64a462ff8c145ddef737c" @@ -4145,7 +4180,7 @@ js-yaml@4.0.0: dependencies: argparse "^2.0.1" -js-yaml@^3.10.0, js-yaml@^3.13.1, js-yaml@^3.8.1: +js-yaml@^3.10.0, js-yaml@^3.8.1: version "3.14.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537" integrity sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g== @@ -4160,16 +4195,16 @@ js-yaml@^4.1.0: dependencies: argparse "^2.0.1" +json-buffer@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13" + integrity sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ== + json-schema-traverse@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== -json-schema-traverse@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" - integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== - json-stable-stringify-without-jsonify@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" @@ -4185,6 +4220,13 @@ just-extend@^6.2.0: resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-6.2.0.tgz#b816abfb3d67ee860482e7401564672558163947" integrity sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw== +keyv@^4.5.3: + version "4.5.4" + resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.4.tgz#a879a99e29452f942439f2a405e3af8b31d4de93" + integrity sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw== + dependencies: + json-buffer "3.0.1" + kind-of@^0.1.0, kind-of@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-0.1.2.tgz#07bd601cc9433f5d79bd5edd2031ed155f0604a4" @@ -4554,11 +4596,6 @@ lodash.clonedeep@3.0.1: lodash._baseclone "^3.0.0" lodash._bindcallback "^3.0.0" -lodash.clonedeep@^4.5.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" - integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= - lodash.escape@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/lodash.escape/-/lodash.escape-3.2.0.tgz#995ee0dc18c1b48cc92effae71a10aab5b487698" @@ -4638,11 +4675,6 @@ lodash.templatesettings@^4.0.0: dependencies: lodash._reinterpolate "^3.0.0" -lodash.truncate@^4.4.2: - version "4.4.2" - resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193" - integrity sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM= - lodash@^3.10.1, lodash@^3.5.0, lodash@^3.6.0, lodash@^3.7.0: version "3.10.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" @@ -4767,13 +4799,6 @@ lru-cache@2: resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" integrity sha1-bUUk6LlV+V1PW1iFHOId1y+06VI= -lru-cache@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" - integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== - dependencies: - yallist "^4.0.0" - make-iterator@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/make-iterator/-/make-iterator-0.1.1.tgz#873d27b8198a465a81483b6f5d16da4e863ecf5b" @@ -5103,6 +5128,13 @@ minimatch@^2.0.1: dependencies: brace-expansion "^1.0.0" +minimatch@^3.0.5, minimatch@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" + integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== + dependencies: + brace-expansion "^1.1.7" + minimatch@~0.2.11: version "0.2.14" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a" @@ -5197,7 +5229,7 @@ ms@2.1.2: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== -ms@2.1.3, ms@^2.1.1: +ms@2.1.3, ms@^2.1.1, ms@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== @@ -5549,17 +5581,17 @@ option-cache@^3.4.0: set-value "^0.4.3" to-object-path "^0.3.0" -optionator@^0.9.1: - version "0.9.1" - resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499" - integrity sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw== +optionator@^0.9.3: + version "0.9.4" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.4.tgz#7ea1c1a5d91d764fb282139c88fe11e182a3a734" + integrity sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g== dependencies: deep-is "^0.1.3" fast-levenshtein "^2.0.6" levn "^0.4.1" prelude-ls "^1.2.1" type-check "^0.4.0" - word-wrap "^1.2.3" + word-wrap "^1.2.5" ora@^2.1.0: version "2.1.0" @@ -5973,11 +6005,6 @@ process-nextick-args@^2.0.0, process-nextick-args@~2.0.0: resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== -progress@^2.0.0: - version "2.0.3" - resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" - integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== - project-name@^0.2.6: version "0.2.6" resolved "https://registry.yarnpkg.com/project-name/-/project-name-0.2.6.tgz#3e4f781fe1ee94b0786a9bae53506376c379af69" @@ -6009,6 +6036,11 @@ punycode@^2.1.0: resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== +queue-microtask@^1.2.2: + version "1.2.3" + resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243" + integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A== + randomatic@^3.0.0: version "3.1.1" resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed" @@ -6180,11 +6212,6 @@ regexp.prototype.flags@^1.2.0: call-bind "^1.0.2" define-properties "^1.1.3" -regexpp@^3.1.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2" - integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg== - relative-dest@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/relative-dest/-/relative-dest-0.1.0.tgz#ba055b4c2a021f71de92a582eb766dd7b3b0c618" @@ -6293,11 +6320,6 @@ require-directory@^2.1.1: resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I= -require-from-string@^2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" - integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw== - require-main-filename@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" @@ -6390,6 +6412,11 @@ rethrow@^0.2.3: lazy-cache "^0.2.3" right-align "^0.1.3" +reusify@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" + integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== + right-align@^0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef" @@ -6420,6 +6447,13 @@ rimraf@^3.0.2: dependencies: glob "^7.1.3" +run-parallel@^1.1.9: + version "1.2.0" + resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee" + integrity sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA== + dependencies: + queue-microtask "^1.2.2" + safe-buffer@^5.1.0, safe-buffer@~5.2.0: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" @@ -6469,13 +6503,6 @@ semver-greatest-satisfied-range@^1.1.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== -semver@^7.2.1: - version "7.3.5" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" - integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== - dependencies: - lru-cache "^6.0.0" - serialize-javascript@5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-5.0.1.tgz#7886ec848049a462467a97d3d918ebb2aaf934f4" @@ -6647,15 +6674,6 @@ sinon@^17.0.1: nise "^5.1.5" supports-color "^7.2.0" -slice-ansi@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-4.0.0.tgz#500e8dd0fd55b05815086255b3195adf2a45fe6b" - integrity sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ== - dependencies: - ansi-styles "^4.0.0" - astral-regex "^2.0.0" - is-fullwidth-code-point "^3.0.0" - snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" @@ -6911,6 +6929,13 @@ strip-ansi@^6.0.0: dependencies: ansi-regex "^5.0.0" +strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-bom-string@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/strip-bom-string/-/strip-bom-string-1.0.0.tgz#e5211e9224369fbb81d633a2f00044dc8cedad92" @@ -6943,7 +6968,7 @@ strip-indent@^1.0.1: dependencies: get-stdin "^4.0.1" -strip-json-comments@3.1.1, strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: +strip-json-comments@3.1.1, strip-json-comments@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== @@ -6992,18 +7017,6 @@ sver-compat@^1.5.0: es6-iterator "^2.0.1" es6-symbol "^3.1.1" -table@^6.0.9: - version "6.7.1" - resolved "https://registry.yarnpkg.com/table/-/table-6.7.1.tgz#ee05592b7143831a8c94f3cee6aae4c1ccef33e2" - integrity sha512-ZGum47Yi6KOOFDE8m223td53ath2enHcYLgOCjGr5ngu8bdIARQk6mN/wRMv4yMRcHnCSnHbCEha4sobQx5yWg== - dependencies: - ajv "^8.0.1" - lodash.clonedeep "^4.5.0" - lodash.truncate "^4.4.2" - slice-ansi "^4.0.0" - string-width "^4.2.0" - strip-ansi "^6.0.0" - template-bind-helpers@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/template-bind-helpers/-/template-bind-helpers-0.1.2.tgz#dcb7376db2681c43dd74bc3a73f522400e1b727e" @@ -7210,7 +7223,7 @@ templates@^1.2.9: text-table@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" - integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= + integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw== through2-filter@^3.0.0: version "3.0.0" @@ -7593,11 +7606,6 @@ uuid@^9.0.1: resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== -v8-compile-cache@^2.0.3: - version "2.3.0" - resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee" - integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA== - v8flags@^2.0.10: version "2.1.1" resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.1.1.tgz#aab1a1fa30d45f88dd321148875ac02c0b55e5b4" @@ -7997,6 +8005,11 @@ word-wrap@^1.1.0, word-wrap@^1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== +word-wrap@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" + integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== + wordwrap@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" @@ -8058,11 +8071,6 @@ y18n@^5.0.5: resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== -yallist@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" - integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== - yargs-parser@20.2.4: version "20.2.4" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54" From 18165ddb4b1430e4d897542dfc7dea3d770da088 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 13:35:42 +0100 Subject: [PATCH 11/46] Remove index.js --- index.js | 61 --------------------------- package.json | 2 +- test/examples/{index.js => index.mjs} | 32 ++++++++------ test/match.mjs | 2 +- 4 files changed, 20 insertions(+), 77 deletions(-) delete mode 100644 index.js rename test/examples/{index.js => index.mjs} (82%) diff --git a/index.js b/index.js deleted file mode 100644 index e527003a..00000000 --- a/index.js +++ /dev/null @@ -1,61 +0,0 @@ -/*! - * handlebars-helpers - * - * Copyright (c) 2013-2017, Jon Schlinkert, Brian Woodward. - * Released under the MIT License. - */ - -'use strict'; - -var lib = require('./lib/'); - -/** - * Expose helpers - */ - -module.exports = function helpers(groups, options) { - if (typeof groups === 'string') { - groups = [groups]; - } else if (!Array.isArray(groups)) { - options = groups; - groups = null; - } - - options = options || {}; - var hbs = options.handlebars || options.hbs || require('handlebars'); - module.exports.handlebars = hbs; - - if (groups) { - groups.forEach(function(key) { - hbs.registerHelper(lib[key]); - }); - } else { - for (const key in lib) { - const group = lib[key]; - hbs.registerHelper(group); - } - } - - return hbs.helpers; -}; - -/** - * Expose helper groups - */ -for (const key in lib) { - const group = lib[key]; - - module.exports[key] = function(options) { - options = options || {}; - var hbs = options.handlebars || options.hbs || require('handlebars'); - module.exports.handlebars = hbs; - hbs.registerHelper(group); - return group; - }; -} - -/** - * Expose `utils` - */ - -module.exports.utils = require('./lib/utils'); diff --git a/package.json b/package.json index 40a27607..de1faded 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "index.js", "lib" ], - "main": "index.js", + "main": "index.mjs", "engines": { "node": ">=10.12.0" }, diff --git a/test/examples/index.js b/test/examples/index.mjs similarity index 82% rename from test/examples/index.js rename to test/examples/index.mjs index bb4bec66..e98133de 100644 --- a/test/examples/index.js +++ b/test/examples/index.mjs @@ -1,22 +1,26 @@ 'use strict'; -require('mocha'); +import 'mocha'; -const sinon = require('sinon'); -sinon.stub(require('../../lib/uuid'), 'uuid').returns('f34ebc66-93bd-4f7c-b79b-92b5569138bc'); +import { restore, stub } from 'sinon'; +import uuid from '../../lib/uuid.js'; +import math from '../../lib/math.js'; +restore(); +stub(uuid, 'uuid').returns('f34ebc66-93bd-4f7c-b79b-92b5569138bc'); -sinon.stub(require('../../lib/math'), 'random').returns(10); +stub(math, 'random').returns(10); -var assert = require('assert'); -var lib = require('../../lib/'); +import { equal } from 'assert'; +import lib from '../../lib/index.js'; -const fs = require('fs'); -const doctrine = require('doctrine'); -const path = require('path'); +import { readFileSync } from 'fs'; +import { parse } from 'doctrine'; +import { join } from 'path'; -var handlebars = require('handlebars').create(); -var helpers = require('../..'); +import hbs from 'handlebars'; +const handlebars = hbs.create(); +import * as helpers from '../../index.mjs'; function lookForward(lines, funcLines, idx) { const funcLen = funcLines.length; @@ -55,7 +59,7 @@ function getCommentInfo(file, func) { if (comment == null) { return { description: '' }; } - const docs = doctrine.parse(comment, { unwrap: true }); + const docs = parse(comment, { unwrap: true }); // some hacky fixes docs.description = docs.description.replace(/\n/g, ' '); docs.description = docs.description.replace(/[ ]{2,}/g, ' '); @@ -85,7 +89,7 @@ describe('examples', function() { const group = lib[key]; - const fileContent = fs.readFileSync(require.resolve(path.join('../../lib/', key)), 'utf8'); + const fileContent = readFileSync(join('./lib/', `${key}.js`), 'utf8'); describe(key, function() { for (const func in group) { @@ -124,7 +128,7 @@ describe('examples', function() { // Nothing to parse } result = result.replace(/&nbsp;/g, ' '); - assert.equal(result, expectedResult); + equal(result, expectedResult); }); } }); diff --git a/test/match.mjs b/test/match.mjs index 151ca759..0559c163 100644 --- a/test/match.mjs +++ b/test/match.mjs @@ -4,7 +4,7 @@ import { readdirSync } from 'fs'; import assert, { equal } from 'assert'; import handlebars from 'handlebars'; const hbs = handlebars.create(); -import helpers from '../index.js'; +import * as helpers from '../index.mjs'; helpers.match({handlebars: hbs}); var testFiles = readdirSync('./test'); From 275949e77716b2b14fb3c21ca62e4bac5aca9734 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 13:37:41 +0100 Subject: [PATCH 12/46] Remove unnecessary "integration" tests --- package.json | 3 - test/integration/templates.js | 110 ----------- yarn.lock | 335 ++-------------------------------- 3 files changed, 11 insertions(+), 437 deletions(-) delete mode 100644 test/integration/templates.js diff --git a/package.json b/package.json index de1faded..696e0aa3 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,6 @@ "uuid": "^9.0.1" }, "devDependencies": { - "engine-handlebars": "^0.8.2", "eslint": "^8.57.0", "fs-exists-sync": "^0.1.0", "global-modules": "^2.0.0", @@ -98,10 +97,8 @@ "js-yaml": "^4.1.0", "markdown-link": "^0.1.1", "mocha": "^8.4.0", - "rimraf": "^3.0.2", "sinon": "^17.0.1", "template-helpers": "^1.0.1", - "templates": "^1.2.9", "through2": "^4.0.2", "verb": "^0.8.10", "verb-cli": "^0.7.4", diff --git a/test/integration/templates.js b/test/integration/templates.js deleted file mode 100644 index 9df07e6a..00000000 --- a/test/integration/templates.js +++ /dev/null @@ -1,110 +0,0 @@ -'use strict'; - -var os = require('os'); -var path = require('path'); -var assert = require('assert'); -var gm = require('global-modules'); -var engine = require('engine-handlebars'); -var templates = require('templates'); -var helpers = require('../..'); -var compile; -var render; -var app; - -describe('templates integration tests', function() { - beforeEach(function() { - app = templates(); - app.helpers(helpers()); - app.engine('hbs', engine); - app.option('engine', 'hbs'); - app.context = function(val) { - return val; - }; - - compile = function(content) { - return app.compile(app.view({path: 'string', content: content})); - }; - - render = function(content, context) { - return compile(content).fn(context); - }; - }); - - describe('absolute', function() { - it('should create an absolute file path', function() { - assert.equal(render('{{absolute "a/b/c/package.json"}}'), path.resolve('a/b/c/package.json')); - assert.equal(render('{{absolute "a/b/c/docs/toc.md"}}'), path.resolve('a/b/c/docs/toc.md')); - }); - - it('should use the cwd on locals', function() { - assert.equal(render('{{absolute "a/b/c/package.json"}}', {cwd: os.homedir()}), path.resolve(os.homedir(), 'a/b/c/package.json')); - assert.equal(render('{{absolute "a/b/c/package.json"}}', {cwd: os.homedir()}), path.resolve(os.homedir(), 'a/b/c/package.json')); - assert.equal(render('{{absolute "a/b/c/docs/toc.md"}}', {cwd: os.homedir()}), path.resolve(os.homedir(), 'a/b/c/docs/toc.md')); - }); - }); - - describe('dirname', function() { - it('should get the dirname of a file path', function() { - assert.equal(render('{{dirname "a/b/c/package.json"}}'), 'a/b/c'); - assert.equal(render('{{dirname "a/b/c/docs/toc.md"}}'), 'a/b/c/docs'); - }); - }); - - describe('relative', function() { - it('should return the relative path from file A to file B', function() { - var view = compile('{{relative "dist/docs.html" "index.html"}}'); - assert.equal(view.fn(), path.join('..', 'index.html')); - }); - it('should return the relative path from file A to file B in', function() { - var view = compile('{{relative "examples/result/md/path.md" "examples/assets"}}'); - assert.equal(view.fn(), path.join('..', '..', 'assets')); - }); - it('should use the cwd passed on options', function() { - var view = compile('{{relative "examples/result/md/path.md" "examples/assets"}}'); - assert.equal(view.fn({cwd: gm}), path.join('..', '..', 'assets')); - }); - }); - - describe('basename', function() { - it('should get the basename of a file path', function() { - assert.equal(render('{{basename "a/b/c/package.json"}}'), 'package.json'); - assert.equal(render('{{basename "a/b/c/docs/toc.md"}}'), 'toc.md'); - }); - it('should get the basename when a path has no extension', function() { - var view = compile('{{basename "a/b/c/CHANGELOG"}}'); - assert.equal(view.fn(), 'CHANGELOG'); - }); - }); - - describe('stem', function() { - it('should get the stem of a file path', function() { - assert.equal(render('{{stem "a/b/c/package.json"}}'), 'package'); - assert.equal(render('{{stem "a/b/c/docs/toc.md"}}'), 'toc'); - }); - it('should get the stem when a path has no extension', function() { - var view = compile('{{stem "CHANGELOG"}}'); - assert.equal(view.fn(), 'CHANGELOG'); - }); - }); - - describe('extname', function() { - it('should get the extname of a file path', function() { - assert.equal(render('{{extname "a/b/c/package.json"}}'), '.json'); - assert.equal(render('{{extname "a/b/c/docs/toc.md"}}'), '.md'); - }); - it('should not blow up when a path has no extension', function() { - var view = compile('{{extname "a/b/c/CHANGELOG"}}'); - assert.equal(view.fn(), ''); - }); - }); - - describe('segments', function() { - it('should return specified path segments:', function() { - assert.equal(render('{{segments "a/b/c/e.js" 1 3}}'), 'b/c'); - assert.equal(render('{{segments "a/b/c/e.js" 1 2}}'), 'b'); - assert.equal(render('{{segments "a/b/c/e.js" 0 3}}'), 'a/b/c'); - assert.equal(render('{{segments "a/b/c/e.js" 2 3}}'), 'c'); - assert.equal(render('{{segments "a/b/c/e.js" 0 3}}'), 'a/b/c'); - }); - }); -}); diff --git a/yarn.lock b/yarn.lock index 12a83b1b..61698bc1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -522,7 +522,7 @@ arr-filter@^1.1.0, arr-filter@^1.1.1: dependencies: make-iterator "^1.0.0" -arr-flatten@^1.0.0, arr-flatten@^1.0.1, arr-flatten@^1.0.3, arr-flatten@^1.1.0: +arr-flatten@^1.0.0, arr-flatten@^1.0.1, arr-flatten@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.1.0.tgz#36048bbff4e7b47e136644316c99669ea5ae91f1" integrity sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg== @@ -600,15 +600,6 @@ array-slice@^1.0.0: resolved "https://registry.yarnpkg.com/array-slice/-/array-slice-1.1.0.tgz#e368ea15f89bc7069f7ffb89aec3a6c7d4ac22d4" integrity sha512-B1qMD3RBP7O8o0H2KbrXDyB0IccejMF15+87Lvlor12ONPRHP6gTjXMNkt/d3ZuOGbAe66hFmaCfECI24Ufp6w== -array-sort@^0.1.2: - version "0.1.4" - resolved "https://registry.yarnpkg.com/array-sort/-/array-sort-0.1.4.tgz#662855eaeb671b4188df4451b2f24a0753992b23" - integrity sha512-BNcM+RXxndPxiZ2rd76k6nyQLRZr2/B/sdi8pQ+Joafr5AH279L40dfokSUTp8O+AaqYjXWhblBWa2st2nc4fQ== - dependencies: - default-compare "^1.0.0" - get-value "^2.0.6" - kind-of "^5.0.2" - array-sort@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-sort/-/array-sort-1.0.0.tgz#e4c05356453f56f53512a7d1d6123f2c54c0a88a" @@ -728,14 +719,6 @@ async-helpers@^0.2.2: dependencies: async "^0.9.0" -async-helpers@^0.3.9: - version "0.3.17" - resolved "https://registry.yarnpkg.com/async-helpers/-/async-helpers-0.3.17.tgz#3d91af1ff853d62e9809b0f31c4bdac79baa6ba4" - integrity sha512-LfgCyvmK6ZiC7pyqOgli2zfkWL4HYbEb+HXvGgdmqVBgsOOtQz5rSF8Ii/H/1cNNtrfj1KsdZE/lUMeIY3Qcwg== - dependencies: - co "^4.6.0" - kind-of "^6.0.0" - async-listener@^0.6.0: version "0.6.10" resolved "https://registry.yarnpkg.com/async-listener/-/async-listener-0.6.10.tgz#a7c97abe570ba602d782273c0de60a51e3e17cbc" @@ -845,29 +828,6 @@ base-data@^0.6.0: set-value "^2.0.0" union-value "^1.0.0" -base-engines@^0.2.0: - version "0.2.1" - resolved "https://registry.yarnpkg.com/base-engines/-/base-engines-0.2.1.tgz#697800ca8ab888a33789738dbfaccb818a2a5a7b" - integrity sha1-aXgAyoq4iKM3iXONv6zLgYoqWns= - dependencies: - debug "^2.2.0" - define-property "^0.2.5" - engine-cache "^0.19.0" - is-valid-app "^0.1.2" - lazy-cache "^2.0.1" - -base-helpers@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/base-helpers/-/base-helpers-0.2.0.tgz#75a9494bb8c059ff3d7943829cf755047bfe10d7" - integrity sha1-dalJS7jAWf89eUOCnPdVBHv+ENc= - dependencies: - debug "^2.6.0" - define-property "^0.2.5" - is-valid-app "^0.2.1" - isobject "^3.0.0" - lazy-cache "^2.0.2" - load-helpers "^0.3.1" - base-loader@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/base-loader/-/base-loader-0.1.0.tgz#d9237e506582bb5e475db7536580741d3c7e537c" @@ -876,40 +836,6 @@ base-loader@^0.1.0: map-files "^0.7.4" relative "^3.0.0" -base-option@^0.8.4: - version "0.8.4" - resolved "https://registry.yarnpkg.com/base-option/-/base-option-0.8.4.tgz#11417fa9244f227a4d537b4d291723462787d5c7" - integrity sha1-EUF/qSRPInpNU3tNKRcjRieH1cc= - dependencies: - define-property "^0.2.5" - get-value "^2.0.6" - is-valid-app "^0.2.0" - isobject "^2.1.0" - lazy-cache "^2.0.1" - mixin-deep "^1.1.3" - option-cache "^3.4.0" - set-value "^0.3.3" - -base-plugins@^0.4.13: - version "0.4.13" - resolved "https://registry.yarnpkg.com/base-plugins/-/base-plugins-0.4.13.tgz#91df178dc37f86842dea286d79e48fb86b5aac3d" - integrity sha1-kd8XjcN/hoQt6ihteeSPuGtarD0= - dependencies: - define-property "^0.2.5" - is-registered "^0.1.5" - isobject "^2.1.0" - -base-routes@^0.2.2: - version "0.2.2" - resolved "https://registry.yarnpkg.com/base-routes/-/base-routes-0.2.2.tgz#0a614d172d49045d8c9387713f860df3c405341e" - integrity sha1-CmFNFy1JBF2Mk4dxP4YN88QFNB4= - dependencies: - debug "^2.2.0" - en-route "^0.7.5" - is-valid-app "^0.2.0" - lazy-cache "^2.0.1" - template-error "^0.1.2" - base@^0.11.1: version "0.11.2" resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f" @@ -1261,7 +1187,7 @@ clone@^1.0.0, clone@^1.0.2: resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" integrity sha1-2jCcwmPfFZlMaIypAheco8fNfH4= -clone@^2.1.0, clone@^2.1.1: +clone@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18= @@ -1275,11 +1201,6 @@ cloneable-readable@^1.0.0: process-nextick-args "^2.0.0" readable-stream "^2.3.5" -co@^4.6.0: - version "4.6.0" - resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" - integrity sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ= - code-context@^0.5.2: version "0.5.3" resolved "https://registry.yarnpkg.com/code-context/-/code-context-0.5.3.tgz#e368c7bd247d3ac71100d91b5fd02e4e66fa9022" @@ -1650,13 +1571,6 @@ decompress-response@^3.3.0: dependencies: mimic-response "^1.0.0" -deep-bind@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/deep-bind/-/deep-bind-0.3.0.tgz#95c31dd84a1cd1b381119a2c42edb90db485bc33" - integrity sha1-lcMd2Eoc0bOBEZosQu25DbSFvDM= - dependencies: - mixin-deep "^1.1.3" - deep-equal@^1.0.1: version "1.1.1" resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.1.1.tgz#b5c98c942ceffaf7cb051e24e1434a25a2e6076a" @@ -1842,18 +1756,6 @@ en-route@^0.5.0: path-to-regexp "^1.0.3" utils-merge "^1.0.0" -en-route@^0.7.5: - version "0.7.5" - resolved "https://registry.yarnpkg.com/en-route/-/en-route-0.7.5.tgz#e8230e73836c5e95c6757e0442d3c113124bdd98" - integrity sha1-6CMOc4NsXpXGdX4EQtPBExJL3Zg= - dependencies: - arr-flatten "^1.0.1" - debug "^2.2.0" - extend-shallow "^2.0.1" - kind-of "^3.0.2" - lazy-cache "^1.0.3" - path-to-regexp "^1.2.1" - end-of-stream@^0.1.4: version "0.1.5" resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-0.1.5.tgz#8e177206c3c80837d85632e8b9359dfe8b2f6eaf" @@ -1902,18 +1804,6 @@ engine-cache@^0.12.1: extend-shallow "^1.1.4" helper-cache "^0.7.1" -engine-cache@^0.19.0: - version "0.19.4" - resolved "https://registry.yarnpkg.com/engine-cache/-/engine-cache-0.19.4.tgz#8224966fbdf6a65e780ec79df87b6b2cb82395b2" - integrity sha1-giSWb732pl54Dsed+HtrLLgjlbI= - dependencies: - async-helpers "^0.3.9" - extend-shallow "^2.0.1" - helper-cache "^0.7.2" - isobject "^3.0.0" - lazy-cache "^2.0.2" - mixin-deep "^1.1.3" - engine-handlebars@^0.8.2: version "0.8.2" resolved "https://registry.yarnpkg.com/engine-handlebars/-/engine-handlebars-0.8.2.tgz#aa709d86949d35331a15d650023d9cbe4215a9f9" @@ -1939,7 +1829,7 @@ engine-utils@^0.1.1: resolved "https://registry.yarnpkg.com/engine-utils/-/engine-utils-0.1.1.tgz#addf4708dd85a05a3217a97797eab8a013c4f80e" integrity sha1-rd9HCN2FoFoyF6l3l+q4oBPE+A4= -engine@^0.1.10, engine@^0.1.11, engine@^0.1.12, engine@^0.1.5: +engine@^0.1.10, engine@^0.1.11, engine@^0.1.12: version "0.1.12" resolved "https://registry.yarnpkg.com/engine/-/engine-0.1.12.tgz#f87e8c90bb80cd3f58597ac569593ee46da2742d" integrity sha1-+H6MkLuAzT9YWXrFaVk+5G2idC0= @@ -2732,14 +2622,6 @@ get-value@^3.0.0, get-value@^3.0.1: dependencies: isobject "^3.0.1" -get-view@^0.1.1, get-view@^0.1.3: - version "0.1.3" - resolved "https://registry.yarnpkg.com/get-view/-/get-view-0.1.3.tgz#3660ac058ba13df9749cabcaa6bcb96d41aa0ea0" - integrity sha1-NmCsBYuhPfl0nKvKpry5bUGqDqA= - dependencies: - isobject "^3.0.0" - match-file "^0.2.1" - getobject@0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/getobject/-/getobject-0.1.0.tgz#047a449789fa160d018f5486ed91320b6ec7885c" @@ -3126,18 +3008,6 @@ gray-matter@^3.0.2: kind-of "^5.0.2" strip-bom-string "^1.0.0" -group-array@^0.3.1: - version "0.3.4" - resolved "https://registry.yarnpkg.com/group-array/-/group-array-0.3.4.tgz#7ce02db67169ef2db472f1323c255ea5661b3748" - integrity sha512-YAmNsgsi1uQ7Ai3T4FFkMoskqbLEUPRajAmrn8FclwZQQnV98NLrNWjQ3n2+i1pANxdO3n6wsNEkKq5XrYy0Ow== - dependencies: - arr-flatten "^1.0.1" - for-own "^0.1.4" - get-value "^2.0.6" - kind-of "^3.1.0" - split-string "^1.0.1" - union-value "^1.0.1" - growl@1.10.5: version "1.10.5" resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" @@ -3413,7 +3283,7 @@ helper-apidocs@^0.5.1: relative "^3.0.2" template-bind-helpers "^0.2.0" -helper-cache@^0.7.0, helper-cache@^0.7.1, helper-cache@^0.7.2: +helper-cache@^0.7.0, helper-cache@^0.7.1: version "0.7.2" resolved "https://registry.yarnpkg.com/helper-cache/-/helper-cache-0.7.2.tgz#024562c4b4b8b2ab2ab531d00be16ec496518b90" integrity sha1-AkVixLS4sqsqtTHQC+FuxJZRi5A= @@ -3617,7 +3487,7 @@ imurmurhash@^0.1.4: resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= -inflection@^1.12.0, inflection@^1.7.0: +inflection@^1.7.0: version "1.13.1" resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.13.1.tgz#c5cadd80888a90cf84c2e96e340d7edc85d5f0cb" integrity sha512-dldYtl2WlN0QDkIDtg8+xFwOS2Tbmp12t1cHa5/YClU6ZQjTFm7B66UcVbh9NQB+HvT5BAd2t5+yKsBkw5pcqA== @@ -3695,7 +3565,7 @@ is-accessor-descriptor@^1.0.0: dependencies: kind-of "^6.0.0" -is-arguments@^1.0.2, is-arguments@^1.0.4: +is-arguments@^1.0.4: version "1.1.0" resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.1.0.tgz#62353031dfbee07ceb34656a6bde59efecae8dd9" integrity sha512-1Ij4lOMPl/xB5kBDn7I+b2ttPMKa8szhEIrXDuXQD/oe3HJLTLhqhgGspwgyGd6MOywBUqVvYicF72lkgDnIHg== @@ -4027,16 +3897,6 @@ is-utf8@^0.2.0, is-utf8@^0.2.1: resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" integrity sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI= -is-valid-app@^0.1.2: - version "0.1.2" - resolved "https://registry.yarnpkg.com/is-valid-app/-/is-valid-app-0.1.2.tgz#2f67cbb3baf64d659c70d043fc91139b5a8b9590" - integrity sha1-L2fLs7r2TWWccNBD/JETm1qLlZA= - dependencies: - debug "^2.2.0" - is-registered "^0.1.5" - is-valid-instance "^0.1.0" - lazy-cache "^2.0.1" - is-valid-app@^0.2.0, is-valid-app@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/is-valid-app/-/is-valid-app-0.2.1.tgz#65cf195bbd71bd776cb161991c684248d65dff89" @@ -4067,14 +3927,6 @@ is-valid-glob@^1.0.0: resolved "https://registry.yarnpkg.com/is-valid-glob/-/is-valid-glob-1.0.0.tgz#29bf3eff701be2d4d315dbacc39bc39fe8f601aa" integrity sha1-Kb8+/3Ab4tTTFdusw5vDn+j2Aao= -is-valid-instance@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/is-valid-instance/-/is-valid-instance-0.1.0.tgz#7ad5c6a3886dfdf7d9cc78049ceff2171a9907b3" - integrity sha1-etXGo4ht/ffZzHgEnO/yFxqZB7M= - dependencies: - isobject "^2.1.0" - pascalcase "^0.1.1" - is-valid-instance@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/is-valid-instance/-/is-valid-instance-0.2.0.tgz#e1a9ff1106b8cbae0007ea6a20f89d546a2a5a0f" @@ -4244,7 +4096,7 @@ kind-of@^2.0.0, kind-of@^2.0.1: dependencies: is-buffer "^1.0.2" -kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.0.4, kind-of@^3.1.0, kind-of@^3.2.0, kind-of@^3.2.2: +kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.0.4, kind-of@^3.1.0, kind-of@^3.2.0: version "3.2.2" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" integrity sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ= @@ -4276,16 +4128,6 @@ last-run@^1.1.0: default-resolution "^2.0.0" es6-weak-map "^2.0.1" -layouts@^0.12.1: - version "0.12.1" - resolved "https://registry.yarnpkg.com/layouts/-/layouts-0.12.1.tgz#6b99b3f1aa53e5e78c90ec75d4f491a6e0f57043" - integrity sha1-a5mz8apT5eeMkOx11PSRpuD1cEM= - dependencies: - delimiter-regex "^1.3.1" - "falsey" "^0.3.0" - get-view "^0.1.1" - lazy-cache "^2.0.1" - layouts@^0.9.0: version "0.9.0" resolved "https://registry.yarnpkg.com/layouts/-/layouts-0.9.0.tgz#29ced985f16a0131581ea10ddff1aa019453ae09" @@ -4412,18 +4254,6 @@ list-item@^1.1.1: is-number "^2.1.0" repeat-string "^1.5.2" -load-helpers@^0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/load-helpers/-/load-helpers-0.3.1.tgz#99a8ba07362901827c8e62c95b0b0b1fe9830549" - integrity sha1-mai6BzYpAYJ8jmLJWwsLH+mDBUk= - dependencies: - component-emitter "^1.2.1" - extend-shallow "^2.0.1" - is-valid-glob "^0.3.0" - lazy-cache "^2.0.1" - matched "^0.4.3" - resolve-dir "^0.1.0" - load-json-file@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0" @@ -4942,15 +4772,6 @@ markdown-utils@^0.7.0, markdown-utils@^0.7.1, markdown-utils@^0.7.3: list-item "^1.1.1" to-gfm-code-block "^0.1.1" -match-file@^0.2.1: - version "0.2.2" - resolved "https://registry.yarnpkg.com/match-file/-/match-file-0.2.2.tgz#26e6bcf1b390a661f6126faf8ac501e33eccfae9" - integrity sha1-Jua88bOQpmH2Em+visUB4z7M+uk= - dependencies: - is-glob "^3.1.0" - isobject "^3.0.0" - micromatch "^2.3.11" - match-file@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/match-file/-/match-file-1.0.0.tgz#3496169751607b22f91a0153f879ce6deae9a968" @@ -4970,7 +4791,7 @@ matchdep@^2.0.0: resolve "^1.4.0" stack-trace "0.0.10" -matched@^0.4.1, matched@^0.4.3, matched@^0.4.4: +matched@^0.4.1, matched@^0.4.4: version "0.4.4" resolved "https://registry.yarnpkg.com/matched/-/matched-0.4.4.tgz#56d7b7eb18033f0cf9bc52eb2090fac7dc1e89fa" integrity sha1-Vte36xgDPwz5vFLrIJD6x9weifo= @@ -5027,7 +4848,7 @@ merge-value@^1.0.0: mixin-deep "^1.2.0" set-value "^2.0.0" -micromatch@^2.1.0, micromatch@^2.1.5, micromatch@^2.2.0, micromatch@^2.3.11, micromatch@^2.3.7, micromatch@^2.3.8: +micromatch@^2.1.0, micromatch@^2.1.5, micromatch@^2.2.0, micromatch@^2.3.7, micromatch@^2.3.8: version "2.3.11" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" integrity sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU= @@ -5566,21 +5387,6 @@ option-cache@^1.3.0, option-cache@^1.4.0: set-value "^0.2.0" to-flags "^0.1.0" -option-cache@^3.4.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/option-cache/-/option-cache-3.5.0.tgz#cb765155ba2a861c1109ff26e2a20eaa06612b2b" - integrity sha1-y3ZRVboqhhwRCf8m4qIOqgZhKys= - dependencies: - arr-flatten "^1.0.3" - collection-visit "^1.0.0" - component-emitter "^1.2.1" - get-value "^2.0.6" - has-value "^0.3.1" - kind-of "^3.2.2" - lazy-cache "^2.0.2" - set-value "^0.4.3" - to-object-path "^0.3.0" - optionator@^0.9.3: version "0.9.4" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.4.tgz#7ea1c1a5d91d764fb282139c88fe11e182a3a734" @@ -5657,11 +5463,6 @@ pad-right@^0.2.2: dependencies: repeat-string "^1.5.2" -paginationator@^0.1.4: - version "0.1.4" - resolved "https://registry.yarnpkg.com/paginationator/-/paginationator-0.1.4.tgz#84786dd3850aae1f11bbb911b0c1e0851b538106" - integrity sha1-hHht04UKrh8Ru7kRsMHghRtTgQY= - parent-module@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2" @@ -5868,7 +5669,7 @@ path-root@^0.1.1: dependencies: path-root-regex "^0.1.0" -path-to-regexp@^1.0.3, path-to-regexp@^1.2.1: +path-to-regexp@^1.0.3: version "1.8.0" resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.8.0.tgz#887b3ba9d84393e87a0a0b9f4cb756198b53548a" integrity sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA== @@ -6400,18 +6201,6 @@ rethrow@^0.1.0: resolved "https://registry.yarnpkg.com/rethrow/-/rethrow-0.1.0.tgz#7364b1ef6862696882594a88b66d5af8cfaf5e58" integrity sha1-c2Sx72hiaWiCWUqItm1a+M+vXlg= -rethrow@^0.2.3: - version "0.2.3" - resolved "https://registry.yarnpkg.com/rethrow/-/rethrow-0.2.3.tgz#c5528f190e89ec7535889452a1be68996b5f6616" - integrity sha1-xVKPGQ6J7HU1iJRSob5omWtfZhY= - dependencies: - ansi-bgred "^0.1.1" - ansi-red "^0.1.1" - ansi-yellow "^0.1.1" - extend-shallow "^1.1.4" - lazy-cache "^0.2.3" - right-align "^0.1.3" - reusify@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" @@ -6554,15 +6343,6 @@ set-value@^0.2.0: isobject "^1.0.0" noncharacters "^1.1.0" -set-value@^0.3.3: - version "0.3.3" - resolved "https://registry.yarnpkg.com/set-value/-/set-value-0.3.3.tgz#b81223681638a1088fd88a435b8a9d32dae8d9ba" - integrity sha1-uBIjaBY4oQiP2IpDW4qdMtro2bo= - dependencies: - extend-shallow "^2.0.1" - isobject "^2.0.0" - to-object-path "^0.2.0" - set-value@^0.4.0, set-value@^0.4.3: version "0.4.3" resolved "https://registry.yarnpkg.com/set-value/-/set-value-0.4.3.tgz#7db08f9d3d22dc7f78e53af3c3bf4666ecdfccf1" @@ -6776,13 +6556,6 @@ spdx-license-ids@^3.0.0: resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.9.tgz#8a595135def9592bda69709474f1cbeea7c2467f" integrity sha512-Ki212dKK4ogX+xDo4CtOZBVIwhsKBEfsEEcwmJfLQzirgc2jIWdzg40Unxz/HzEUqM1WFzVlQSMF9kZZ2HboLQ== -split-string@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/split-string/-/split-string-1.0.1.tgz#bcbab3f4152acee3a0d6ab2479c0d2879c3db3ce" - integrity sha1-vLqz9BUqzuOg1qskecDSh5w9s84= - dependencies: - extend-shallow "^2.0.1" - split-string@^3.0.1, split-string@^3.0.2: version "3.1.0" resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2" @@ -7029,16 +6802,6 @@ template-bind-helpers@^0.2.0: dependencies: isobject "^2.0.0" -template-error@^0.1.2: - version "0.1.2" - resolved "https://registry.yarnpkg.com/template-error/-/template-error-0.1.2.tgz#18c9f600d90f2f3dfba0833e37f7cb6f413542d4" - integrity sha1-GMn2ANkPLz37oIM+N/fLb0E1QtQ= - dependencies: - engine "^0.1.5" - kind-of "^2.0.1" - lazy-cache "^0.2.3" - rethrow "^0.2.3" - template-helper-apidocs@^0.4.4: version "0.4.4" resolved "https://registry.yarnpkg.com/template-helper-apidocs/-/template-helper-apidocs-0.4.4.tgz#8f558ff973b9496bc89feefa124b43e5aa4b7448" @@ -7181,45 +6944,6 @@ template@^0.14.3: relative "^3.0.0" template-utils "^0.6.2" -templates@^1.2.9: - version "1.2.9" - resolved "https://registry.yarnpkg.com/templates/-/templates-1.2.9.tgz#d8b0de71d69331af755cb09533b4ecc2da649801" - integrity sha1-2LDecdaTMa91XLCVM7TswtpkmAE= - dependencies: - array-sort "^0.1.2" - async-each "^1.0.1" - base "^0.11.1" - base-data "^0.6.0" - base-engines "^0.2.0" - base-helpers "^0.2.0" - base-option "^0.8.4" - base-plugins "^0.4.13" - base-routes "^0.2.2" - debug "^2.6.0" - deep-bind "^0.3.0" - define-property "^0.2.5" - engine-base "^0.1.2" - export-files "^2.1.1" - extend-shallow "^2.0.1" - "falsey" "^0.3.0" - get-value "^2.0.6" - get-view "^0.1.3" - group-array "^0.3.1" - has-glob "^1.0.0" - has-value "^0.3.1" - inflection "^1.12.0" - is-valid-app "^0.2.1" - layouts "^0.12.1" - lazy-cache "^2.0.2" - match-file "^0.2.1" - mixin-deep "^1.1.3" - paginationator "^0.1.4" - pascalcase "^0.1.1" - set-value "^0.4.0" - template-error "^0.1.2" - vinyl-item "^1.0.0" - vinyl-view "^2.0.0" - text-table@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" @@ -7311,14 +7035,6 @@ to-gfm-code-block@^0.1.1: resolved "https://registry.yarnpkg.com/to-gfm-code-block/-/to-gfm-code-block-0.1.1.tgz#25d045a5fae553189e9637b590900da732d8aa82" integrity sha1-JdBFpfrlUxielje1kJANpzLYqoI= -to-object-path@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.2.0.tgz#1634e1b52a88ba00e3949619fc0081dc9a3b07ca" - integrity sha1-FjThtSqIugDjlJYZ/ACB3Jo7B8o= - dependencies: - arr-flatten "^1.0.1" - is-arguments "^1.0.2" - to-object-path@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af" @@ -7481,7 +7197,7 @@ union-value@^0.2.3: is-extendable "^0.1.1" set-value "^0.4.3" -union-value@^1.0.0, union-value@^1.0.1: +union-value@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847" integrity sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg== @@ -7891,22 +7607,6 @@ vinyl-fs@^3.0.0: vinyl "^2.0.0" vinyl-sourcemap "^1.1.0" -vinyl-item@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/vinyl-item/-/vinyl-item-1.0.0.tgz#e4188fab795154de9e74588eaad3df4ba5151692" - integrity sha1-5BiPq3lRVN6edFiOqtPfS6UVFpI= - dependencies: - base "^0.11.1" - base-option "^0.8.4" - base-plugins "^0.4.13" - clone "^2.1.0" - clone-stats "^1.0.0" - define-property "^0.2.5" - extend-shallow "^2.0.1" - isobject "^3.0.0" - lazy-cache "^2.0.2" - vinyl "^2.0.1" - vinyl-sourcemap@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/vinyl-sourcemap/-/vinyl-sourcemap-1.1.0.tgz#92a800593a38703a8cdb11d8b300ad4be63b3e16" @@ -7920,19 +7620,6 @@ vinyl-sourcemap@^1.1.0: remove-bom-buffer "^3.0.0" vinyl "^2.0.0" -vinyl-view@^2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/vinyl-view/-/vinyl-view-2.0.1.tgz#46a4d99fa8688bf37912868f912665a15b66816a" - integrity sha1-RqTZn6hoi/N5EoaPkSZloVtmgWo= - dependencies: - arr-union "^3.1.0" - define-property "^0.2.5" - engine-base "^0.1.2" - extend-shallow "^2.0.1" - isobject "^3.0.0" - lazy-cache "^2.0.2" - vinyl-item "^1.0.0" - vinyl@^0.4.0, vinyl@^0.4.6: version "0.4.6" resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-0.4.6.tgz#2f356c87a550a255461f36bbeb2a5ba8bf784847" From 4406a2748e8631a784c0e7afe7682a5caa9e6b45 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 13:42:35 +0100 Subject: [PATCH 13/46] Update lib/index --- index.mjs | 2 +- lib/index.js | 24 ------------------------ lib/index.mjs | 39 +++++++++++++++++++++++++++++++++++++++ test/examples/index.mjs | 2 +- 4 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 lib/index.js create mode 100644 lib/index.mjs diff --git a/index.mjs b/index.mjs index dfdb499d..14df218d 100644 --- a/index.mjs +++ b/index.mjs @@ -7,7 +7,7 @@ 'use strict'; -import lib from './lib/index.js'; +import lib from './lib/index.mjs'; // TODO: import only when required import Handlebars from 'handlebars'; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f5ab2e30..00000000 --- a/lib/index.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -module.exports = { - array: require('./array'), - code: require('./code'), - collection: require('./collection'), - comparison: require('./comparison'), - //date: require('./date'), - //fs: require('./fs'), - html: require('./html'), - i18n: require('./i18n'), - inflection: require('./inflection'), - //markdown: require('./markdown'), - match: require('./match'), - math: require('./math'), - misc: require('./misc'), - number: require('./number'), - object: require('./object'), - path: require('./path'), - regex: require('./regex'), - string: require('./string'), - url: require('./url'), - uuid: require('./uuid') -}; diff --git a/lib/index.mjs b/lib/index.mjs new file mode 100644 index 00000000..758676e2 --- /dev/null +++ b/lib/index.mjs @@ -0,0 +1,39 @@ +'use strict'; + +import array from './array.js'; +import code from './code.js'; +import collection from './collection.js'; +import comparison from './comparison.js'; +import html from './html.js'; +import i18n from './i18n.js'; +import inflection from './inflection.js'; +import match from './match.js'; +import math from './math.js'; +import misc from './misc.js'; +import number from './number.js'; +import object from './object.js'; +import path from './path.js'; +import regex from './regex.js'; +import string from './string.js'; +import url from './url.js'; +import uuid from './uuid.js'; + +export default { + array, + code, + collection, + comparison, + html, + i18n, + inflection, + match, + math, + misc, + number, + object, + path, + regex, + string, + url, + uuid +}; diff --git a/test/examples/index.mjs b/test/examples/index.mjs index e98133de..cd3f0074 100644 --- a/test/examples/index.mjs +++ b/test/examples/index.mjs @@ -12,7 +12,7 @@ stub(uuid, 'uuid').returns('f34ebc66-93bd-4f7c-b79b-92b5569138bc'); stub(math, 'random').returns(10); import { equal } from 'assert'; -import lib from '../../lib/index.js'; +import lib from '../../lib/index.mjs'; import { readFileSync } from 'fs'; import { parse } from 'doctrine'; From d0d041b21811ea8a4083a50a13044fc3f815e01e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 14:04:36 +0100 Subject: [PATCH 14/46] Convert uuid --- lib/index.mjs | 4 ++-- lib/{uuid.js => uuid.mjs} | 6 +++--- test/examples/index.mjs | 15 ++++++++++----- test/uuid.mjs | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) rename lib/{uuid.js => uuid.mjs} (73%) diff --git a/lib/index.mjs b/lib/index.mjs index 758676e2..78d886df 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -16,7 +16,7 @@ import path from './path.js'; import regex from './regex.js'; import string from './string.js'; import url from './url.js'; -import uuid from './uuid.js'; +import * as uuid from './uuid.mjs'; export default { array, @@ -35,5 +35,5 @@ export default { regex, string, url, - uuid + ...uuid }; diff --git a/lib/uuid.js b/lib/uuid.mjs similarity index 73% rename from lib/uuid.js rename to lib/uuid.mjs index be8d67cb..54424645 100644 --- a/lib/uuid.js +++ b/lib/uuid.mjs @@ -1,4 +1,4 @@ -const uuid = require('uuid'); +import {v4} from 'uuid'; /** * Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function). @@ -7,6 +7,6 @@ const uuid = require('uuid'); * @api public * @example {{ uuid }} -> f34ebc66-93bd-4f7c-b79b-92b5569138bc */ -module.exports.uuid = function() { - return uuid.v4(); +export const uuid = function() { + return v4(); }; diff --git a/test/examples/index.mjs b/test/examples/index.mjs index cd3f0074..2a11a35f 100644 --- a/test/examples/index.mjs +++ b/test/examples/index.mjs @@ -4,17 +4,17 @@ import 'mocha'; import { restore, stub } from 'sinon'; -import uuid from '../../lib/uuid.js'; +import {uuid} from '../../lib/uuid.mjs'; import math from '../../lib/math.js'; -restore(); -stub(uuid, 'uuid').returns('f34ebc66-93bd-4f7c-b79b-92b5569138bc'); +restore(); +stub({uuid}, 'uuid').returns('f34ebc66-93bd-4f7c-b79b-92b5569138bc'); stub(math, 'random').returns(10); import { equal } from 'assert'; import lib from '../../lib/index.mjs'; -import { readFileSync } from 'fs'; +import { readFileSync, existsSync } from 'fs'; import { parse } from 'doctrine'; import { join } from 'path'; @@ -89,7 +89,12 @@ describe('examples', function() { const group = lib[key]; - const fileContent = readFileSync(join('./lib/', `${key}.js`), 'utf8'); + let file = join('./lib/', `${key}.js`); + if (!existsSync(file)) { + file = join('./lib/', `${key}.mjs`); + + } + const fileContent = readFileSync(file, 'utf8'); describe(key, function() { for (const func in group) { diff --git a/test/uuid.mjs b/test/uuid.mjs index a0868c9e..f469e668 100644 --- a/test/uuid.mjs +++ b/test/uuid.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { match } from 'assert'; -import { uuid } from '../lib/uuid.js'; +import { uuid } from '../lib/uuid.mjs'; describe('uuid', function() { describe('generate', function() { From 8623487a1ac459cc433278bc0dd24cebeec6a7b1 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 16:54:45 +0100 Subject: [PATCH 15/46] More migrations --- index.mjs | 6 +- lib/{array.js => array.mjs} | 152 +++++++++++++------------- lib/{collection.js => collection.mjs} | 29 +++-- lib/index.mjs | 10 +- lib/{object.js => object.mjs} | 80 +++++++------- lib/{string.js => string.mjs} | 102 ++++++++--------- test/array.mjs | 2 +- test/examples/index.mjs | 1 + 8 files changed, 190 insertions(+), 192 deletions(-) rename lib/{array.js => array.mjs} (91%) rename lib/{collection.js => collection.mjs} (71%) rename lib/{object.js => object.mjs} (82%) rename lib/{string.js => string.mjs} (89%) diff --git a/index.mjs b/index.mjs index 14df218d..9f8204b5 100644 --- a/index.mjs +++ b/index.mjs @@ -28,12 +28,12 @@ export default function helpers(groups, options) { if (groups) { groups.forEach(function(key) { - hbs.registerHelper(lib[key]); + hbs.registerHelper({...lib[key]}); }); } else { for (const key in lib) { const group = lib[key]; - hbs.registerHelper(group); + hbs.registerHelper({...group}); } } @@ -47,7 +47,7 @@ function exportGroup(group) { return function(options) { options = options || {}; var hbs = options.handlebars || options.hbs || Handlebars; - hbs.registerHelper(group); + hbs.registerHelper({...group}); return group; }; }; diff --git a/lib/array.js b/lib/array.mjs similarity index 91% rename from lib/array.js rename to lib/array.mjs index db4b1556..c1d2c040 100644 --- a/lib/array.js +++ b/lib/array.mjs @@ -1,17 +1,24 @@ 'use strict'; -var util = { - isUndefined: require('./utils/isUndefined'), - result: require('./utils/result'), - value: require('./utils/value'), - indexOf: require('./utils/indexOf'), - isString: require('./utils/isString'), - isOptions: require('./utils/isOptions'), - isObject: require('./utils/isObject') +import isUndefined from './utils/isUndefined.js'; +import result from './utils/result.js'; +import value from './utils/value.js'; +import indexOf from './utils/indexOf.js'; +import isString from './utils/isString.js'; +import isOptions from './utils/isOptions.js'; +import isObject from './utils/isObject.js'; + +const util = { + isUndefined, + result, + value, + indexOf, + isString, + isOptions, + isObject }; -var helpers = module.exports; -const getValue = require('get-value'); -const createFrame = require('./utils/createFrame'); +import getValue from 'get-value'; +import createFrame from './utils/createFrame.js'; /** * Returns all of the items in an array after the specified index. @@ -29,14 +36,14 @@ const createFrame = require('./utils/createFrame'); * @example {{ after ['a', 'b', 'c', 'd'] 2}} -> ['c', 'd'] */ -helpers.after = function(array, n) { +export function after(array, n) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { return array.slice(n); } return ''; -}; +} /** * Cast the given `value` to an array. @@ -51,10 +58,10 @@ helpers.after = function(array, n) { * @example {{ arrayify 'foo' }} -> ['foo'] */ -helpers.arrayify = function(value) { +export function arrayify(value) { if (util.isUndefined(value)) return []; return value ? (Array.isArray(value) ? value : [value]) : []; -}; +} /** * Return all of the items in the collection before the specified @@ -72,14 +79,14 @@ helpers.arrayify = function(value) { * @example {{ before ['a', 'b', 'c', 'd'] 3}} -> ['a', 'b'] */ -helpers.before = function(array, n) { +export function before(array, n) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { return array.slice(0, n - 1); } return ''; -}; +} /** * ```handlebars @@ -96,7 +103,7 @@ helpers.before = function(array, n) { * @example {{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}} -> ' 1 is 0 2 is 1 3 is 2 ' */ -helpers.eachIndex = function(array, options) { +export function eachIndex(array, options) { var result = ''; if (util.isUndefined(array)) return ''; array = util.result(array); @@ -106,7 +113,7 @@ helpers.eachIndex = function(array, options) { } } return result; -}; +} /** * Block helper that filters the given array and renders the block for values that @@ -126,7 +133,7 @@ helpers.eachIndex = function(array, options) { * @example {{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}} -> 2 Found */ -helpers.filter = function(array, value, options) { +export function filter(array, value, options) { if (util.isUndefined(array)) return options.inverse(this); array = util.result(array); if (Array.isArray(array)) { @@ -154,7 +161,7 @@ helpers.filter = function(array, value, options) { } } return options.inverse(this); -}; +} /** * Returns the first item, or first `n` items of an array. @@ -170,7 +177,7 @@ helpers.filter = function(array, value, options) { * @example {{first [1, 2, 3, 4] 2}} -> 1,2 */ -helpers.first = function(array, n) { +export function first(array, n) { if (util.isUndefined(array)) return []; array = util.result(array); if (Array.isArray(array)) { @@ -180,7 +187,7 @@ helpers.first = function(array, n) { return array.slice(0, n); } return []; -}; +} /** * Iterates over each item in an array and exposes the current item @@ -218,7 +225,7 @@ helpers.first = function(array, n) { * @example {{#forEach [{ 'name': 'John' }] }} {{ name }} {{/forEach}} -> ' John ' */ -helpers.forEach = function(array, options) { +export function forEach(array, options) { if (util.isUndefined(array)) return options.inverse(this); array = util.result(array); if (Array.isArray(array)) { @@ -239,7 +246,7 @@ helpers.forEach = function(array, options) { return buffer; } return options.inverse(this); -}; +} /** * Block helper that renders the block if an array has the @@ -264,14 +271,14 @@ helpers.forEach = function(array, options) { * @example {{#inArray [1, 2, 3] 2}} 2 exists {{else}} 2 does not exist {{/inArray}} -> ' 2 exists ' */ -helpers.inArray = function(array, value, options) { +export function inArray(array, value, options) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { return util.value(util.indexOf(array, value) > -1, this, options); } return ''; -}; +} /** * Returns true if `value` is an es5 array. @@ -290,9 +297,9 @@ helpers.inArray = function(array, value, options) { * @example {{isArray [1, 2]}} -> true */ -helpers.isArray = function(value) { +export function isArray(value) { return Array.isArray(value); -}; +} /** * Returns the item from `array` at index `idx`. @@ -309,7 +316,7 @@ helpers.isArray = function(value) { * @example {{itemAt [1, 2, 3] 1}} -> 2 */ -helpers.itemAt = function(array, idx) { +export function itemAt(array, idx) { if (util.isUndefined(array)) return null; array = util.result(array); if (Array.isArray(array)) { @@ -322,7 +329,7 @@ helpers.itemAt = function(array, idx) { } } return null; -}; +} /** * Join all elements of array into a string, optionally using a @@ -343,7 +350,7 @@ helpers.itemAt = function(array, idx) { * @example {{join [1, 2, 3]}} -> 1, 2, 3 */ -helpers.join = function(array, separator) { +export function join(array, separator) { if (util.isUndefined(array)) return ''; if (typeof array === 'string') return array; array = util.result(array); @@ -352,7 +359,7 @@ helpers.join = function(array, separator) { return array.join(separator); } return ''; -}; +} /** * Returns true if the the length of the given `value` is equal @@ -367,16 +374,16 @@ helpers.join = function(array, separator) { * @example {{equalsLength [1, 2, 3] 3}} -> true */ -helpers.equalsLength = function(value, length, options) { +export function equalsLength(value, length, options) { if (util.isOptions(length)) { options = length; length = 0; } - var len = helpers.length(value); + var len = _length(value); return util.value(len === length, this, options); -}; +} /** * Returns the last item, or last `n` items of an array or string. @@ -401,7 +408,7 @@ helpers.equalsLength = function(value, length, options) { * @example {{last [1, 2, 3]}} -> 3 */ -helpers.last = function(array, n) { +export function last(array, n) { if (util.isUndefined(array)) return ''; if (!Array.isArray(array) && typeof value !== 'string') { return ''; @@ -410,7 +417,7 @@ helpers.last = function(array, n) { return array[array.length - 1]; } return array.slice(-Math.abs(n)); -}; +} /** * Returns the length of the given string or array. @@ -433,17 +440,15 @@ helpers.last = function(array, n) { * @example {{length [1, 2, 3]}} -> 3 */ -helpers.length = function(array) { +const _length = function(array) { if (util.isUndefined(array)) return 0; if (util.isObject(array) && !util.isOptions(array)) { array = Object.keys(array); } // this is an inline array, split it - if ( - typeof array === 'string' && + if (typeof array === 'string' && array.startsWith('[') && - array.endsWith(']') - ) { + array.endsWith(']')) { return array.split(',').length; } if (typeof array === 'string' || Array.isArray(array)) { @@ -451,14 +456,9 @@ helpers.length = function(array) { } return 0; }; +export { _length as length }; -/** - * Alias for [equalsLength](#equalsLength) - * - * @api public - */ - -helpers.lengthEqual = helpers.equalsLength; +export const lengthEqual = equalsLength; /** * Returns a new array, created by calling `function` on each @@ -478,7 +478,7 @@ helpers.lengthEqual = helpers.equalsLength; * @example {{map [1, 2, 3] double}} -> [2, 4, 6] */ -helpers.map = function(array, iter) { +export function map(array, iter) { if (util.isUndefined(array)) return ''; if (!Array.isArray(array)) return ''; var len = array.length; @@ -493,7 +493,7 @@ helpers.map = function(array, iter) { res[i] = iter(array[i], i, array); } return res; -}; +} /** * Map over the given object or array or objects and create an array of values @@ -511,7 +511,7 @@ helpers.map = function(array, iter) { * @example {{pluck [{ 'name': 'Bob' }] 'name' }} -> ['Bob'] */ -helpers.pluck = function(array, prop) { +export function pluck(array, prop) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -525,7 +525,7 @@ helpers.pluck = function(array, prop) { return res; } return ''; -}; +} /** * Reverse the elements in an array, or the characters in a string. @@ -543,7 +543,7 @@ helpers.pluck = function(array, prop) { * @api public * @example {{reverse [1, 2, 3]}} -> [3, 2, 1] */ -helpers.reverse = function(array) { +export function reverse(array) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -553,7 +553,7 @@ helpers.reverse = function(array) { return array.split('').reverse().join(''); } return ''; -}; +} /** * Block helper that returns the block if the callback returns true @@ -577,7 +577,7 @@ helpers.reverse = function(array) { * @example {{#some [1, "b", 3] isString}} string found {{else}} No string found {{/some}} -> ' string found ' */ -helpers.some = function(array, iter, options) { +export function some(array, iter, options) { if (util.isUndefined(array)) return options.inverse(this); array = util.result(array); if (Array.isArray(array)) { @@ -588,7 +588,7 @@ helpers.some = function(array, iter, options) { } } return options.inverse(this); -}; +} /** * Sort the given `array`. If an array of objects is passed, @@ -608,7 +608,7 @@ helpers.some = function(array, iter, options) { * @example {{ sort ['b', 'a', 'c'] }} -> ['a', 'b', 'c'] */ -helpers.sort = function(array, options) { +export function sort(array, options) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -618,7 +618,7 @@ helpers.sort = function(array, options) { return [...array].sort(); } return ''; -}; +} /** * Sort an `array`. If an array of objects is passed, @@ -638,7 +638,7 @@ helpers.sort = function(array, options) { * @example {{ sortBy [{'a': 'zzz'}, {'a': 'aaa'}] 'a' }} -> [{'a':'aaa'},{'a':'zzz'}] */ -helpers.sortBy = function(array, prop, options) { +export function sortBy(array, prop, options) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -657,7 +657,7 @@ helpers.sortBy = function(array, prop, options) { return [...array].sort((a, b) => (a[prop] > b[prop] ? 1 : -1)); } return ''; -}; +} /** * Use the items in the array _after_ the specified index @@ -679,7 +679,7 @@ helpers.sortBy = function(array, prop, options) { * @example {{#withAfter [1, 2, 3] 1 }} {{this}} {{/withAfter}} -> ' 2 3 ' */ -helpers.withAfter = function(array, idx, options) { +export function withAfter(array, idx, options) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -692,7 +692,7 @@ helpers.withAfter = function(array, idx, options) { return result; } return ''; -}; +} /** * Use the items in the array _before_ the specified index @@ -714,7 +714,7 @@ helpers.withAfter = function(array, idx, options) { * @example {{#withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}} -> ' 1 ' */ -helpers.withBefore = function(array, idx, options) { +export function withBefore(array, idx, options) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -727,7 +727,7 @@ helpers.withBefore = function(array, idx, options) { return result; } return ''; -}; +} /** * Use the first item in a collection inside a handlebars @@ -749,7 +749,7 @@ helpers.withBefore = function(array, idx, options) { * @example {{#withFirst [1, 2, 3] }}{{this}}{{/withFirst}} -> 1 */ -helpers.withFirst = function(array, idx, options) { +export function withFirst(array, idx, options) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -770,7 +770,7 @@ helpers.withFirst = function(array, idx, options) { return result; } return ''; -}; +} /** * Block helper that groups array elements by given group `size`. @@ -796,7 +796,7 @@ helpers.withFirst = function(array, idx, options) { * @example {{#withGroup [1, 2, 3, 4] 2}}{{#each this}}{{.}}{{/each}}
{{/withGroup}} -> 12
34
* */ -helpers.withGroup = function(array, size, options) { +export function withGroup(array, size, options) { if (util.isUndefined(array)) return ''; var result = ''; array = util.result(array); @@ -812,7 +812,7 @@ helpers.withGroup = function(array, size, options) { result += options.fn(subcontext); } return result; -}; +} /** * Use the last item or `n` items in an array as context inside a block. @@ -833,7 +833,7 @@ helpers.withGroup = function(array, size, options) { * @example {{#withLast [1, 2, 3, 4]}}{{this}}{{/withLast}} -> 4 */ -helpers.withLast = function(array, idx, options) { +export function withLast(array, idx, options) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -856,7 +856,7 @@ helpers.withLast = function(array, idx, options) { return result; } return ''; -}; +} /** * Block helper that sorts a collection and exposes the sorted @@ -876,7 +876,7 @@ helpers.withLast = function(array, idx, options) { * @example {{#withSort ['b', 'a', 'c']}}{{this}}{{/withSort}} -> abc */ -helpers.withSort = function(array, prop, options) { +export function withSort(array, prop, options) { if (util.isUndefined(array)) return ''; array = util.result(array); if (Array.isArray(array)) { @@ -914,7 +914,7 @@ helpers.withSort = function(array, prop, options) { return result; } return ''; -}; +} /** * Block helper that return an array with all duplicate @@ -933,7 +933,7 @@ helpers.withSort = function(array, prop, options) { * @example {{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }}{{.}}{{/each}} -> acbe */ -helpers.unique = function(array, options) { +export function unique(array, options) { if (util.isUndefined(array)) return ''; array = util.result(array); @@ -943,4 +943,4 @@ helpers.unique = function(array, options) { }); } return ''; -}; +} diff --git a/lib/collection.js b/lib/collection.mjs similarity index 71% rename from lib/collection.js rename to lib/collection.mjs index 6cb87f1d..3b11fd38 100644 --- a/lib/collection.js +++ b/lib/collection.mjs @@ -1,11 +1,10 @@ 'use strict'; -var util = require('./utils/handlebarsUtils'); -var object = require('./object'); -var array = require('./array'); -var forEach = array.forEach; -var forOwn = object.forOwn; -var helpers = module.exports; +import handlebarsUtils from './utils/handlebarsUtils.js'; +import { forOwn } from './object.mjs'; +import { forEach } from './array.mjs'; + +const { isOptions, fn, value, isObject } = handlebarsUtils; /** * Inline, subexpression, or block helper that returns true (or the block) @@ -28,20 +27,20 @@ var helpers = module.exports; * @api public */ -helpers.isEmpty = function(collection, options) { - if (!util.isOptions(options)) { +export function isEmpty(collection, options) { + if (!isOptions(options)) { options = collection; - return util.fn(true, this, options); + return fn(true, this, options); } if (Array.isArray(collection) && !collection.length) { - return util.fn(true, this, options); + return fn(true, this, options); } var keys = Object.keys(collection); var isEmpty = typeof collection === 'object' && !keys.length; - return util.value(isEmpty, this, options); -}; + return value(isEmpty, this, options); +} /** * Block helper that iterates over an array or object. If @@ -56,12 +55,12 @@ helpers.isEmpty = function(collection, options) { * @api public */ -helpers.iterate = function(collection, options) { +export function iterate(collection, options) { if (Array.isArray(collection)) { return forEach.apply(null, arguments); } - if (util.isObject(collection)) { + if (isObject(collection)) { return forOwn.apply(null, arguments); } return options.inverse(this); -}; +} diff --git a/lib/index.mjs b/lib/index.mjs index 78d886df..63c4f54c 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -1,8 +1,8 @@ 'use strict'; -import array from './array.js'; +import * as array from './array.mjs'; import code from './code.js'; -import collection from './collection.js'; +import * as collection from './collection.mjs'; import comparison from './comparison.js'; import html from './html.js'; import i18n from './i18n.js'; @@ -11,10 +11,10 @@ import match from './match.js'; import math from './math.js'; import misc from './misc.js'; import number from './number.js'; -import object from './object.js'; +import * as object from './object.mjs'; import path from './path.js'; import regex from './regex.js'; -import string from './string.js'; +import * as string from './string.mjs'; import url from './url.js'; import * as uuid from './uuid.mjs'; @@ -35,5 +35,5 @@ export default { regex, string, url, - ...uuid + uuid }; diff --git a/lib/object.js b/lib/object.mjs similarity index 82% rename from lib/object.js rename to lib/object.mjs index 3cd17757..f1dba2ae 100644 --- a/lib/object.js +++ b/lib/object.mjs @@ -1,15 +1,18 @@ 'use strict'; var hasOwn = Object.hasOwnProperty; + +import isOptions from './utils/isOptions.js'; +import isObject from './utils/isObject.js'; var util = { - isOptions: require('./utils/isOptions'), - isObject: require('./utils/isObject') + isOptions, + isObject }; -var array = require('./array'); -var helpers = module.exports; -const getValue = require('get-value'); -const getObject = require('get-object'); -const createFrame = require('./utils/createFrame'); +import { arrayify } from './array.mjs'; + +import getValue from 'get-value'; +import getObject from 'get-object'; +import createFrame from './utils/createFrame.js'; /** * Extend the context with the properties of other objects. @@ -20,7 +23,7 @@ const createFrame = require('./utils/createFrame'); * @api public */ -helpers.extend = function(/*objects*/) { +export function extend(/*objects*/) { var args = [].slice.call(arguments); var opts = {}; @@ -44,7 +47,7 @@ helpers.extend = function(/*objects*/) { } return context; -}; +} /** * Block helper that iterates over the properties of @@ -57,7 +60,7 @@ helpers.extend = function(/*objects*/) { * @api public */ -helpers.forIn = function(obj, options) { +export function forIn(obj, options) { if (!util.isOptions(options)) { return obj.inverse(this); } @@ -70,7 +73,7 @@ helpers.forIn = function(obj, options) { result += options.fn(obj[key], { data: data }); } return result; -}; +} /** * Block helper that iterates over the **own** properties of @@ -83,7 +86,7 @@ helpers.forIn = function(obj, options) { * @api public */ -helpers.forOwn = function(obj, options) { +export function forOwn(obj, options) { if (!util.isOptions(options)) { return obj.inverse(this); } @@ -98,7 +101,7 @@ helpers.forOwn = function(obj, options) { } } return result; -}; +} /** * Take arguments and, if they are string or number, convert them to a dot-delineated object property path. @@ -108,7 +111,7 @@ helpers.forOwn = function(obj, options) { * @api public */ -helpers.toPath = function(/*prop*/) { +export function toPath(/*prop*/) { var prop = []; for (var i = 0; i < arguments.length; i++) { if (typeof arguments[i] === 'string' || typeof arguments[i] === 'number') { @@ -116,7 +119,7 @@ helpers.toPath = function(/*prop*/) { } } return prop.join('.'); -}; +} /** * Use property paths (`a.b.c`) to get a value or nested value from @@ -130,13 +133,13 @@ helpers.toPath = function(/*prop*/) { * @api public */ -helpers.get = function(prop, context, options) { +export function get(prop, context, options) { var val = getValue(context, prop); if (options && options.fn) { return val ? options.fn(val) : options.inverse(context); } return val; -}; +} /** * Use property paths (`a.b.c`) to get an object from @@ -151,9 +154,10 @@ helpers.get = function(prop, context, options) { * @api public */ -helpers.getObject = function(prop, context) { +const _getObject = function(prop, context) { return getObject(context, prop); }; +export { _getObject as getObject }; /** * Return true if `key` is an own, enumerable property @@ -169,9 +173,10 @@ helpers.getObject = function(prop, context) { * @api public */ -helpers.hasOwn = function(context, key) { +const _hasOwn = function(context, key) { return hasOwn.call(context, key); }; +export { _hasOwn as hasOwn }; /** * Return true if `value` is an object. @@ -185,9 +190,10 @@ helpers.hasOwn = function(context, key) { * @api public */ -helpers.isObject = function(value) { +const _isObject = function(value) { return typeof value === 'object'; }; +export { _isObject as isObject }; /** * Parses the given string using `JSON.parse`. @@ -203,9 +209,9 @@ helpers.isObject = function(value) { * @api public */ -helpers.JSONparse = function(str, options) { +export function JSONparse(str, options) { return JSON.parse(str); -}; +} /** * Stringify an object using `JSON.stringify`. @@ -220,12 +226,12 @@ helpers.JSONparse = function(str, options) { * @api public */ -helpers.JSONstringify = function(obj, indent) { +export function JSONstringify(obj, indent) { if (isNaN(indent)) { indent = 0; } return JSON.stringify(obj, null, indent); -}; +} /** * Deeply merge the properties of the given `objects` with the @@ -237,7 +243,7 @@ helpers.JSONstringify = function(obj, indent) { * @api public */ -helpers.merge = function(context/*, objects, options*/) { +export function merge(context/*, objects, options*/) { var args = [].slice.call(arguments); var opts = {}; @@ -249,14 +255,9 @@ helpers.merge = function(context/*, objects, options*/) { } return Object.assign.apply(null, args); -}; - -/** - * Alias for parseJSON. this will be - * deprecated in a future release - */ +} -helpers.parseJSON = helpers.JSONparse; +export const parseJSON = JSONparse; /** * Pick properties from the context object. @@ -269,13 +270,13 @@ helpers.parseJSON = helpers.JSONparse; * @api public */ -helpers.pick = function(props, context, options) { - var keys = array.arrayify(props); +export function pick(props, context, options) { + var keys = arrayify(props); var len = keys.length, i = -1; var result = {}; while (++i < len) { - result = helpers.extend({}, result, getObject(context, keys[i])); + result = extend({}, result, getObject(context, keys[i])); } if (options.fn) { @@ -285,11 +286,6 @@ helpers.pick = function(props, context, options) { return options.inverse(context); } return result; -}; - -/** - * Alias for JSONstringify. this will be - * deprecated in a future release - */ +} -helpers.stringify = helpers.JSONstringify; +export const stringify = JSONstringify; diff --git a/lib/string.js b/lib/string.mjs similarity index 89% rename from lib/string.js rename to lib/string.mjs index 4351da27..55e94867 100644 --- a/lib/string.js +++ b/lib/string.mjs @@ -1,13 +1,15 @@ 'use strict'; -var util = { - isString: require('./utils/isString'), - isObject: require('./utils/isObject'), - options: require('./utils/options') +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 }; -var utils = require('./utils'); -var helpers = module.exports; -let lorem = require('./lorem.js'); +import utils from './utils/index.js'; +import loremText from './lorem.js'; /** * Append the specified `suffix` to the given string. @@ -24,7 +26,7 @@ let lorem = require('./lorem.js'); * @example {{append 'index' '.html'}} -> index.html */ -helpers.append = function(str, suffix) { +export const append = function(str, suffix) { if (typeof str === 'string' && typeof suffix === 'string') { return str + suffix; } @@ -44,7 +46,7 @@ helpers.append = function(str, suffix) { * @example {{camelcase 'foo bar baz'}} -> fooBarBaz */ -helpers.camelcase = function(str) { +export const camelcase = function(str) { if (typeof(str) !== 'string') return ''; return utils.changecase(str, function(ch) { return ch.toUpperCase(); @@ -64,7 +66,7 @@ helpers.camelcase = function(str) { * @example {{capitalize 'foo bar baz'}} -> Foo bar baz */ -helpers.capitalize = function(str) { +export const capitalize = function(str) { if (typeof(str) !== 'string') return ''; return str.charAt(0).toUpperCase() + str.slice(1); }; @@ -82,11 +84,11 @@ helpers.capitalize = function(str) { * @example {{ capitalizeAll 'foo bar baz'}} -> Foo Bar Baz */ -helpers.capitalizeAll = function(str) { +export const capitalizeAll = function(str) { if (typeof(str) !== 'string') return ''; if (util.isString(str)) { return str.replace(/\w\S*/g, function(word) { - return helpers.capitalize(word); + return capitalize(word); }); } }; @@ -101,7 +103,7 @@ helpers.capitalizeAll = function(str) { * @example {{ center 'test' 1}} -> ' test ' */ -helpers.center = function(str, spaces) { +export const center = function(str, spaces) { if (typeof(str) !== 'string') return ''; var space = ''; var i = 0; @@ -132,7 +134,7 @@ helpers.center = function(str, spaces) { * @example {{ chop ' ABC '}} -> ABC */ -helpers.chop = function(str) { +export const chop = function(str) { if (typeof(str) !== 'string') return ''; return utils.chop(str); }; @@ -151,7 +153,7 @@ helpers.chop = function(str) { * @example {{dashcase 'a-b-c d_e'}} -> a-b-c-d-e */ -helpers.dashcase = function(str) { +export const dashcase = function(str) { if (typeof(str) !== 'string') return ''; return utils.changecase(str, function(ch) { return '-' + ch; @@ -171,7 +173,7 @@ helpers.dashcase = function(str) { * @example {{dotcase 'a-b-c d_e'}} -> a.b.c.d.e */ -helpers.dotcase = function(str) { +export const dotcase = function(str) { if (typeof(str) !== 'string') return ''; return utils.changecase(str, function(ch) { return '.' + ch; @@ -193,8 +195,8 @@ helpers.dotcase = function(str) { */ -helpers.downcase = function() { - return helpers.lowercase.apply(this, arguments); +export const downcase = function() { + return lowercase.apply(this, arguments); }; /** @@ -214,12 +216,12 @@ helpers.downcase = function() { * @example {{ellipsis 'foo bar baz' 7}} -> foo bar… */ -helpers.ellipsis = function(str, limit) { +export const ellipsis = function(str, limit) { if (util.isString(str)) { if (str.length <= limit) { return str; } - return helpers.truncate(str, limit) + '…'; + return truncate(str, limit) + '…'; } }; @@ -236,7 +238,7 @@ helpers.ellipsis = function(str, limit) { * @example {{hyphenate 'foo bar baz qux'}} -> foo-bar-baz-qux */ -helpers.hyphenate = function(str) { +export const hyphenate = function(str) { if (typeof(str) !== 'string') return ''; return str.split(' ').join('-'); }; @@ -254,7 +256,7 @@ helpers.hyphenate = function(str) { * @example {{isString 'foo'}} -> true */ -helpers.isString = function(value) { +export const isString = function(value) { return typeof value === 'string'; }; @@ -271,7 +273,7 @@ helpers.isString = function(value) { * @example {{lowercase 'Foo BAR baZ'}} -> foo bar baz */ -helpers.lowercase = function(str) { +export const lowercase = function(str) { if (util.isObject(str) && str.fn) { return str.fn(this).toLowerCase(); } @@ -294,7 +296,7 @@ helpers.lowercase = function(str) { * @example {{occurrences 'foo bar foo bar baz' 'foo'}} -> 2 */ -helpers.occurrences = function(str, substring) { +export const occurrences = function(str, substring) { if (typeof(str) !== 'string') return ''; var len = substring.length; var pos = 0; @@ -320,7 +322,7 @@ helpers.occurrences = function(str, substring) { * @example {{pascalcase 'foo bar baz'}} -> FooBarBaz */ -helpers.pascalcase = function(str) { +export const pascalcase = function(str) { if (typeof(str) !== 'string') return ''; str = utils.changecase(str, function(ch) { return ch.toUpperCase(); @@ -341,7 +343,7 @@ helpers.pascalcase = function(str) { * @example {{pathcase 'a-b-c d_e'}} -> a/b/c/d/e */ -helpers.pathcase = function(str) { +export const pathcase = function(str) { if (typeof(str) !== 'string') return ''; return utils.changecase(str, function(ch) { return '/' + ch; @@ -362,7 +364,7 @@ helpers.pathcase = function(str) { * @example {{plusify 'foo bar baz'}} -> foo+bar+baz */ -helpers.plusify = function(str, ch) { +export const plusify = function(str, ch) { if (typeof(str) !== 'string') return ''; if (!util.isString(ch)) ch = ' '; return str.split(ch).join('+'); @@ -383,7 +385,7 @@ helpers.plusify = function(str, ch) { * @example {{prepend 'bar' 'foo-'}} -> foo-bar */ -helpers.prepend = function(str, prefix) { +export const prepend = function(str, prefix) { return typeof str === 'string' && typeof prefix === 'string' ? (prefix + str) : str; @@ -406,7 +408,7 @@ helpers.prepend = function(str, prefix) { * @example {{{{raw}}}}{{foo}}{{{{/raw}}}} -> \{{foo}} */ -helpers.raw = function(options) { +export const raw = function(options) { var str = options.fn(); var opts = util.options(this, options); if (opts.escape !== false) { @@ -435,7 +437,7 @@ helpers.raw = function(options) { * @example {{remove 'a b a b a b' 'a '}} -> b b b */ -helpers.remove = function(str, ch) { +export const remove = function(str, ch) { if (typeof(str) !== 'string') return ''; if (!util.isString(ch)) return str; return str.split(ch).join(''); @@ -455,7 +457,7 @@ helpers.remove = function(str, ch) { * @example {{removeFirst 'a b a b a b' 'a'}} -> ' b a b a b' */ -helpers.removeFirst = function(str, ch) { +export const removeFirst = function(str, ch) { if (typeof(str) !== 'string') return ''; if (!util.isString(ch)) return str; return str.replace(ch, ''); @@ -476,7 +478,7 @@ helpers.removeFirst = function(str, ch) { * @example {{replace 'a b a b a b' 'a' 'z'}} -> z b z b z b */ -helpers.replace = function(str, a, b) { +export const replace = function(str, a, b) { if (typeof(str) !== 'string') return ''; if (!util.isString(a)) return str; if (!util.isString(b)) b = ''; @@ -498,7 +500,7 @@ helpers.replace = function(str, a, b) { * @example {{replaceFirst 'a b a b a b' 'a' 'z'}} -> z b a b a b */ -helpers.replaceFirst = 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 = ''; @@ -518,7 +520,7 @@ helpers.replaceFirst = function(str, a, b) { * @example {{reverse 'abcde'}} -> edcba */ -helpers.reverse = require('./array').reverse; +export { reverse} from './array.mjs'; /** * Sentence case the given string @@ -533,7 +535,7 @@ helpers.reverse = require('./array').reverse; * @example {{sentence 'hello world. goodbye world.'}} -> Hello world. Goodbye world. */ -helpers.sentence = function(str) { +export const sentence = function(str) { if (typeof(str) !== 'string') return ''; return str.replace(/((?:\S[^\.\?\!]*)[\.\?\!]*)/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); @@ -553,7 +555,7 @@ helpers.sentence = function(str) { * @example {{snakecase 'a-b-c d_e'}} -> a_b_c_d_e */ -helpers.snakecase = function(str) { +export const snakecase = function(str) { if (typeof(str) !== 'string') return ''; return utils.changecase(str, function(ch) { return '_' + ch; @@ -573,7 +575,7 @@ helpers.snakecase = function(str) { * @example {{split 'a,b,c'}} -> ['a', 'b', 'c'] */ -helpers.split = function(str, ch) { +export const split = function(str, ch) { if (typeof(str) !== 'string') return ''; if (!util.isString(ch)) ch = ','; return str.split(ch); @@ -599,7 +601,7 @@ helpers.split = function(str, ch) { * @example {{#startsWith 'Goodbye' 'Hello, world!'}}Yep{{else}}Nope{{/startsWith}} -> Nope */ -helpers.startsWith = function(prefix, str, options) { +export const startsWith = function(prefix, str, options) { var args = [].slice.call(arguments); options = args.pop(); if (util.isString(str) && str.indexOf(prefix) === 0) { @@ -624,7 +626,7 @@ helpers.startsWith = function(prefix, str, options) { * @example {{titleize 'this is title case' }} -> This Is Title Case */ -helpers.titleize = function(str) { +export const titleize = function(str) { if (typeof(str) !== 'string') return ''; var title = str.replace(/[- _]+/g, ' '); var words = title.split(' '); @@ -633,7 +635,7 @@ helpers.titleize = function(str) { var i = 0; while (len--) { var word = words[i++]; - res.push(exports.capitalize(word)); + res.push(capitalize(word)); } return res.join(' '); }; @@ -652,7 +654,7 @@ helpers.titleize = function(str) { * @example {{trim ' ABC ' }} -> ABC */ -helpers.trim = function(str) { +export const trim = function(str) { return typeof str === 'string' ? str.trim() : ''; }; @@ -669,7 +671,7 @@ helpers.trim = function(str) { * @example {{trimLeft ' ABC ' }} -> 'ABC ' */ -helpers.trimLeft = function(str) { +export const trimLeft = function(str) { if (util.isString(str)) { return str.replace(/^\s+/, ''); } @@ -688,7 +690,7 @@ helpers.trimLeft = function(str) { * @example {{trimRight ' ABC ' }} -> ' ABC' */ -helpers.trimRight = function(str) { +export const trimRight = function(str) { if (util.isString(str)) { return str.replace(/\s+$/, ''); } @@ -712,7 +714,7 @@ helpers.trimRight = function(str) { * @example {{truncate 'foo bar baz' 7 }} -> foo bar */ -helpers.truncate = function(str, limit, suffix) { +export const truncate = function(str, limit, suffix) { if (util.isString(str)) { if (typeof suffix !== 'string') { suffix = ''; @@ -745,7 +747,7 @@ helpers.truncate = function(str, limit, suffix) { * @example {{truncateWords 'foo bar baz' 1 }} -> foo… */ -helpers.truncateWords = function(str, count, suffix) { +export const truncateWords = function(str, count, suffix) { if (util.isString(str) && !isNaN(count)) { if (typeof suffix !== 'string') { suffix = '…'; @@ -777,8 +779,8 @@ helpers.truncateWords = function(str, count, suffix) { * @example {{upcase 'aBcDef'}} -> ABCDEF */ -helpers.upcase = function() { - return helpers.uppercase.apply(this, arguments); +export const upcase = function() { + return uppercase.apply(this, arguments); }; /** @@ -800,7 +802,7 @@ helpers.upcase = function() { * @example {{uppercase 'aBcDef'}} -> ABCDEF */ -helpers.uppercase = function(str) { +export const uppercase = function(str) { if (util.isObject(str) && str.fn) { return str.fn(this).toUpperCase(); } @@ -823,11 +825,11 @@ helpers.uppercase = function(str) { * @example {{lorem 11}} -> Lorem ipsum */ -helpers.lorem = function(num) { +export const lorem = function(num) { // Sad Path - Not a number, or not greater than 1, or not truthy if (isNaN(num) || num < 1 || !num) { num = 11; } - return lorem.substring(0, num); + return loremText.substring(0, num); }; diff --git a/test/array.mjs b/test/array.mjs index 1f1d7a1a..92ab8527 100644 --- a/test/array.mjs +++ b/test/array.mjs @@ -390,7 +390,7 @@ describe('array', function() { it('should sort based on object key:', function() { var ctx = {arr: [{a: 'zzz'}, {a: 'aaa'}]}; - hbs.registerHelper(object()); + object({handlebars: hbs}); var fn = hbs.compile('{{{stringify (sortBy arr "a") 0}}}'); equal(fn(ctx), '[{"a":"aaa"},{"a":"zzz"}]'); }); diff --git a/test/examples/index.mjs b/test/examples/index.mjs index 2a11a35f..92c93541 100644 --- a/test/examples/index.mjs +++ b/test/examples/index.mjs @@ -13,6 +13,7 @@ stub(math, 'random').returns(10); import { equal } from 'assert'; import lib from '../../lib/index.mjs'; +lib.uuid = () => 'f34ebc66-93bd-4f7c-b79b-92b5569138bc'; import { readFileSync, existsSync } from 'fs'; import { parse } from 'doctrine'; From b9d8538e3e46f885c27e77b104fc78922865c27a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 16:55:44 +0100 Subject: [PATCH 16/46] Migrate "code" --- lib/{code.js => code.mjs} | 34 +++++++++++----------------------- lib/index.mjs | 2 +- 2 files changed, 12 insertions(+), 24 deletions(-) rename lib/{code.js => code.mjs} (70%) diff --git a/lib/code.js b/lib/code.mjs similarity index 70% rename from lib/code.js rename to lib/code.mjs index d665c03b..92510bc1 100644 --- a/lib/code.js +++ b/lib/code.mjs @@ -1,10 +1,9 @@ 'use strict'; -var fs = require('fs'); -var path = require('path'); -const codeBlock = require('to-gfm-code-block'); -const htmlTag = require('html-tag'); -var helpers = module.exports; +import { readFileSync } from 'fs'; +import { extname } from 'path'; +import codeBlock from 'to-gfm-code-block'; +import htmlTag from 'html-tag'; /** * Embed code from an external file as preformatted text. @@ -21,16 +20,16 @@ var helpers = module.exports; * @api public */ -helpers.embed = function embed(filepath, ext) { - ext = typeof ext !== 'string' ? path.extname(filepath).slice(1) : ext; - var code = fs.readFileSync(filepath, 'utf8'); +export function embed(filepath, ext) { + ext = typeof ext !== 'string' ? extname(filepath).slice(1) : ext; + var code = readFileSync(filepath, 'utf8'); if (ext === 'markdown' || ext === 'md') { ext = 'markdown'; // if the string is markdown, escape backticks code = code.split('`').join('`'); } return codeBlock(code, ext).trim() + '\n'; -}; +} /** * Embed a GitHub Gist using only the id of the Gist @@ -43,22 +42,11 @@ helpers.embed = function embed(filepath, ext) { * @api public */ -helpers.gist = function(id) { +export function gist(id) { return htmlTag('script', {src: 'https://gist.github.com/' + id + '.js'}); -}; - -/** - * Generate the HTML for a jsFiddle link with the given `params` - * - * ```handlebars - * {{jsfiddle id='0dfk10ks' tabs='true'}} - * ``` - * @param {Object} `params` - * @return {String} - * @api public - */ +} -helpers.jsfiddle = function jsFiddle(options) { +export const jsfiddle = function jsFiddle(options) { var attr = Object.assign({}, options && options.hash); if (typeof attr.id === 'undefined') { diff --git a/lib/index.mjs b/lib/index.mjs index 63c4f54c..2f5ee1a7 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -1,7 +1,7 @@ 'use strict'; import * as array from './array.mjs'; -import code from './code.js'; +import * as code from './code.mjs'; import * as collection from './collection.mjs'; import comparison from './comparison.js'; import html from './html.js'; From 24ace03963c860916069b164797e60f0554ecf71 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:05:31 +0100 Subject: [PATCH 17/46] Convert "comparison" --- lib/{comparison.js => comparison.mjs} | 124 ++++++++++++-------------- lib/index.mjs | 2 +- lib/utils/index.js | 7 ++ 3 files changed, 66 insertions(+), 67 deletions(-) rename lib/{comparison.js => comparison.mjs} (90%) diff --git a/lib/comparison.js b/lib/comparison.mjs similarity index 90% rename from lib/comparison.js rename to lib/comparison.mjs index cad8c9a8..28e55ba5 100644 --- a/lib/comparison.js +++ b/lib/comparison.mjs @@ -1,18 +1,10 @@ 'use strict'; -var has = require('has-value'); -var util = { - value: require('./utils/value'), - isOptions: require('./utils/isOptions'), - isString: require('./utils/isString'), - fn: require('./utils/fn'), - isObject: require('./utils/isObject'), - inverse: require('./utils/inverse') -}; -var utils = require('./utils'); -const falsey = require('./utils/falsey'); -const isOdd = require('./utils/odd'); -var helpers = module.exports; +import has from 'has-value'; + +import util from './utils/index.js'; +import falsey from './utils/falsey.js'; +import isOdd from './utils/odd.js'; /** * Helper that renders the block if **both** of the given values @@ -34,7 +26,7 @@ var helpers = module.exports; * @example {{#and great magnificent}}both{{else}}no{{/and}} -> no */ -helpers.and = function() { +export function and() { var len = arguments.length - 1; var options = arguments[len]; var val = true; @@ -47,7 +39,7 @@ helpers.and = function() { } return util.value(val, this, options); -}; +} /** * Render a block when a comparison of the first and third @@ -66,7 +58,7 @@ helpers.and = function() { * @example {{compare 10 '<' 5 }} -> false */ -helpers.compare = function(a, operator, b, options) { +export function compare(a, operator, b, options) { /*eslint eqeqeq: 0*/ if (arguments.length < 4) { @@ -110,7 +102,7 @@ helpers.compare = function(a, operator, b, options) { } return util.value(result, this, options); -}; +} /** * Block helper that renders the block if `collection` has the @@ -136,14 +128,14 @@ helpers.compare = function(a, operator, b, options) { * @example {{#contains ['a', 'b', 'c'] 'd'}} This will not be rendered. {{else}} This will be rendered. {{/contains}} -> ' This will be rendered. ' */ -helpers.contains = function(collection, value, startIndex, options) { +export function contains(collection, value, startIndex, options) { if (typeof startIndex === 'object') { options = startIndex; startIndex = undefined; } - var val = utils.contains(collection, value, startIndex); + var val = util.contains(collection, value, startIndex); return util.value(val, this, options); -}; +} /** * Returns the first value that is not undefined, otherwise the 'default' value is returned. @@ -156,12 +148,13 @@ helpers.contains = function(collection, value, startIndex, options) { * @example {{default null null 'default'}} -> default */ -helpers.default = function() { +const _default = function() { for (var i = 0; i < arguments.length - 1; i++) { if (arguments[i] != null) return arguments[i]; } return ''; }; +export { _default as default }; /** * Block helper that renders a block if `a` is **equal to** `b`. @@ -179,13 +172,13 @@ helpers.default = function() { * @example {{#eq 3 3}}equal{{else}}not equal{{/eq}} -> equal */ -helpers.eq = function(a, b, options) { +export function eq(a, b, options) { if (arguments.length === 2) { options = b; b = options.hash.compare; } return util.value(a === b, this, options); -}; +} /** * Block helper that renders a block if `a` is **greater than** `b`. @@ -203,13 +196,13 @@ helpers.eq = function(a, b, options) { * @example {{#gt 4 3}} greater than{{else}} not greater than{{/gt}} -> ' greater than' */ -helpers.gt = function(a, b, options) { +export function gt(a, b, options) { if (arguments.length === 2) { options = b; b = options.hash.compare; } return util.value(a > b, this, options); -}; +} /** * Block helper that renders a block if `a` is **greater than or @@ -228,13 +221,13 @@ helpers.gt = function(a, b, options) { * @example {{#gte 4 3}} greater than or equal{{else}} not greater than{{/gte}} -> ' greater than or equal' */ -helpers.gte = function(a, b, options) { +export function gte(a, b, options) { if (arguments.length === 2) { options = b; b = options.hash.compare; } return util.value(a >= b, this, options); -}; +} /** * Block helper that renders a block if `value` has `pattern`. @@ -249,7 +242,7 @@ helpers.gte = function(a, b, options) { * @example {{#has 'foobar' 'foo'}}has it{{else}}doesn't{{/has}} -> has it */ -helpers.has = function(value, pattern, options) { +const _has = function(value, pattern, options) { if (util.isOptions(value)) { options = value; pattern = null; @@ -269,10 +262,8 @@ helpers.has = function(value, pattern, options) { return util.value(has(this, value), this, options); } - if ( - (Array.isArray(value) || util.isString(value)) && - util.isString(pattern) - ) { + if ((Array.isArray(value) || util.isString(value)) && + util.isString(pattern)) { if (value.indexOf(pattern) > -1) { return util.fn(true, this, options); } @@ -282,6 +273,7 @@ helpers.has = function(value, pattern, options) { } return util.inverse(false, this, options); }; +export { _has as has }; /** * Returns true if the given `value` is falsey. Uses the [falsey][] @@ -295,9 +287,9 @@ helpers.has = function(value, pattern, options) { * @example {{isFalsey '' }} -> true */ -helpers.isFalsey = function(val, options) { +export function isFalsey(val, options) { return util.value(falsey(val), this, options); -}; +} /** * Returns true if the given `value` is truthy. Uses the [falsey][] @@ -311,9 +303,9 @@ helpers.isFalsey = function(val, options) { * @example {{isTruthy '12' }} -> true */ -helpers.isTruthy = function(val, options) { +export function isTruthy(val, options) { return util.value(!falsey(val), this, options); -}; +} /** * Return true if the given value is an even number. @@ -333,9 +325,9 @@ helpers.isTruthy = function(val, options) { * @example {{#ifEven 2}} even {{else}} odd {{/ifEven}} -> ' even ' */ -helpers.ifEven = function(num, options) { +export function ifEven(num, options) { return util.value(!isOdd(num), this, options); -}; +} /** * Conditionally renders a block if the remainder is zero when @@ -351,10 +343,10 @@ helpers.ifEven = function(num, options) { * @example {{#ifNth 2 10}}remainder{{else}}no remainder{{/ifNth}} -> remainder */ -helpers.ifNth = function(a, b, options) { +export function ifNth(a, b, options) { var isNth = !isNaN(a) && !isNaN(b) && b % a === 0; return util.value(isNth, this, options); -}; +} /** * Block helper that renders a block if `value` is **an odd number**. @@ -375,9 +367,9 @@ helpers.ifNth = function(a, b, options) { * @example {{#ifOdd 3}}odd{{else}}even{{/ifOdd}} -> odd */ -helpers.ifOdd = function(val, options) { +export function ifOdd(val, options) { return util.value(isOdd(val), this, options); -}; +} /** * Block helper that renders a block if `a` is **equal to** `b`. @@ -393,13 +385,13 @@ helpers.ifOdd = function(val, options) { * @example {{#is 3 3}} is {{else}} is not {{/is}} -> ' is ' */ -helpers.is = function(a, b, options) { +export function is(a, b, options) { if (arguments.length === 2) { options = b; b = options.hash.compare; } return util.value(a == b, this, options); -}; +} /** * Block helper that renders a block if `a` is **not equal to** `b`. @@ -416,13 +408,13 @@ helpers.is = function(a, b, options) { * @example {{#isnt 3 3}} isnt {{else}} is {{/isnt}} -> ' is ' */ -helpers.isnt = function(a, b, options) { +export function isnt(a, b, options) { if (arguments.length === 2) { options = b; b = options.hash.compare; } return util.value(a != b, this, options); -}; +} /** * Block helper that renders a block if `a` is **less than** `b`. @@ -439,13 +431,13 @@ helpers.isnt = function(a, b, options) { * @example {{#lt 2 3}} less than {{else}} more than or equal {{/lt}} -> ' less than ' */ -helpers.lt = function(a, b, options) { +export function lt(a, b, options) { if (arguments.length === 2) { options = b; b = options.hash.compare; } return util.value(a < b, this, options); -}; +} /** * Block helper that renders a block if `a` is **less than or @@ -464,13 +456,13 @@ helpers.lt = function(a, b, options) { * @example {{#lte 2 3}} less than or equal {{else}} more than {{/lte}} -> ' less than or equal ' */ -helpers.lte = function(a, b, options) { +export function lte(a, b, options) { if (arguments.length === 2) { options = b; b = options.hash.compare; } return util.value(a <= b, this, options); -}; +} /** * Block helper that renders a block if **neither of** the given values @@ -486,9 +478,9 @@ helpers.lte = function(a, b, options) { * @example {{#neither null null}}both falsey{{else}}both not falsey{{/neither}} -> both falsey */ -helpers.neither = function(a, b, options) { +export function neither(a, b, options) { return util.value(!a && !b, this, options); -}; +} /** * Returns true if `val` is falsey. Works as a block or inline helper. @@ -501,9 +493,9 @@ helpers.neither = function(a, b, options) { * @example {{#not undefined }}falsey{{else}}not falsey{{/not}} -> falsey */ -helpers.not = function(val, options) { +export function not(val, options) { return util.value(!val, this, options); -}; +} /** * Block helper that renders a block if **any of** the given values @@ -524,7 +516,7 @@ helpers.not = function(val, options) { * @example {{#or 1 2 undefined }} at least one truthy {{else}} all falsey {{/or}} -> ' at least one truthy ' */ -helpers.or = function(/* any, any, ..., options */) { +export function or(/* any, any, ..., options */) { var len = arguments.length - 1; var options = arguments[len]; var val = false; @@ -536,7 +528,7 @@ helpers.or = function(/* any, any, ..., options */) { } } return util.value(val, this, options); -}; +} /** * Block helper that always renders the inverse block **unless `a` is @@ -551,13 +543,13 @@ helpers.or = function(/* any, any, ..., options */) { * @example {{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> ' not equal ' */ -helpers.unlessEq = function(a, b, options) { +export function unlessEq(a, b, options) { if (util.isOptions(b)) { options = b; b = options.hash.compare; } return util.value(a !== b, this, options); -}; +} /** * Block helper that always renders the inverse block **unless `a` is @@ -572,13 +564,13 @@ helpers.unlessEq = function(a, b, options) { * @example {{#unlessGt 20 1 }} not greater than {{else}} greater than {{/unlessGt}} -> ' greater than ' */ -helpers.unlessGt = function(a, b, options) { +export function unlessGt(a, b, options) { if (util.isOptions(b)) { options = b; b = options.hash.compare; } return util.value(a <= b, this, options); -}; +} /** * Block helper that always renders the inverse block **unless `a` is @@ -593,13 +585,13 @@ helpers.unlessGt = function(a, b, options) { * @example {{#unlessLt 20 1 }}greater than or equal{{else}}less than{{/unlessLt}} -> greater than or equal */ -helpers.unlessLt = function(a, b, options) { +export function unlessLt(a, b, options) { if (util.isOptions(b)) { options = b; b = options.hash.compare; } return util.value(a >= b, this, options); -}; +} /** * Block helper that always renders the inverse block **unless `a` is @@ -614,13 +606,13 @@ helpers.unlessLt = function(a, b, options) { * @example {{#unlessGteq 20 1 }} less than {{else}}greater than or equal to{{/unlessGteq}} -> greater than or equal to */ -helpers.unlessGteq = function(a, b, options) { +export function unlessGteq(a, b, options) { if (util.isOptions(b)) { options = b; b = options.hash.compare; } return util.value(a < b, this, options); -}; +} /** * Block helper that always renders the inverse block **unless `a` is @@ -635,10 +627,10 @@ helpers.unlessGteq = function(a, b, options) { * @example {{#unlessLteq 20 1 }} greater than {{else}} less than or equal to {{/unlessLteq}} -> ' greater than ' */ -helpers.unlessLteq = function(a, b, options) { +export function unlessLteq(a, b, options) { if (util.isOptions(b)) { options = b; b = options.hash.compare; } return util.value(a > b, this, options); -}; +} diff --git a/lib/index.mjs b/lib/index.mjs index 2f5ee1a7..9986e72f 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -3,7 +3,7 @@ import * as array from './array.mjs'; import * as code from './code.mjs'; import * as collection from './collection.mjs'; -import comparison from './comparison.js'; +import * as comparison from './comparison.mjs'; import html from './html.js'; import i18n from './i18n.js'; import inflection from './inflection.js'; diff --git a/lib/utils/index.js b/lib/utils/index.js index 0ad95ebd..c0bae479 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -77,3 +77,10 @@ exports.changecase = function(str, fn) { exports.random = function(min, max) { return min + Math.floor(Math.random() * (max - min + 1)); }; + +exports.isOptions = require('./isOptions'); +exports.value = require('./value'); +exports.isString = require('./isString'); +exports.fn = require('./fn'); +exports.isObject = require('./isObject'); +exports.inverse = require('./inverse'); From 4f92a79efd5e8fa7f682d4465086320fb9642c6a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:05:36 +0100 Subject: [PATCH 18/46] Fix linting --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index c15096ec..adad6c4c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,5 @@ { - "parserOptions": { "sourceType": "module" }, + "parserOptions": { "sourceType": "module", "ecmaVersion": "latest" }, "env": { "browser": false, "es6": true, From 6cfdc1f293d641a973693653b8f6b8ec4f0df7ea Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:12:24 +0100 Subject: [PATCH 19/46] Convert number --- .eslintrc.json | 2 +- lib/index.mjs | 2 +- lib/{number.js => number.mjs} | 41 ++++++++++++++++------------------- lib/utils/index.js | 1 + 4 files changed, 22 insertions(+), 24 deletions(-) rename lib/{number.js => number.mjs} (89%) diff --git a/.eslintrc.json b/.eslintrc.json index adad6c4c..a8debbb7 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,5 @@ { - "parserOptions": { "sourceType": "module", "ecmaVersion": "latest" }, + "parserOptions": { "sourceType": "module", "ecmaVersion": 9 }, "env": { "browser": false, "es6": true, diff --git a/lib/index.mjs b/lib/index.mjs index 9986e72f..bb2f0f3f 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -10,7 +10,7 @@ import inflection from './inflection.js'; import match from './match.js'; import math from './math.js'; import misc from './misc.js'; -import number from './number.js'; +import * as number from './number.mjs'; import * as object from './object.mjs'; import path from './path.js'; import regex from './regex.js'; diff --git a/lib/number.js b/lib/number.mjs similarity index 89% rename from lib/number.js rename to lib/number.mjs index 7948db60..a72c1643 100644 --- a/lib/number.js +++ b/lib/number.mjs @@ -1,9 +1,6 @@ 'use strict'; -var util = { - isUndefined: require('./utils/isUndefined') -}; -var helpers = module.exports; +import util from './utils/index.js'; /** * Format a number to it's equivalent in bytes. If a string is passed, @@ -22,7 +19,7 @@ var helpers = module.exports; * @example {{ bytes 1386 1 }} -> 1.4 kB */ -helpers.bytes = function(number, precision, options) { +export function bytes(number, precision, options) { if (number == null) return '0 B'; if (isNaN(number)) { @@ -49,7 +46,7 @@ helpers.bytes = function(number, precision, options) { } return number; -}; +} /** * Add commas to numbers @@ -60,9 +57,9 @@ helpers.bytes = function(number, precision, options) { * @example {{ addCommas 1000000 }} -> 1,000,000 */ -helpers.addCommas = function(num) { +export function addCommas(num) { return num.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,'); -}; +} /** * Convert a string or number to a formatted phone number. @@ -74,13 +71,13 @@ helpers.addCommas = function(num) { * @example {{ phoneNumber 8005551212 }} -> (800) 555-1212 */ -helpers.phoneNumber = function(num) { +export function phoneNumber(num) { num = num.toString(); return '(' + num.substr(0, 3) + ') ' + num.substr(3, 3) + '-' + num.substr(6, 4); -}; +} /** * Abbreviate numbers to the given number of `precision`. This is for @@ -93,7 +90,7 @@ helpers.phoneNumber = function(num) { * @example {{ toAbbr 10123 2 }} -> 10.12k */ -helpers.toAbbr = function(number, precision) { +export function toAbbr(number, precision) { if (isNaN(number)) { number = 0; } @@ -117,7 +114,7 @@ helpers.toAbbr = function(number, precision) { len--; } return number; -}; +} /** * Returns a string representing the given number in exponential notation. @@ -132,7 +129,7 @@ helpers.toAbbr = function(number, precision) { * @example {{ toExponential 10123 2 }} -> 1.01e+4 */ -helpers.toExponential = function(number, digits) { +export function toExponential(number, digits) { if (isNaN(number)) { number = 0; } @@ -140,7 +137,7 @@ helpers.toExponential = function(number, digits) { digits = 0; } return Number(number).toExponential(digits); -}; +} /** * Formats the given number using fixed-point notation. @@ -156,7 +153,7 @@ helpers.toExponential = function(number, digits) { * @example {{ toFixed 1.1234 2 }} -> 1.12 */ -helpers.toFixed = function(number, digits) { +export function toFixed(number, digits) { if (isNaN(number)) { number = 0; } @@ -164,7 +161,7 @@ helpers.toFixed = function(number, digits) { digits = 0; } return Number(number).toFixed(digits); -}; +} /** * @param {Number} `number` @@ -172,9 +169,9 @@ helpers.toFixed = function(number, digits) { * @api public */ -helpers.toFloat = function(number) { +export function toFloat(number) { return parseFloat(number); -}; +} /** * @param {Number} `number` @@ -182,9 +179,9 @@ helpers.toFloat = function(number) { * @api public */ -helpers.toInt = function(number) { +export function toInt(number) { return parseInt(number, 10); -}; +} /** * Returns a string representing the `Number` object to the specified precision. @@ -200,7 +197,7 @@ helpers.toInt = function(number) { * @example {{toPrecision '1.1234' 2}} -> 1.1 */ -helpers.toPrecision = function(number, precision) { +export function toPrecision(number, precision) { if (isNaN(number)) { number = 0; } @@ -208,4 +205,4 @@ helpers.toPrecision = function(number, precision) { precision = 1; } return Number(number).toPrecision(precision); -}; +} diff --git a/lib/utils/index.js b/lib/utils/index.js index c0bae479..7952773f 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -84,3 +84,4 @@ exports.isString = require('./isString'); exports.fn = require('./fn'); exports.isObject = require('./isObject'); exports.inverse = require('./inverse'); +exports.isUndefined = require('./isUndefined'); From 81d68f8f237f327a97075972f82b31da1a6127ff Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:16:32 +0100 Subject: [PATCH 20/46] Migrate i18n --- lib/{i18n.js => i18n.mjs} | 15 +++++++-------- lib/index.mjs | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) rename lib/{i18n.js => i18n.mjs} (77%) diff --git a/lib/i18n.js b/lib/i18n.mjs similarity index 77% rename from lib/i18n.js rename to lib/i18n.mjs index 1b4a8d66..a06b7b48 100644 --- a/lib/i18n.js +++ b/lib/i18n.mjs @@ -1,8 +1,7 @@ 'use strict'; -var util = require('./utils/handlebarsUtils'); -var helpers = module.exports; -const getValue = require('get-value'); +import handlebarsUtils from './utils/handlebarsUtils.js'; +import getValue from 'get-value'; /** * i18n helper. See [button-i18n](https://github.com/assemble/buttons) @@ -15,17 +14,17 @@ const getValue = require('get-value'); * @api public */ -helpers.i18n = function(prop, locals, options) { - if (util.isOptions(locals)) { +export function i18n(prop, locals, options) { + if (handlebarsUtils.isOptions(locals)) { options = locals; locals = {}; } - if (!util.isString(prop)) { + if (!handlebarsUtils.isString(prop)) { throw new Error('{{i18n}} helper expected "key" to be a string'); } - var opts = util.options(this, locals, options); + var opts = handlebarsUtils.options(this, locals, options); var context = Object.assign({}, this, opts); var lang = context.language || context.lang; @@ -45,4 +44,4 @@ helpers.i18n = function(prop, locals, options) { } return result; -}; +} diff --git a/lib/index.mjs b/lib/index.mjs index bb2f0f3f..270f6410 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -5,7 +5,7 @@ import * as code from './code.mjs'; import * as collection from './collection.mjs'; import * as comparison from './comparison.mjs'; import html from './html.js'; -import i18n from './i18n.js'; +import * as i18n from './i18n.mjs'; import inflection from './inflection.js'; import match from './match.js'; import math from './math.js'; From 9a2c3b1722ad365950d0658531e72a67e7532c28 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:18:41 +0100 Subject: [PATCH 21/46] Migrate html --- lib/{fs.js => fs.mjs} | 40 +++++++++++++--------------- lib/{html.js => html.mjs} | 56 ++++++++++++++++++++------------------- lib/index.mjs | 2 +- 3 files changed, 48 insertions(+), 50 deletions(-) rename lib/{fs.js => fs.mjs} (54%) rename lib/{html.js => html.mjs} (85%) diff --git a/lib/fs.js b/lib/fs.mjs similarity index 54% rename from lib/fs.js rename to lib/fs.mjs index 6460a6de..16bfcd41 100644 --- a/lib/fs.js +++ b/lib/fs.mjs @@ -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 @@ -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 @@ -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') { @@ -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; -}; +} diff --git a/lib/html.js b/lib/html.mjs similarity index 85% rename from lib/html.js rename to lib/html.mjs index 208ee07a..6011ac9e 100644 --- a/lib/html.js +++ b/lib/html.mjs @@ -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`. @@ -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 `` tags. Automatically resolves @@ -42,13 +44,13 @@ 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) { @@ -56,15 +58,15 @@ helpers.css = function(list, options) { } 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') { @@ -72,7 +74,7 @@ helpers.css = function(list, options) { } return ``; }).join('\n'); -}; +} /** * Generate one or more `` tags with paths/urls to @@ -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 ``; @@ -96,13 +98,13 @@ helpers.js = function(context) { return ``; } - 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 @@ -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 (`
    `) @@ -132,14 +134,14 @@ helpers.sanitize = function(str) { * @api public */ -helpers.ul = function(context, options) { +export function ul(context, options) { return ('
      ') + context.map(function(item) { if (typeof item !== 'string') { item = options.fn(item); } return '
    • ' + item + '
    • '; }).join('\n') + '
    '; -}; +} /** * Block helper for creating ordered lists (`
      `) @@ -151,14 +153,14 @@ helpers.ul = function(context, options) { * @api public */ -helpers.ol = function(context, options) { +export function ol(context, options) { return ('
        ') + context.map(function(item) { if (typeof item !== 'string') { item = options.fn(item); } return '
      1. ' + item + '
      2. '; }).join('\n') + '
      '; -}; +} /** * Returns a `
      ` with a thumbnail linked to a full picture @@ -173,7 +175,7 @@ helpers.ol = function(context, options) { * @api public */ -helpers.thumbnailImage = function(context) { +export function thumbnailImage(context) { var figure = ''; var image = ''; @@ -215,4 +217,4 @@ helpers.thumbnailImage = function(context) { figure += '
      '; return figure; -}; +} diff --git a/lib/index.mjs b/lib/index.mjs index 270f6410..a58c5a5e 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -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'; From 7ae82565a55991a3b2be9edc3220b0d2065737f7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:20:39 +0100 Subject: [PATCH 22/46] More conversions --- lib/index.mjs | 2 +- lib/{inflection.js => inflection.mjs} | 14 +++++++------- lib/string.mjs | 2 +- lib/{ => utils}/lorem.js | 0 4 files changed, 9 insertions(+), 9 deletions(-) rename lib/{inflection.js => inflection.mjs} (85%) rename lib/{ => utils}/lorem.js (100%) diff --git a/lib/index.mjs b/lib/index.mjs index a58c5a5e..cbf2b8d6 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -6,7 +6,7 @@ import * as collection from './collection.mjs'; import * as comparison from './comparison.mjs'; import * as html from './html.mjs'; import * as i18n from './i18n.mjs'; -import inflection from './inflection.js'; +import * as inflection from './inflection.mjs'; import match from './match.js'; import math from './math.js'; import misc from './misc.js'; diff --git a/lib/inflection.js b/lib/inflection.mjs similarity index 85% rename from lib/inflection.js rename to lib/inflection.mjs index b518b98e..9c6c5419 100644 --- a/lib/inflection.js +++ b/lib/inflection.mjs @@ -1,7 +1,7 @@ 'use strict'; -var util = require('./utils/handlebarsUtils'); -var helpers = module.exports; +import handlebarsUtils from './utils/handlebarsUtils.js'; +const { indexOf } = handlebarsUtils; /** * Returns either the `singular` or `plural` inflection of a word based on @@ -27,14 +27,14 @@ var helpers = module.exports; * @api public */ -helpers.inflect = function(count, singular, plural, includeCount) { +export function inflect(count, singular, plural, includeCount) { var word = (count > 1 || count === 0) ? plural : singular; if (includeCount === true) { return String(count) + ' ' + word; } else { return word; } -}; +} /** * Returns an ordinalized number as a string. @@ -55,12 +55,12 @@ helpers.inflect = function(count, singular, plural, includeCount) { * @api public */ -helpers.ordinalize = function(val) { +export function ordinalize(val) { var num = Math.abs(Math.round(val)); var str = String(val); var res = num % 100; - if (util.indexOf([11, 12, 13], res) >= 0) { + if (indexOf([11, 12, 13], res) >= 0) { return str + 'th'; } @@ -75,4 +75,4 @@ helpers.ordinalize = function(val) { return str + 'th'; } } -}; +} diff --git a/lib/string.mjs b/lib/string.mjs index 55e94867..066dd8c5 100644 --- a/lib/string.mjs +++ b/lib/string.mjs @@ -9,7 +9,7 @@ const util = { options: utilOptions }; import utils from './utils/index.js'; -import loremText from './lorem.js'; +import loremText from './utils/lorem.js'; /** * Append the specified `suffix` to the given string. diff --git a/lib/lorem.js b/lib/utils/lorem.js similarity index 100% rename from lib/lorem.js rename to lib/utils/lorem.js From 51ad523ed92a5f989da993432609f63393c31dd7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:22:59 +0100 Subject: [PATCH 23/46] More conversions --- lib/index.mjs | 2 +- lib/{match.js => match.mjs} | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) rename lib/{match.js => match.mjs} (74%) diff --git a/lib/index.mjs b/lib/index.mjs index cbf2b8d6..6d578210 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -7,7 +7,7 @@ import * as comparison from './comparison.mjs'; import * as html from './html.mjs'; import * as i18n from './i18n.mjs'; import * as inflection from './inflection.mjs'; -import match from './match.js'; +import * as match from './match.mjs'; import math from './math.js'; import misc from './misc.js'; import * as number from './number.mjs'; diff --git a/lib/match.js b/lib/match.mjs similarity index 74% rename from lib/match.js rename to lib/match.mjs index 049c99ff..aef7956b 100644 --- a/lib/match.js +++ b/lib/match.mjs @@ -1,8 +1,8 @@ 'use strict'; -var util = require('./utils/handlebarsUtils'); -var helpers = module.exports; -const micromatch = require('micromatch'); +import handlebarsUtils from './utils/handlebarsUtils.js'; + +import micromatch from 'micromatch'; /** * Returns an array of strings that match the given glob pattern(s). @@ -20,13 +20,13 @@ const micromatch = require('micromatch'); * @api public */ -helpers.match = function(files, patterns, locals, options) { - var opts = util.options(this, locals, options); +export function match(files, patterns, locals, options) { + var opts = handlebarsUtils.options(this, locals, options); if (typeof patterns === 'string') { patterns = patterns.split(/, */); } return micromatch(files, patterns, opts); -}; +} /** * Returns true if a filepath contains the given pattern. @@ -44,18 +44,18 @@ helpers.match = function(files, patterns, locals, options) { * @api public */ -helpers.isMatch = function(files, patterns, locals, options) { - var opts = util.options(this, locals, options); +export function isMatch(files, patterns, locals, options) { + var opts = handlebarsUtils.options(this, locals, options); return micromatch.isMatch(files, patterns, opts); -}; +} /** * Alias for micromatch helper. Deprecated in v0.9.0. */ -helpers.mm = function() { +export function mm() { console.log('the {{mm}} helper is depcrecated and will be removed'); console.log('in handlebars-helpers v1.0.0, please use the {{match}}'); console.log('helper instead.'); - return helpers.match.apply(this, arguments); -}; + return match.apply(this, arguments); +} From a22f4875e775f103f5550ad12479633396b77246 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:30:00 +0100 Subject: [PATCH 24/46] Migrate and fix math --- index.mjs | 3 +- lib/index.mjs | 2 +- lib/{math.js => math.mjs} | 65 +++++++++++++++++++-------------------- test/examples/index.mjs | 10 ++---- 4 files changed, 37 insertions(+), 43 deletions(-) rename lib/{math.js => math.mjs} (88%) diff --git a/index.mjs b/index.mjs index 9f8204b5..c421d05f 100644 --- a/index.mjs +++ b/index.mjs @@ -44,10 +44,11 @@ export default function helpers(groups, options) { * Expose helper groups */ function exportGroup(group) { + group = {...group}; return function(options) { options = options || {}; var hbs = options.handlebars || options.hbs || Handlebars; - hbs.registerHelper({...group}); + hbs.registerHelper(group); return group; }; }; diff --git a/lib/index.mjs b/lib/index.mjs index 6d578210..6cc6a2b2 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -8,7 +8,7 @@ import * as html from './html.mjs'; import * as i18n from './i18n.mjs'; import * as inflection from './inflection.mjs'; import * as match from './match.mjs'; -import math from './math.js'; +import * as math from './math.mjs'; import misc from './misc.js'; import * as number from './number.mjs'; import * as object from './object.mjs'; diff --git a/lib/math.js b/lib/math.mjs similarity index 88% rename from lib/math.js rename to lib/math.mjs index 77884435..45422983 100644 --- a/lib/math.js +++ b/lib/math.mjs @@ -1,7 +1,6 @@ 'use strict'; -var utils = require('./utils'); -var helpers = module.exports; +import utils from './utils/index.js'; /** * Return the magnitude of `a`. @@ -12,12 +11,12 @@ var helpers = module.exports; * @example {{ abs 12012.1000 }} -> 12012.1 */ -helpers.abs = function(num) { +export function abs(num) { if (isNaN(num)) { throw new TypeError('expected a number'); } return Math.abs(num); -}; +} /** * Return the sum of `a` plus `b`. @@ -29,7 +28,7 @@ helpers.abs = function(num) { * @example {{ add 1 2 }} -> 3 */ -helpers.add = function(a, b) { +export function add(a, b) { if (!isNaN(a) && !isNaN(b)) { return Number(a) + Number(b); } @@ -37,7 +36,7 @@ helpers.add = function(a, b) { return a + b; } return ''; -}; +} /** * Returns the average of all numbers in the given array. @@ -53,12 +52,12 @@ helpers.add = function(a, b) { * @example {{ avg 1 2 3 4 5 }} -> 3 */ -helpers.avg = function() { +export function avg() { const args = [].concat.apply([], arguments); // remove handlebars options object args.pop(); - return helpers.sum(args) / args.length; -}; + return sum(args) / args.length; +} /** * Get the `Math.ceil()` of the given value. @@ -69,12 +68,12 @@ helpers.avg = function() { * @example {{ ceil 1.2 }} -> 2 */ -helpers.ceil = function(num) { +export function ceil(num) { if (isNaN(num)) { throw new TypeError('expected a number'); } return Math.ceil(num); -}; +} /** * Divide `a` by `b` @@ -85,7 +84,7 @@ helpers.ceil = function(num) { * @example {{ divide 10 5 }} -> 2 */ -helpers.divide = function(a, b) { +export function divide(a, b) { if (isNaN(a)) { throw new TypeError('expected the first argument to be a number'); } @@ -93,7 +92,7 @@ helpers.divide = function(a, b) { throw new TypeError('expected the second argument to be a number'); } return Number(a) / Number(b); -}; +} /** * Get the `Math.floor()` of the given value. @@ -104,12 +103,12 @@ helpers.divide = function(a, b) { * @example {{ floor 1.2 }} -> 1 */ -helpers.floor = function(num) { +export function floor(num) { if (isNaN(num)) { throw new TypeError('expected a number'); } return Math.floor(num); -}; +} /** * Return the difference of `a` minus `b`. @@ -121,7 +120,7 @@ helpers.floor = function(num) { * @example {{ minus 10 5 }} -> 5 */ -helpers.minus = function(a, b) { +export function minus(a, b) { if (isNaN(a)) { throw new TypeError('expected the first argument to be a number'); } @@ -129,7 +128,7 @@ helpers.minus = function(a, b) { throw new TypeError('expected the second argument to be a number'); } return Number(a) - Number(b); -}; +} /** * Get the remainder of a division operation. @@ -141,7 +140,7 @@ helpers.minus = function(a, b) { * @example {{ modulo 10 5 }} -> 0 */ -helpers.modulo = function(a, b) { +export function modulo(a, b) { if (isNaN(a)) { throw new TypeError('expected the first argument to be a number'); } @@ -149,7 +148,7 @@ helpers.modulo = function(a, b) { throw new TypeError('expected the second argument to be a number'); } return Number(a) % Number(b); -}; +} /** * Multiply number `a` by number `b`. @@ -162,7 +161,7 @@ helpers.modulo = function(a, b) { * @example {{ multiply 10 5 }} -> 50 */ -helpers.multiply = function(a, b) { +export function multiply(a, b) { if (isNaN(a)) { throw new TypeError('expected the first argument to be a number'); } @@ -170,7 +169,7 @@ helpers.multiply = function(a, b) { throw new TypeError('expected the second argument to be a number'); } return Number(a) * Number(b); -}; +} /** * Add `a` by `b`. @@ -181,7 +180,7 @@ helpers.multiply = function(a, b) { * @example {{ plus 10 5 }} -> 15 */ -helpers.plus = function(a, b) { +export function plus(a, b) { if (isNaN(a)) { throw new TypeError('expected the first argument to be a number'); } @@ -189,7 +188,7 @@ helpers.plus = function(a, b) { throw new TypeError('expected the second argument to be a number'); } return Number(a) + Number(b); -}; +} /** * Generate a random number between two values @@ -201,7 +200,7 @@ helpers.plus = function(a, b) { * @example {{ random 0 20 }} -> 10 */ -helpers.random = function(min, max) { +export function random(min, max) { if (isNaN(min)) { throw new TypeError('expected minimum to be a number'); } @@ -209,7 +208,7 @@ helpers.random = function(min, max) { throw new TypeError('expected maximum to be a number'); } return utils.random(min, max); -}; +} /** * Get the remainder when `a` is divided by `b`. @@ -220,9 +219,9 @@ helpers.random = function(min, max) { * @example {{ remainder 10 6 }} -> 4 */ -helpers.remainder = function(a, b) { +export function remainder(a, b) { return a % b; -}; +} /** * Round the given number. @@ -233,12 +232,12 @@ helpers.remainder = function(a, b) { * @example {{ round 10.3 }} -> 10 */ -helpers.round = function(num) { +export function round(num) { if (isNaN(num)) { throw new TypeError('expected a number'); } return Math.round(num); -}; +} /** * Return the product of `a` minus `b`. @@ -251,7 +250,7 @@ helpers.round = function(num) { * @example {{ subtract 10 5 }} -> 5 */ -helpers.subtract = function(a, b) { +export function subtract(a, b) { if (isNaN(a)) { throw new TypeError('expected the first argument to be a number'); } @@ -259,7 +258,7 @@ helpers.subtract = function(a, b) { throw new TypeError('expected the second argument to be a number'); } return Number(a) - Number(b); -}; +} /** * Returns the sum of all numbers in the given array. @@ -274,7 +273,7 @@ helpers.subtract = function(a, b) { * @example {{ sum [1, 2, 3] }} -> 6 */ -helpers.sum = function() { +export function sum() { var args = [].concat.apply([], arguments); var len = args.length; var sum = 0; @@ -285,4 +284,4 @@ helpers.sum = function() { } } return sum; -}; +} diff --git a/test/examples/index.mjs b/test/examples/index.mjs index 92c93541..38b0d0bc 100644 --- a/test/examples/index.mjs +++ b/test/examples/index.mjs @@ -3,17 +3,11 @@ import 'mocha'; -import { restore, stub } from 'sinon'; -import {uuid} from '../../lib/uuid.mjs'; -import math from '../../lib/math.js'; - -restore(); -stub({uuid}, 'uuid').returns('f34ebc66-93bd-4f7c-b79b-92b5569138bc'); -stub(math, 'random').returns(10); - import { equal } from 'assert'; import lib from '../../lib/index.mjs'; +import * as math from '../../lib/math.mjs'; lib.uuid = () => 'f34ebc66-93bd-4f7c-b79b-92b5569138bc'; +lib.math = () => ({...math, random: () => 10}); import { readFileSync, existsSync } from 'fs'; import { parse } from 'doctrine'; From fccb815108c20a35719318b8678adc19f81d372e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:30:06 +0100 Subject: [PATCH 25/46] Remove sinon --- package.json | 1 - yarn.lock | 85 +--------------------------------------------------- 2 files changed, 1 insertion(+), 85 deletions(-) diff --git a/package.json b/package.json index 696e0aa3..45c48652 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,6 @@ "js-yaml": "^4.1.0", "markdown-link": "^0.1.1", "mocha": "^8.4.0", - "sinon": "^17.0.1", "template-helpers": "^1.0.1", "through2": "^4.0.2", "verb": "^0.8.10", diff --git a/yarn.lock b/yarn.lock index 61698bc1..c0229e5e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -74,41 +74,6 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@sinonjs/commons@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-2.0.0.tgz#fd4ca5b063554307e8327b4564bd56d3b73924a3" - integrity sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg== - dependencies: - type-detect "4.0.8" - -"@sinonjs/commons@^3.0.0": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.1.tgz#1029357e44ca901a615585f6d27738dbc89084cd" - integrity sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ== - dependencies: - type-detect "4.0.8" - -"@sinonjs/fake-timers@^11.2.2": - version "11.2.2" - resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz#50063cc3574f4a27bd8453180a04171c85cc9699" - integrity sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw== - dependencies: - "@sinonjs/commons" "^3.0.0" - -"@sinonjs/samsam@^8.0.0": - version "8.0.0" - resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-8.0.0.tgz#0d488c91efb3fa1442e26abea81759dfc8b5ac60" - integrity sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew== - dependencies: - "@sinonjs/commons" "^2.0.0" - lodash.get "^4.4.2" - type-detect "^4.0.8" - -"@sinonjs/text-encoding@^0.7.2": - version "0.7.2" - resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz#5981a8db18b56ba38ef0efb7d995b12aa7b51918" - integrity sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ== - "@ungap/promise-all-settled@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" @@ -1690,11 +1655,6 @@ diff@^2.0.2: resolved "https://registry.yarnpkg.com/diff/-/diff-2.2.3.tgz#60eafd0d28ee906e4e8ff0a52c1229521033bf99" integrity sha1-YOr9DSjukG5Oj/ClLBIpUhAzv5k= -diff@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-5.1.0.tgz#bc52d298c5ea8df9194800224445ed43ffc87e40" - integrity sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw== - doctrine@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961" @@ -4067,11 +4027,6 @@ just-debounce@^1.0.0: resolved "https://registry.yarnpkg.com/just-debounce/-/just-debounce-1.1.0.tgz#2f81a3ad4121a76bc7cb45dbf704c0d76a8e5ddf" integrity sha512-qpcRocdkUmf+UTNBYx5w6dexX5J31AKK1OmPwH630a83DdVVUIngk55RSAiIGpQyoH0dlr872VHfPjnQnK1qDQ== -just-extend@^6.2.0: - version "6.2.0" - resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-6.2.0.tgz#b816abfb3d67ee860482e7401564672558163947" - integrity sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw== - keyv@^4.5.3: version "4.5.4" resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.4.tgz#a879a99e29452f942439f2a405e3af8b31d4de93" @@ -4433,11 +4388,6 @@ lodash.escape@^3.0.0: dependencies: lodash._root "^3.0.0" -lodash.get@^4.4.2: - version "4.4.2" - resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" - integrity sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ== - lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" @@ -5126,17 +5076,6 @@ next-tick@~1.0.0: resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c" integrity sha1-yobR/ogoFpsBICCOPchCS524NCw= -nise@^5.1.5: - version "5.1.7" - resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.7.tgz#03ca96539efb306612eb60a8c5d6beeb208e27e5" - integrity sha512-wWtNUhkT7k58uvWTB/Gy26eA/EJKtPZFVAhEilN5UYVmmGRYOURbejRUyKm0Uu9XVEW7K5nBOZfR8VMB4QR2RQ== - dependencies: - "@sinonjs/commons" "^3.0.0" - "@sinonjs/fake-timers" "^11.2.2" - "@sinonjs/text-encoding" "^0.7.2" - just-extend "^6.2.0" - path-to-regexp "^6.2.1" - no-case@^2.2.0: version "2.3.2" resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac" @@ -5676,11 +5615,6 @@ path-to-regexp@^1.0.3: dependencies: isarray "0.0.1" -path-to-regexp@^6.2.1: - version "6.2.1" - resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.1.tgz#d54934d6798eb9e5ef14e7af7962c945906918e5" - integrity sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw== - path-type@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441" @@ -6442,18 +6376,6 @@ simple-get@^2.5.1: once "^1.3.1" simple-concat "^1.0.0" -sinon@^17.0.1: - version "17.0.1" - resolved "https://registry.yarnpkg.com/sinon/-/sinon-17.0.1.tgz#26b8ef719261bf8df43f925924cccc96748e407a" - integrity sha512-wmwE19Lie0MLT+ZYNpDymasPHUKTaZHUH/pKEubRXIzySv9Atnlw+BUMGCzWgV7b7wO+Hw6f1TEOr0IUnmU8/g== - dependencies: - "@sinonjs/commons" "^3.0.0" - "@sinonjs/fake-timers" "^11.2.2" - "@sinonjs/samsam" "^8.0.0" - diff "^5.1.0" - nise "^5.1.5" - supports-color "^7.2.0" - snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" @@ -6775,7 +6697,7 @@ supports-color@^5.3.0: dependencies: has-flag "^3.0.0" -supports-color@^7.1.0, supports-color@^7.2.0: +supports-color@^7.1.0: version "7.2.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== @@ -7114,11 +7036,6 @@ type-check@^0.4.0, type-check@~0.4.0: dependencies: prelude-ls "^1.2.1" -type-detect@4.0.8, type-detect@^4.0.8: - version "4.0.8" - resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" - integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== - type-fest@^0.20.2: version "0.20.2" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4" From 78a43f1c59c1f8be727d41b7e71432ebd7b53ce0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:36:27 +0100 Subject: [PATCH 26/46] More conversions --- lib/index.mjs | 6 +++--- lib/{misc.js => misc.mjs} | 29 +++++++++++++++-------------- lib/{path.js => path.mjs} | 25 ++++++++++++------------- lib/{regex.js => regex.mjs} | 14 +++++++------- lib/utils/index.js | 1 + 5 files changed, 38 insertions(+), 37 deletions(-) rename lib/{misc.js => misc.mjs} (76%) rename lib/{path.js => path.mjs} (87%) rename lib/{regex.js => regex.mjs} (83%) diff --git a/lib/index.mjs b/lib/index.mjs index 6cc6a2b2..8a6e44eb 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -9,11 +9,11 @@ import * as i18n from './i18n.mjs'; import * as inflection from './inflection.mjs'; import * as match from './match.mjs'; import * as math from './math.mjs'; -import misc from './misc.js'; +import * as misc from './misc.mjs'; import * as number from './number.mjs'; import * as object from './object.mjs'; -import path from './path.js'; -import regex from './regex.js'; +import * as path from './path.mjs'; +import * as regex from './regex.mjs'; import * as string from './string.mjs'; import url from './url.js'; import * as uuid from './uuid.mjs'; diff --git a/lib/misc.js b/lib/misc.mjs similarity index 76% rename from lib/misc.js rename to lib/misc.mjs index 79110038..06df0996 100644 --- a/lib/misc.js +++ b/lib/misc.mjs @@ -1,15 +1,16 @@ 'use strict'; -var util = require('./utils/handlebarsUtils'); -var helpers = module.exports; -const getValue = require('get-value'); -const createFrame = require('./utils/createFrame'); +import handlebarsUtils from './utils/handlebarsUtils.js'; +const { options: _options } = handlebarsUtils; + +import getValue from 'get-value'; +import createFrame from './utils/createFrame.js'; /** * Block helper for exposing private `@` variables on the context */ -helpers.frame = function(context, options) { +export function frame(context, options) { if (typeof(context) === 'object' && context.hash) { options = context; context = options.data; @@ -23,7 +24,7 @@ helpers.frame = function(context, options) { // extend the frame with hash arguments frame.extend(options.hash); return options.fn(this, { data: frame }); -}; +} /** * Return the given value of `prop` from `this.options`. @@ -38,9 +39,9 @@ helpers.frame = function(context, options) { * @api public */ -helpers.option = function(prop, locals, options) { - return getValue(util.options(this, locals, options), prop); -}; +export function option(prop, locals, options) { + return getValue(_options(this, locals, options), prop); +} /** * Block helper that renders the block without taking any arguments. @@ -51,9 +52,9 @@ helpers.option = function(prop, locals, options) { * @api public */ -helpers.noop = function(options) { +export function noop(options) { return options.fn(this); -}; +} /** * Get the native type of the given `value` @@ -71,7 +72,7 @@ helpers.noop = function(options) { * @api public */ -helpers.typeOf = function(val) { return typeof val; }; +export function typeOf(val) { return typeof val; } /** * Block helper that builds the context for the block @@ -83,10 +84,10 @@ helpers.typeOf = function(val) { return typeof val; }; * @api public */ -helpers.withHash = function(options) { +export function withHash(options) { if (options.hash && Object.keys(options.hash).length) { return options.fn(options.hash); } else { return options.inverse(this); } -}; +} diff --git a/lib/path.js b/lib/path.mjs similarity index 87% rename from lib/path.js rename to lib/path.mjs index 6af69c4e..94aa8270 100644 --- a/lib/path.js +++ b/lib/path.mjs @@ -1,9 +1,8 @@ 'use strict'; -var util = require('./utils/handlebarsUtils'); -var path = require('path'); -const relative = require('relative'); -var helpers = module.exports; +import util from './utils/handlebarsUtils.js'; +import path from 'path'; +import _relative from 'relative'; /** * Get the directory path segment from the given `filepath`. @@ -17,7 +16,7 @@ var helpers = module.exports; * @api public */ -helpers.absolute = function(filepath, options) { +export const absolute = function(filepath, options) { options = options || { data: {} }; var context = util.options(this, options); var ctx = Object.assign({}, options.data.root, context); @@ -37,7 +36,7 @@ helpers.absolute = function(filepath, options) { * @api public */ -helpers.dirname = function(filepath, options) { +export const dirname = function(filepath, options) { if (typeof filepath !== 'string') { throw new TypeError(util.expectedType('filepath', 'string', filepath)); } @@ -56,14 +55,14 @@ helpers.dirname = function(filepath, options) { * @api public */ -helpers.relative = function(a, b) { +export const relative = function(a, b) { if (typeof a !== 'string') { throw new TypeError(util.expectedType('first path', 'string', a)); } if (typeof b !== 'string') { throw new TypeError(util.expectedType('second path', 'string', b)); } - return relative(a, b); + return _relative(a, b); }; /** @@ -78,7 +77,7 @@ helpers.relative = function(a, b) { * @api public */ -helpers.basename = function(filepath) { +export const basename = function(filepath) { if (typeof filepath !== 'string') { throw new TypeError(util.expectedType('filepath', 'string', filepath)); } @@ -97,7 +96,7 @@ helpers.basename = function(filepath) { * @api public */ -helpers.stem = function(filepath) { +export const stem = function(filepath) { if (typeof filepath !== 'string') { throw new TypeError(util.expectedType('filepath', 'string', filepath)); } @@ -116,7 +115,7 @@ helpers.stem = function(filepath) { * @api public */ -helpers.extname = function(filepath) { +export const extname = function(filepath) { if (typeof filepath !== 'string') { throw new TypeError(util.expectedType('filepath', 'string', filepath)); } @@ -135,7 +134,7 @@ helpers.extname = function(filepath) { * @api public */ -helpers.resolve = function(filepath) { +export const resolve = function(filepath) { var args = [].slice.call(arguments); var opts = util.options(this, args.pop()); var cwd = path.resolve(opts.cwd || process.cwd()); @@ -163,7 +162,7 @@ helpers.resolve = function(filepath) { * @api public */ -helpers.segments = function(filepath, a, b) { +export const segments = function(filepath, a, b) { if (typeof filepath !== 'string') { throw new TypeError(util.expectedType('filepath', 'string', filepath)); } diff --git a/lib/regex.js b/lib/regex.mjs similarity index 83% rename from lib/regex.js rename to lib/regex.mjs index 5cba5f6d..f3837b46 100644 --- a/lib/regex.js +++ b/lib/regex.mjs @@ -1,8 +1,8 @@ 'use strict'; -var util = { options: require('./utils/options') }; -var helpers = module.exports; -const kindOf = require('kind-of'); +import util from './utils/index.js'; + +import kindOf from 'kind-of'; /** * Convert the given string to a regular expression. @@ -17,10 +17,10 @@ const kindOf = require('kind-of'); * @example {{toRegex 'foo'}} -> /foo/ */ -helpers.toRegex = function(str, locals, options) { +export function toRegex(str, locals, options) { var opts = util.options({}, locals, options); return new RegExp(str, opts.flags); -}; +} /** * Returns true if the given `str` matches the given regex. A regex can @@ -41,7 +41,7 @@ helpers.toRegex = function(str, locals, options) { * @example {{test 'foobar' (toRegex 'foo')}} -> true */ -helpers.test = function(str, regex) { +export function test(str, regex) { if (typeof(str) !== 'string') { return false; } @@ -49,4 +49,4 @@ helpers.test = function(str, regex) { throw new TypeError('expected a regular expression'); } return regex.test(str); -}; +} diff --git a/lib/utils/index.js b/lib/utils/index.js index 7952773f..2c5eded5 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -85,3 +85,4 @@ exports.fn = require('./fn'); exports.isObject = require('./isObject'); exports.inverse = require('./inverse'); exports.isUndefined = require('./isUndefined'); +exports.options = require('./options'); From 0ddfa0093f01cfc4324837da97f3c11d6ce0fb35 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:37:31 +0100 Subject: [PATCH 27/46] Migrate url --- lib/index.mjs | 2 +- lib/{url.js => url.mjs} | 45 +++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 25 deletions(-) rename lib/{url.js => url.mjs} (81%) diff --git a/lib/index.mjs b/lib/index.mjs index 8a6e44eb..f426b5ce 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -15,7 +15,7 @@ import * as object from './object.mjs'; import * as path from './path.mjs'; import * as regex from './regex.mjs'; import * as string from './string.mjs'; -import url from './url.js'; +import * as url from './url.mjs'; import * as uuid from './uuid.mjs'; export default { diff --git a/lib/url.js b/lib/url.mjs similarity index 81% rename from lib/url.js rename to lib/url.mjs index 5ee2496a..95c5459f 100644 --- a/lib/url.js +++ b/lib/url.mjs @@ -1,11 +1,8 @@ 'use strict'; -var url = require('url'); -var util = { - isString: require('./utils/isString') -}; -var querystring = require('querystring'); -var helpers = module.exports; +import { resolve, parse } from 'url'; +import util from './utils/index.js'; +import * as qs from 'querystring'; /** * Encodes a Uniform Resource Identifier (URI) component @@ -19,11 +16,11 @@ var helpers = module.exports; * @example {{ encodeURI 'https://myurl?Hello There' }} -> https%3A%2F%2Fmyurl%3FHello%20There */ -helpers.encodeURI = function(str) { +export function encodeURI(str) { if (util.isString(str)) { return encodeURIComponent(str); } -}; +} /** * Escape the given string by replacing characters with escape sequences. @@ -35,11 +32,11 @@ helpers.encodeURI = function(str) { * @example {{ escape 'https://myurl?Hello+There' }} -> https%3A%2F%2Fmyurl%3FHello%2BThere */ -helpers.escape = function(str) { +export function escape(str) { if (util.isString(str)) { - return querystring.escape(str); + return qs.escape(str); } -}; +} /** * Decode a Uniform Resource Identifier (URI) component. @@ -50,11 +47,11 @@ helpers.escape = function(str) { * @example {{ decodeURI 'https://myurl?Hello%20There' }} -> https://myurl?Hello There */ -helpers.decodeURI = function(str) { +export function decodeURI(str) { if (util.isString(str)) { return decodeURIComponent(str); } -}; +} /** * Take a base URL, and a href URL, and resolve them as a @@ -67,9 +64,9 @@ helpers.decodeURI = function(str) { * @example {{ urlResolve 'https://myurl' '/api/test' }} -> https://myurl/api/test */ -helpers.urlResolve = function(base, href) { - return url.resolve(base, href); -}; +export function urlResolve(base, href) { + return resolve(base, href); +} /** * Parses a `url` string into an object. @@ -80,9 +77,9 @@ helpers.urlResolve = function(base, href) { * @example {{ urlParse 'https://myurl/api/test' }} */ -helpers.urlParse = function(str) { - return url.parse(str); -}; +export function urlParse(str) { + return parse(str); +} /** * Strip the query string from the given `url`. @@ -93,11 +90,11 @@ helpers.urlParse = function(str) { * @example {{ stripQuerystring 'https://myurl/api/test?foo=bar' }} -> 'https://myurl/api/test' */ -helpers.stripQuerystring = function(str) { +export function stripQuerystring(str) { if (util.isString(str)) { return str.split('?')[0]; } -}; +} /** * Strip protocol from a `url`. Useful for displaying media that @@ -114,10 +111,10 @@ helpers.stripQuerystring = function(str) { * @example {{ stripProtocol 'https://myurl/api/test' }} -> '//myurl/api/test' */ -helpers.stripProtocol = function(str) { +export function stripProtocol(str) { if (util.isString(str)) { - var parsed = url.parse(str); + var parsed = parse(str); parsed.protocol = ''; return parsed.format(); } -}; +} From 2a1f618f38307c32f9b0c9eabc8efcb3cb91922a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:42:56 +0100 Subject: [PATCH 28/46] Migrate utils/index --- index.mjs | 2 +- lib/comparison.mjs | 2 +- lib/math.mjs | 2 +- lib/number.mjs | 2 +- lib/regex.mjs | 2 +- lib/string.mjs | 2 +- lib/url.mjs | 2 +- lib/utils/{index.js => index.mjs} | 43 +++++++++++++++++++------------ test/utils.mjs | 2 +- 9 files changed, 34 insertions(+), 25 deletions(-) rename lib/utils/{index.js => index.mjs} (65%) diff --git a/index.mjs b/index.mjs index c421d05f..25514d1f 100644 --- a/index.mjs +++ b/index.mjs @@ -71,5 +71,5 @@ export const string = exportGroup(lib.string); export const url = exportGroup(lib.url); export const uuid = exportGroup(lib.uuid); -import * as _utils from './lib/utils/index.js'; +import * as _utils from './lib/utils/index.mjs'; export const utils = _utils; diff --git a/lib/comparison.mjs b/lib/comparison.mjs index 28e55ba5..eb21fae3 100644 --- a/lib/comparison.mjs +++ b/lib/comparison.mjs @@ -2,7 +2,7 @@ import has from 'has-value'; -import util from './utils/index.js'; +import * as util from './utils/index.mjs'; import falsey from './utils/falsey.js'; import isOdd from './utils/odd.js'; diff --git a/lib/math.mjs b/lib/math.mjs index 45422983..ee11e976 100644 --- a/lib/math.mjs +++ b/lib/math.mjs @@ -1,6 +1,6 @@ 'use strict'; -import utils from './utils/index.js'; +import * as utils from './utils/index.mjs'; /** * Return the magnitude of `a`. diff --git a/lib/number.mjs b/lib/number.mjs index a72c1643..ecead6bf 100644 --- a/lib/number.mjs +++ b/lib/number.mjs @@ -1,6 +1,6 @@ 'use strict'; -import util from './utils/index.js'; +import * as util from './utils/index.mjs'; /** * Format a number to it's equivalent in bytes. If a string is passed, diff --git a/lib/regex.mjs b/lib/regex.mjs index f3837b46..facedabe 100644 --- a/lib/regex.mjs +++ b/lib/regex.mjs @@ -1,6 +1,6 @@ 'use strict'; -import util from './utils/index.js'; +import * as util from './utils/index.mjs'; import kindOf from 'kind-of'; diff --git a/lib/string.mjs b/lib/string.mjs index 066dd8c5..03c90040 100644 --- a/lib/string.mjs +++ b/lib/string.mjs @@ -8,7 +8,7 @@ const util = { isObject: utilIsObject, options: utilOptions }; -import utils from './utils/index.js'; +import * as utils from './utils/index.mjs'; import loremText from './utils/lorem.js'; /** diff --git a/lib/url.mjs b/lib/url.mjs index 95c5459f..43289bde 100644 --- a/lib/url.mjs +++ b/lib/url.mjs @@ -1,7 +1,7 @@ 'use strict'; import { resolve, parse } from 'url'; -import util from './utils/index.js'; +import * as util from './utils/index.mjs'; import * as qs from 'querystring'; /** diff --git a/lib/utils/index.js b/lib/utils/index.mjs similarity index 65% rename from lib/utils/index.js rename to lib/utils/index.mjs index 2c5eded5..a4fcd354 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.mjs @@ -10,12 +10,12 @@ * @return {Boolean} */ -exports.contains = function(val, obj, start) { +export function contains(val, obj, start) { if (val == null || obj == null || isNaN(val.length)) { return false; } return val.indexOf(obj, start) !== -1; -}; +} /** * Remove leading and trailing whitespace and non-word @@ -25,11 +25,11 @@ exports.contains = function(val, obj, start) { * @return {String} */ -exports.chop = function(str) { +export function chop(str) { if (typeof(str) !== 'string') return ''; var re = /^[-_.\W\s]+|[-_.\W\s]+$/g; return str.trim().replace(re, ''); -}; +} /** * Change casing on the given `string`, optionally @@ -48,13 +48,13 @@ exports.chop = function(str) { * @api public */ -exports.changecase = function(str, fn) { +export function changecase(str, fn) { if (typeof(str) !== 'string') return ''; if (str.length === 1) { return str.toLowerCase(); } - str = exports.chop(str).toLowerCase(); + str = chop(str).toLowerCase(); if (typeof fn !== 'function') { fn = (val) => val; } @@ -63,7 +63,7 @@ exports.changecase = function(str, fn) { return str.replace(re, function(_, ch) { return fn(ch); }); -}; +} /** * Generate a random number @@ -74,15 +74,24 @@ exports.changecase = function(str, fn) { * @api public */ -exports.random = function(min, max) { +export function random(min, max) { return min + Math.floor(Math.random() * (max - min + 1)); -}; +} -exports.isOptions = require('./isOptions'); -exports.value = require('./value'); -exports.isString = require('./isString'); -exports.fn = require('./fn'); -exports.isObject = require('./isObject'); -exports.inverse = require('./inverse'); -exports.isUndefined = require('./isUndefined'); -exports.options = require('./options'); +import _isOptions from './isOptions.js'; +import _value from './value.js'; +import _isString from './isString.js'; +import _fn from './fn.js'; +import _isObject from './isObject.js'; +import _inverse from './inverse.js'; +import _isUndefined from './isUndefined.js'; +import _options from './options.js'; + +export const isOptions = _isOptions; +export const value = _value; +export const isString = _isString; +export const fn = _fn; +export const isObject = _isObject; +export const inverse = _inverse; +export const isUndefined = _isUndefined; +export const options = _options; diff --git a/test/utils.mjs b/test/utils.mjs index 624ef906..5544be95 100644 --- a/test/utils.mjs +++ b/test/utils.mjs @@ -2,7 +2,7 @@ import 'mocha'; import { equal } from 'assert'; -import { chop, changecase } from '../lib/utils/index.js'; +import { chop, changecase } from '../lib/utils/index.mjs'; import { condense, padcomments, parseAttributes, toAttributes } from '../lib/utils/html.js'; describe('utils', function() { From ed657216ce0868aac4b40a72dd64e21e84993359 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:45:59 +0100 Subject: [PATCH 29/46] More conversions --- lib/array.mjs | 2 +- lib/misc.mjs | 2 +- lib/object.mjs | 2 +- lib/utils/{createFrame.js => createFrame.mjs} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename lib/utils/{createFrame.js => createFrame.mjs} (90%) diff --git a/lib/array.mjs b/lib/array.mjs index c1d2c040..0c61f9e1 100644 --- a/lib/array.mjs +++ b/lib/array.mjs @@ -18,7 +18,7 @@ const util = { isObject }; import getValue from 'get-value'; -import createFrame from './utils/createFrame.js'; +import createFrame from './utils/createFrame.mjs'; /** * Returns all of the items in an array after the specified index. diff --git a/lib/misc.mjs b/lib/misc.mjs index 06df0996..fb2f87ff 100644 --- a/lib/misc.mjs +++ b/lib/misc.mjs @@ -4,7 +4,7 @@ import handlebarsUtils from './utils/handlebarsUtils.js'; const { options: _options } = handlebarsUtils; import getValue from 'get-value'; -import createFrame from './utils/createFrame.js'; +import createFrame from './utils/createFrame.mjs'; /** * Block helper for exposing private `@` variables on the context diff --git a/lib/object.mjs b/lib/object.mjs index f1dba2ae..1385d86a 100644 --- a/lib/object.mjs +++ b/lib/object.mjs @@ -12,7 +12,7 @@ import { arrayify } from './array.mjs'; import getValue from 'get-value'; import getObject from 'get-object'; -import createFrame from './utils/createFrame.js'; +import createFrame from './utils/createFrame.mjs'; /** * Extend the context with the properties of other objects. diff --git a/lib/utils/createFrame.js b/lib/utils/createFrame.mjs similarity index 90% rename from lib/utils/createFrame.js rename to lib/utils/createFrame.mjs index ba552b11..88c9be03 100644 --- a/lib/utils/createFrame.js +++ b/lib/utils/createFrame.mjs @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function createFrame(data) { +export default function createFrame(data) { if (typeof(data) !== 'object') { throw new TypeError('createFrame expects data to be an object'); } From be1cda5732e764ba99ac719525a5967a290800f2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Dec 2024 17:49:27 +0100 Subject: [PATCH 30/46] More conversions --- lib/comparison.mjs | 2 +- lib/utils/{falsey.js => falsey.mjs} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename lib/utils/{falsey.js => falsey.mjs} (95%) diff --git a/lib/comparison.mjs b/lib/comparison.mjs index eb21fae3..e828d2c0 100644 --- a/lib/comparison.mjs +++ b/lib/comparison.mjs @@ -3,7 +3,7 @@ import has from 'has-value'; import * as util from './utils/index.mjs'; -import falsey from './utils/falsey.js'; +import falsey from './utils/falsey.mjs'; import isOdd from './utils/odd.js'; /** diff --git a/lib/utils/falsey.js b/lib/utils/falsey.mjs similarity index 95% rename from lib/utils/falsey.js rename to lib/utils/falsey.mjs index a0e43f85..546240f0 100644 --- a/lib/utils/falsey.js +++ b/lib/utils/falsey.mjs @@ -36,4 +36,4 @@ falsey.keywords = [ 'zero' ]; -module.exports = falsey; +export default falsey; From 434bbd60e798063bfcd9f20bffbbe24b008e3132 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 4 Dec 2024 10:04:57 +0100 Subject: [PATCH 31/46] Migrate html --- lib/html.mjs | 2 +- lib/utils/{html.js => html.mjs} | 28 +++++++++++++++------------- test/utils.mjs | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) rename lib/utils/{html.js => html.mjs} (77%) diff --git a/lib/html.mjs b/lib/html.mjs index 6011ac9e..32525b0b 100644 --- a/lib/html.mjs +++ b/lib/html.mjs @@ -2,7 +2,7 @@ import { extname, posix } from 'path'; import handlebarsUtils from './utils/handlebarsUtils.js'; -import { parseAttributes, sanitize as htmlSanitize } from './utils/html.js'; +import { parseAttributes, sanitize as htmlSanitize } from './utils/html.mjs'; var parseAttr = parseAttributes; import htmlTag from 'html-tag'; diff --git a/lib/utils/html.js b/lib/utils/html.mjs similarity index 77% rename from lib/utils/html.js rename to lib/utils/html.mjs index 92b2a09b..b23aa4ab 100644 --- a/lib/utils/html.js +++ b/lib/utils/html.mjs @@ -1,7 +1,9 @@ 'use strict'; -var util = require('./handlebarsUtils'); -var striptags = require('striptags'); +import utils from './handlebarsUtils.js'; +import striptags from 'striptags'; + +const { isString } = utils; /** * Remove extra newlines from HTML, respect indentation. @@ -11,9 +13,9 @@ var striptags = require('striptags'); * @api public */ -module.exports.condense = function(str) { +export function condense(str) { return str.replace(/(\r\n|\r|\n|\u2028|\u2029) {2,}/g, '\n'); -}; +} /** * Add a single newline above code comments in HTML @@ -23,9 +25,9 @@ module.exports.condense = function(str) { * @api public */ -module.exports.padcomments = function(str) { +export function padcomments(str) { return str.replace(/(\s*