Skip to content

Commit 47007bb

Browse files
committed
improves
1 parent bcd6d88 commit 47007bb

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const timeInMilliseconds = {
1010
seconds: 1000, // 1 second
1111
};
1212

13+
const ordinal_suffix = ['th', 'st', 'nd', 'rd'];
14+
1315
const format_types = {
1416
dddd: 'dddd',
1517
YYYY: 'YYYY',
@@ -342,3 +344,4 @@ module.exports.converter_results_cache = converter_results_cache;
342344
module.exports.formatter_cache = formatter_cache;
343345
module.exports.cached_dateTimeFormat_with_locale = cached_dateTimeFormat_with_locale;
344346
module.exports.COMMON_TIMEZONES = COMMON_TIMEZONES;
347+
module.exports.ordinal_suffix = ordinal_suffix;

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ const {
2424
format_types_cache,
2525
format_types_regex_cache,
2626
formatter_cache,
27+
ordinal_suffix
2728
} = require('./constants');
2829

30+
2931
nopeRedis.config({ defaultTtl: 1300 });
3032

3133
/**
@@ -34,9 +36,8 @@ nopeRedis.config({ defaultTtl: 1300 });
3436
* @returns {string} The number with ordinal suffix
3537
*/
3638
function getOrdinal(n) {
37-
const s = ['th', 'st', 'nd', 'rd'];
3839
const v = n % 100;
39-
return n + (s[(v - 20) % 10] || s[v] || s[0]);
40+
return n + (ordinal_suffix[(v - 20) % 10] || ordinal_suffix[v] || ordinal_suffix[0]);
4041
}
4142

4243
/**

0 commit comments

Comments
 (0)