Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Merge pull request #34 from iLib-js/convertToJest
Browse files Browse the repository at this point in the history
Convert to jest
  • Loading branch information
ehoogerbeets authored Feb 1, 2024
2 parents 5e546e5 + d9506a7 commit f357dca
Show file tree
Hide file tree
Showing 168 changed files with 12,341 additions and 12,149 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ workflows:
test-all-node-versions:
jobs:
- test:
docker_image: circleci/node:12-browsers
docker_image: cimg/node:14.21-browsers
- test:
docker_image: circleci/node:13-browsers
docker_image: cimg/node:16.20-browsers
- test:
docker_image: circleci/node:14-browsers
docker_image: cimg/node:18.9-browsers
- test:
docker_image: circleci/node:16-browsers
docker_image: cimg/node:20.9-browsers
- test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ CalendarFactoryAsync({locale: 'ja-JP'}).then(function(cal) {

## License

Copyright © 2019-2023, JEDLSoft
Copyright © 2019-2024, JEDLSoft

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@
"type": "git",
"url": "[email protected]:iLib-js/ilib-es6.git"
},
"engines": {
"node": ">= 14.0.0"
},
"scripts": {
"build": "npm run build:prod",
"dist": "npm pack",
"test": "LANG=en_US.UTF8 node test/testSuite.js",
"debug": "node --inspect-brk test/testSuite.js",
"test": "npm run test:cli",
"test:cli": "LANG=en_US.UTF8 node --experimental-vm-modules node_modules/.bin/jest --testEnvironment node",
"test:watch": "LANG=en_US.UTF8 node --experimental-vm-modules node_modules/.bin/jest --testEnvironment node --watch",
"debug": "npm run build:dev ; node --experimental-vm-modules --inspect-brk node_modules/.bin/jest --testEnvironment node -i",
"clean": "git clean -f -d * ; rm -rf lib"
},
"dependencies": {
"ilib": "14.19.0"
},
"devDependencies": {
"assertextras": "^1.1.0",
"nodeunit": "^0.11.3"
"jest": "^29.7.0",
"npm-run-all": "^4.1.5"
}
}
4 changes: 2 additions & 2 deletions src/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Address.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -28,7 +28,7 @@ export default class Address {
}

