feature: client: dom: migrate to ESM

This commit is contained in:
coderiaser 2026-01-29 16:04:43 +02:00
parent 9d2c4e4a0d
commit f9c2831939
20 changed files with 211 additions and 178 deletions

View file

@ -1,9 +1,8 @@
'use strict';
import exec from 'execon';
const exec = require('execon');
const isString = (a) => typeof a === 'string';
module.exports.escapeRegExp = (str) => {
export const escapeRegExp = (str) => {
const isStr = isString(str);
if (isStr)
@ -15,7 +14,7 @@ module.exports.escapeRegExp = (str) => {
/**
* get regexp from wild card
*/
module.exports.getRegExp = (wildcard) => {
export const getRegExp = (wildcard) => {
const escaped = `^${wildcard // search from start of line
.replace(/\./g, '\\.')
.replace(/\*/g, '.*')
@ -25,14 +24,13 @@ module.exports.getRegExp = (wildcard) => {
return RegExp(escaped);
};
module.exports.exec = exec;
/**
* function gets file extension
*
* @param name
* @return ext
*/
module.exports.getExt = (name) => {
export const getExt = (name) => {
const isStr = isString(name);
if (!isStr)
@ -52,7 +50,7 @@ module.exports.getExt = (name) => {
* @param array
* @param name
*/
module.exports.findObjByNameInArr = (array, name) => {
export const findObjByNameInArr = (array, name) => {
let ret;
if (!Array.isArray(array))
@ -90,7 +88,7 @@ module.exports.findObjByNameInArr = (array, name) => {
* start timer
* @param name
*/
module.exports.time = (name) => {
export const time = (name) => {
exec.ifExist(console, 'time', [name]);
};
@ -98,6 +96,6 @@ module.exports.time = (name) => {
* stop timer
* @param name
*/
module.exports.timeEnd = (name) => {
export const timeEnd = (name) => {
exec.ifExist(console, 'timeEnd', [name]);
};

View file

@ -1,19 +1,16 @@
'use strict';
const test = require('supertape');
const {tryCatch} = require('try-catch');
const Util = require('./util');
const {
import test from 'supertape';
import {tryCatch} from 'try-catch';
import {
findObjByNameInArr,
getRegExp,
escapeRegExp,
} = Util;
getExt,
} from '#common/util';
test('getExt: no extension', (t) => {
const EXT = '';
const name = 'file-withot-extension';
const ext = Util.getExt(name);
const name = 'file-without-extension';
const ext = getExt(name);
t.equal(ext, EXT, 'should return "" when extension is none');
t.end();
@ -22,14 +19,14 @@ test('getExt: no extension', (t) => {
test('getExt: return extension', (t) => {
const EXT = '.png';
const name = 'picture.png';
const ext = Util.getExt(name);
const ext = getExt(name);
t.equal(ext, EXT, 'should return ".png" in files "picture.png"');
t.end();
});
test('util: getExt: no name', (t) => {
const ext = Util.getExt();
const ext = getExt();
t.equal(ext, '', 'should return empty string');
t.end();