Skip to content

Commit

Permalink
Merge pull request #72 from Aller-Couleur/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
fwalzel authored Jun 26, 2024
2 parents ccf89f7 + 92d9117 commit 084b981
Show file tree
Hide file tree
Showing 8 changed files with 1,096 additions and 755 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test and Coverage

on:
pull_request:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
run: npm install

- name: Run tests and collect coverage
run: mkdir -p coverage/tmp && npm run test:coverage

- name: Wait for coverage report
run: sleep 3

- name: Debug coverage directory
run: ls -R coverage

- name: Debug lcov.info
run: cat coverage/lcov.info

- name: Publish to coveralls.io
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
6 changes: 3 additions & 3 deletions dist/handlebars-i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type unitDisplay = "short" | "narrow" | "long";
type roundingPriority = "auto" | "morePrecision" | "lessPrecision";

type roundingMode =
| "ceil"
"ceil"
| "floor"
| "expand"
| "trunc"
Expand Down Expand Up @@ -197,13 +197,13 @@ export type DateTimeFormatConfiguration = [
CustomFormatName?
];


type DateRelFormatOptions = {
localeMatcher?: localeMatcher,
numberingSystem?: numberingSystem,
numeric?: "always" | "auto",
style?: "long" | "short" | "narrow",
unit?: "second" | "minute" | "hour" | "day" | "week" | "month" | "year"
timeZone?: TimeZone,
unit?: "second" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year"
}

export type RelativeTimeFormatConfiguration = [
Expand Down
51 changes: 22 additions & 29 deletions dist/handlebars-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
const Handlebars = require('handlebars'),
i18next = require('i18next'),
Intl = require('intl'),
RelativeTimeFormat= require('relative-time-format');
RelativeTimeFormat = require('relative-time-format');
module.exports = factory(
Handlebars,
i18next,
Intl,
RelativeTimeFormat,
process?.env?.NODE_ENV === 'TEST');
}
else if (typeof define === 'function' && define.amd)
} else if (typeof define === 'function' && define.amd)
define(['Handlebars', 'i18next', 'Intl'], factory);
else if (typeof root.Handlebars === 'object'
&& typeof root.i18next === 'object'
Expand Down Expand Up @@ -151,7 +150,7 @@
return false;
}

if (! ['DateTimeFormat', 'RelativeTimeFormat', 'NumberFormat', 'PriceFormat'].includes(typeOfFormat)) {
if (!['DateTimeFormat', 'RelativeTimeFormat', 'NumberFormat', 'PriceFormat'].includes(typeOfFormat)) {
console.error('@ handlebars-i18n.configure(): Invalid argument <' + typeOfFormat + '>. ' +
'Second argument must be a string with the options key. ' +
'Use either "DateTimeFormat", "RelativeTimeFormat", "NumberFormat", or "PriceFormat".');
Expand Down Expand Up @@ -191,8 +190,7 @@
optionsConf[formatType].custom[customFormat] = {};

optionsConf[formatType].custom[customFormat][lang] = options;
}
else
} else
optionsConf[formatType].standard[lang] = options;

return true;
Expand Down Expand Up @@ -221,26 +219,22 @@
if (typeof dateInput === 'number') {
// input as milliseconds since unix epoch, like: 1583922952743
date = new Date(dateInput);
}
else if (typeof dateInput === 'string') {
} else if (typeof dateInput === 'string') {

if (dateInput.charAt(0) === '[' && dateInput.slice(-1) === ']') {
// input as array represented as string such as "[2020, 11]"
dateInput = dateInput.substring(1, dateInput.length - 1).replace(/ /g, '');
let dateArr = dateInput.split(',');
let dateFactory = __applyToConstructor.bind(null, Date);
date = dateFactory(dateArr);
}
else if (dateInput.toLowerCase() === 'now' || dateInput.toLowerCase() === 'today') {
} else if (dateInput.toLowerCase() === 'now' || dateInput.toLowerCase() === 'today') {
// input as word "now" or "today"
date = new Date();
}
else {
} else {
// input as date string such as "1995-12-17T03:24:00"
date = new Date(dateInput);
}
}
else {
} else {
// fallback: today’s date
date = new Date();
}
Expand Down Expand Up @@ -337,8 +331,7 @@
else
return false;
});
}
else {
} else {
if (__validateArgs(langOrArr, typeOfFormat, options, customFormatName))
__setArgs(langOrArr, typeOfFormat, options, customFormatName);
else
Expand Down Expand Up @@ -393,7 +386,7 @@
* @returns {*}
*/
function (str, attributes) {
return new handlebars.SafeString((typeof(i18next) !== 'undefined' ? i18next.t(str, attributes.hash) : str));
return new handlebars.SafeString((typeof (i18next) !== 'undefined' ? i18next.t(str, attributes.hash) : str));
}
);
handlebars.registerHelper('_locale',
Expand Down Expand Up @@ -445,7 +438,7 @@
* @param options
*/
function (dateInput, options) {
const date= __createDateObj(dateInput);
const date = __createDateObj(dateInput);
const opts = __configLookup(options, i18next.language, optionsConf.DateTimeFormat);
const dateFormat = new Intl.DateTimeFormat(i18next.language, opts);
return dateFormat.format(date);
Expand All @@ -468,7 +461,7 @@
* @returns {string}
*/
function (dateValue, options) {
const relDate= parseInt(dateValue);
const relDate = parseInt(dateValue);
const opts = __configLookup(options, i18next.language, optionsConf.RelativeTimeFormat);
const relDateFormat = __getRelDateFormatPolyfill(i18next.language, opts);
return relDateFormat.format(relDate, opts.unit);
Expand All @@ -485,20 +478,20 @@
function (dateInputA, dateInputB, options) {

let dateDiff;
let opts = __configLookup(options, i18next.language, optionsConf.RelativeTimeFormat);

if (! __isNumOrString(dateInputA) && ! __isNumOrString(dateInputB))
if (!__isNumOrString(dateInputA)) {
console.error('@ handlebars-i18n: invalid first argument dateInputA was given for _dateDiff.');
return null;
else if (! __isNumOrString(dateInputB))
dateDiff = __createDateObj(dateInputA);
else if (! __isNumOrString(dateInputA))
dateDiff = __createDateObj(dateInputB);
else {
const dateA= __createDateObj(dateInputA);
const dateB= __createDateObj(dateInputB);
dateDiff = dateA - dateB;
}

const opts = __configLookup(options, i18next.language, optionsConf.RelativeTimeFormat);
dateInputB = dateInputB || 'now';

let dateA = __createDateObj(dateInputA);
let dateB = __createDateObj(dateInputB);

dateDiff = dateA - dateB;

const relDate = __getDateDiff(dateDiff, opts.unit);
const relDateFormat = __getRelDateFormatPolyfill(i18next.language, opts);
return relDateFormat.format(relDate, opts.unit);
Expand Down
2 changes: 1 addition & 1 deletion dist/handlebars-i18n.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 084b981

Please sign in to comment.