static create(address, options = {}) {
return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { address } = opts;
return new ilibAddress(address, opts);
}, Object.assign({}, options, {
Expand Down
8 changes: 4 additions & 4 deletions src/AddressFmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* AddressFmt.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,12 +26,12 @@ function wrapGetFormatInfo(formatter) {
if (!formatter) return;

const oldGetFormatInfo = ilibAddressFmt.prototype.getFormatInfo.bind(formatter);
formatter.getFormatInfo = function(locale, sync, callback) {
formatter.getFormatInfo = (locale, sync, callback) => {
if (typeof(sync) === "undefined" || sync) {
return oldGetFormatInfo(locale, sync, callback);
}

return promisifyFunction(function(options = {}) {
return promisifyFunction((options = {}) => {
const {locale, onLoad} = options;
return oldGetFormatInfo(locale, false, onLoad);
}, {
Expand All @@ -50,7 +50,7 @@ export default class AddressFmt {
}

static create(options = {}) {
return new Promise(function(resolve, reject) {
return new Promise((resolve, reject) => {
let tempOptions = Object.assign({}, options, {
sync: false,
onLoad: af => resolve(wrapGetFormatInfo(af))
Expand Down
10 changes: 5 additions & 5 deletions src/CType.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* CType.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,12 +26,12 @@ function CType(ch) {
return ilibCType(ch);
};

CType._init = function (sync, loadParams, onLoad) {
CType._init = (sync, loadParams, onLoad) => {
if (typeof(sync) === "undefined" || sync) {
return ilibCType._init(sync, loadParams, onLoad);
}

return promisifyFunction(function(options = {}) {
return promisifyFunction((options = {}) => {
const { sync, loadParams, onLoad } = options;
return ilibCType._init(sync, loadParams, onLoad);
}, {
Expand All @@ -41,12 +41,12 @@ CType._init = function (sync, loadParams, onLoad) {
});
};

CType._load = function (name, sync, loadParams, onLoad) {
CType._load = (name, sync, loadParams, onLoad) => {
if (typeof(sync) === "undefined" || sync) {
return ilibCType._load(name, sync, loadParams, onLoad);
}

return promisifyFunction(function(options = {}) {
return promisifyFunction((options = {}) => {
const { name, sync, loadParams, onLoad } = options;
return ilibCType._init(name, sync, loadParams, onLoad);
}, {
Expand Down
4 changes: 2 additions & 2 deletions src/CalendarFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* CalendarFactory.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@ import { promisifyFunction } from './promisify.js';
import {default as CalendarFactory } from 'ilib/lib/CalendarFactory.js';

export function CalendarFactoryAsync(options = {}) {
var opts = Object.assign({}, options, {sync: false});
const opts = Object.assign({}, options, {sync: false});
return promisifyFunction(CalendarFactory, opts);
};

Expand Down
4 changes: 2 additions & 2 deletions src/CharmapFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* CharmapFactory.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@ import { promisifyFunction } from './promisify.js';
import { default as CharmapFactory } from 'ilib/lib/CharmapFactory.js';

export function CharmapFactoryAsync(options = {}) {
var opts = Object.assign({}, options);
const opts = Object.assign({}, options);
opts.sync = false;
return promisifyFunction(CharmapFactory, opts);
};
Expand Down
4 changes: 2 additions & 2 deletions src/DateFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* DateFactory.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@ import { promisifyFunction } from './promisify.js';
import { default as DateFactory } from 'ilib/lib/DateFactory.js';

export function DateFactoryAsync(options = {}) {
var opts = Object.assign({}, options, {sync: false});
const opts = Object.assign({}, options, {sync: false});
return promisifyFunction(DateFactory, opts);
};

Expand Down
4 changes: 2 additions & 2 deletions src/GlyphString.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* GlyphString.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -28,7 +28,7 @@ export default class GlyphString {
}

static create(str, options = {}) {
return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { str } = opts;
return new ilibGlyphString(str, opts);
}, Object.assign({}, options, {
Expand Down
4 changes: 2 additions & 2 deletions src/INumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* INumber.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -28,7 +28,7 @@ export default class INumber {
}

static create(str, options = {}) {
return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { str } = opts;
return new ilibINumber(str, opts);
}, Object.assign({}, options, {
Expand Down
22 changes: 11 additions & 11 deletions src/IString.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* IString.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,19 +26,19 @@ function wrapSetLocale(str) {
if (!str) return;

const oldSetLocale = ilibIString.prototype.setLocale.bind(str);
str.setLocale = function(locale, sync, loadParams, onLoad) {
str.setLocale = (locale, sync, loadParams, onLoad) => {
if (typeof(sync) === "undefined" || sync) {
return oldSetLocale(locale, sync, loadParams, onLoad);
}

return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { locale, sync, loadParams, onLoad } = opts;
return oldSetLocale(locale, sync, loadParams, onLoad);
}, {
locale: locale,
locale,
sync: false,
loadParams: loadParams,
onLoad: onLoad
loadParams,
onLoad
});
};

Expand All @@ -50,19 +50,19 @@ export default class IString {
return wrapSetLocale(new ilibIString(str));
}

static loadPlurals(sync, locale, loadParams, callback) {
static loadPlurals(sync, locale, loadParams, onLoad) {
if (typeof(sync) === "undefined" || sync) {
return ilibIString.loadPlurals(sync, locale, loadParams, onLoad);
}

return promisifyFunction(function(options = {}) {
return promisifyFunction((options = {}) => {
const {locale, loadParams, onLoad} = options;
return ilibIString.loadPlurals(false, locale, loadParams, onLoad);
}, {
loadParams: loadParams,
locale: locale,
loadParams,
locale,
sync: false,
onLoad: callback
onLoad
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/LocaleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* LocaleInfo.js - ES6 wrappers around an ilib class
*
* @license
* Copyright © 2018, 2022 JEDLSoft
* Copyright © 2018, 2022, 2024 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -28,7 +28,7 @@ export default class LocaleInfo {
}

static create(locale, options = {}) {
return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { locale } = opts;
return new ilibLocaleInfo(locale, opts);
}, Object.assign({}, options, {
Expand Down
2 changes: 1 addition & 1 deletion src/Name.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Name {
}

static create(name, options = {}) {
return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { name } = opts;
return new ilibName(name, opts);
}, Object.assign({}, options, {
Expand Down
2 changes: 1 addition & 1 deletion src/NormString.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class NormString {
}

static create(str, options = {}) {
return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { str } = opts;
return new ilibNormString(str, opts);
}, Object.assign({}, options, {
Expand Down
6 changes: 3 additions & 3 deletions src/PhoneFmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function wrapFormat(phoneFmt) {
if (!phoneFmt) return;

const oldFormat = ilibPhoneFmt.prototype.format.bind(phoneFmt);
phoneFmt.format = function(number, options = {}) {
phoneFmt.format = (number, options = {}) => {
const { sync } = options;
if (typeof(sync) === "undefined" || sync) {
return oldFormat(number, options);
}

return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { number } = opts;
return oldFormat(number, opts);
}, Object.assign({}, options, {
Expand All @@ -49,7 +49,7 @@ export default class PhoneFmt {
}

static create(options = {}) {
return promisifyFunction(function(options = {}) {
return promisifyFunction((options = {}) => {
return wrapFormat(new ilibPhoneFmt(options));
}, options);
}
Expand Down
17 changes: 14 additions & 3 deletions src/PhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function wrapNormalize(phoneNumber) {
if (!phoneNumber) return;

const oldNormalize = ilibPhoneNumber.prototype.normalize.bind(phoneNumber);
phoneNumber.normalize = function(options = {}) {
phoneNumber.normalize = (options = {}) => {
const { sync } = options;
if (typeof(sync) === "undefined" || sync) {
return oldNormalize(options);
}

return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
return oldNormalize(opts);
}, options);
};
Expand All @@ -46,11 +46,22 @@ export default class PhoneNumber {
}

static create(phoneNumber, options = {}) {
return promisifyFunction(function(opts = {}) {
return promisifyFunction((opts = {}) => {
const { phoneNumber } = opts;
return wrapNormalize(new ilibPhoneNumber(phoneNumber, opts));
}, Object.assign({}, options, {
phoneNumber: phoneNumber
}));
}

static parseImsi(imsi, options = {}) {
const { sync } = options;
if (typeof(sync) === "undefined" || sync) {
return ilibPhoneNumber.parseImsi(imsi, options);
}

return promisifyFunction((opts = {}) => {
return ilibPhoneNumber.parseImsi(imsi, opts);
}, options);
}
};
Loading

0 comments on commit f357dca

Please sign in to comment.