@jsenv/core 40.12.1 → 40.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -852,19 +852,47 @@ const setDecimalsPrecision = (
|
|
|
852
852
|
// return numberTruncated
|
|
853
853
|
// }
|
|
854
854
|
|
|
855
|
-
const
|
|
856
|
-
year:
|
|
857
|
-
month:
|
|
858
|
-
week:
|
|
859
|
-
day:
|
|
860
|
-
hour:
|
|
861
|
-
minute:
|
|
862
|
-
second:
|
|
855
|
+
const UNIT_MS = {
|
|
856
|
+
year: 31_557_600_000,
|
|
857
|
+
month: 2_629_000_000,
|
|
858
|
+
week: 604_800_000,
|
|
859
|
+
day: 86_400_000,
|
|
860
|
+
hour: 3_600_000,
|
|
861
|
+
minute: 60_000,
|
|
862
|
+
second: 1000,
|
|
863
|
+
};
|
|
864
|
+
const UNIT_KEYS = Object.keys(UNIT_MS);
|
|
865
|
+
const SMALLEST_UNIT_NAME = UNIT_KEYS[UNIT_KEYS.length - 1];
|
|
866
|
+
const TIME_DICTIONARY_EN = {
|
|
867
|
+
year: { long: "year", plural: "years", short: "y" },
|
|
868
|
+
month: { long: "month", plural: "months", short: "m" },
|
|
869
|
+
week: { long: "week", plural: "weeks", short: "w" },
|
|
870
|
+
day: { long: "day", plural: "days", short: "d" },
|
|
871
|
+
hour: { long: "hour", plural: "hours", short: "h" },
|
|
872
|
+
minute: { long: "minute", plural: "minutes", short: "m" },
|
|
873
|
+
second: { long: "second", plural: "seconds", short: "s" },
|
|
874
|
+
joinDuration: (primary, remaining) => `${primary} and ${remaining}`,
|
|
875
|
+
};
|
|
876
|
+
const TIME_DICTIONARY_FR = {
|
|
877
|
+
year: { long: "an", plural: "ans", short: "a" },
|
|
878
|
+
month: { long: "mois", plural: "mois", short: "m" },
|
|
879
|
+
week: { long: "semaine", plural: "semaines", short: "s" },
|
|
880
|
+
day: { long: "jour", plural: "jours", short: "j" },
|
|
881
|
+
hour: { long: "heure", plural: "heures", short: "h" },
|
|
882
|
+
minute: { long: "minute", plural: "minutes", short: "m" },
|
|
883
|
+
second: { long: "seconde", plural: "secondes", short: "s" },
|
|
884
|
+
joinDuration: (primary, remaining) => `${primary} et ${remaining}`,
|
|
863
885
|
};
|
|
864
886
|
|
|
865
887
|
const humanizeDuration = (
|
|
866
888
|
ms,
|
|
867
|
-
{
|
|
889
|
+
{
|
|
890
|
+
short,
|
|
891
|
+
rounded = true,
|
|
892
|
+
decimals,
|
|
893
|
+
lang = "en",
|
|
894
|
+
timeDictionnary = lang === "fr" ? TIME_DICTIONARY_FR : TIME_DICTIONARY_EN,
|
|
895
|
+
} = {},
|
|
868
896
|
) => {
|
|
869
897
|
// ignore ms below meaningfulMs so that:
|
|
870
898
|
// humanizeDuration(0.5) -> "0 second"
|
|
@@ -874,7 +902,9 @@ const humanizeDuration = (
|
|
|
874
902
|
// yes we could return "0.1 millisecond" but we choosed consistency over precision
|
|
875
903
|
// so that the prefered unit is "second" (and does not become millisecond when ms is super small)
|
|
876
904
|
if (ms < 1) {
|
|
877
|
-
return short
|
|
905
|
+
return short
|
|
906
|
+
? `0${timeDictionnary.second.short}`
|
|
907
|
+
: `0 ${timeDictionnary.second.long}`;
|
|
878
908
|
}
|
|
879
909
|
const { primary, remaining } = parseMs(ms);
|
|
880
910
|
if (!remaining) {
|
|
@@ -883,52 +913,51 @@ const humanizeDuration = (
|
|
|
883
913
|
decimals === undefined ? (primary.name === "second" ? 1 : 0) : decimals,
|
|
884
914
|
short,
|
|
885
915
|
rounded,
|
|
916
|
+
timeDictionnary,
|
|
886
917
|
});
|
|
887
918
|
}
|
|
888
|
-
|
|
919
|
+
const primaryText = humanizeDurationUnit(primary, {
|
|
889
920
|
decimals: decimals === undefined ? 0 : decimals,
|
|
890
921
|
short,
|
|
891
922
|
rounded,
|
|
892
|
-
|
|
923
|
+
timeDictionnary,
|
|
924
|
+
});
|
|
925
|
+
const remainingText = humanizeDurationUnit(remaining, {
|
|
893
926
|
decimals: decimals === undefined ? 0 : decimals,
|
|
894
927
|
short,
|
|
895
928
|
rounded,
|
|
896
|
-
|
|
929
|
+
timeDictionnary,
|
|
930
|
+
});
|
|
931
|
+
return timeDictionnary.joinDuration(primaryText, remainingText);
|
|
897
932
|
};
|
|
898
|
-
const humanizeDurationUnit = (
|
|
933
|
+
const humanizeDurationUnit = (
|
|
934
|
+
unit,
|
|
935
|
+
{ decimals, short, rounded, timeDictionnary },
|
|
936
|
+
) => {
|
|
899
937
|
const count = rounded
|
|
900
938
|
? setRoundedPrecision(unit.count, { decimals })
|
|
901
939
|
: setPrecision(unit.count, { decimals });
|
|
902
|
-
|
|
940
|
+
const name = unit.name;
|
|
903
941
|
if (short) {
|
|
904
|
-
|
|
905
|
-
return `${count}${
|
|
942
|
+
const unitText = timeDictionnary[name].short;
|
|
943
|
+
return `${count}${unitText}`;
|
|
906
944
|
}
|
|
907
945
|
if (count <= 1) {
|
|
908
|
-
|
|
946
|
+
const unitText = timeDictionnary[name].long;
|
|
947
|
+
return `${count} ${unitText}`;
|
|
909
948
|
}
|
|
910
|
-
|
|
911
|
-
}
|
|
912
|
-
const MS_PER_UNITS = {
|
|
913
|
-
year: 31_557_600_000,
|
|
914
|
-
month: 2_629_000_000,
|
|
915
|
-
week: 604_800_000,
|
|
916
|
-
day: 86_400_000,
|
|
917
|
-
hour: 3_600_000,
|
|
918
|
-
minute: 60_000,
|
|
919
|
-
second: 1000,
|
|
949
|
+
const unitText = timeDictionnary[name].plural;
|
|
950
|
+
return `${count} ${unitText}`;
|
|
920
951
|
};
|
|
921
952
|
|
|
922
953
|
const parseMs = (ms) => {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
const firstUnitIndex = unitNames.findIndex((unitName) => {
|
|
928
|
-
if (unitName === smallestUnitName) {
|
|
954
|
+
let firstUnitName = SMALLEST_UNIT_NAME;
|
|
955
|
+
let firstUnitCount = ms / UNIT_MS[SMALLEST_UNIT_NAME];
|
|
956
|
+
const firstUnitIndex = UNIT_KEYS.findIndex((unitName) => {
|
|
957
|
+
if (unitName === SMALLEST_UNIT_NAME) {
|
|
929
958
|
return false;
|
|
930
959
|
}
|
|
931
|
-
const msPerUnit =
|
|
960
|
+
const msPerUnit = UNIT_MS[unitName];
|
|
932
961
|
const unitCount = Math.floor(ms / msPerUnit);
|
|
933
962
|
if (unitCount) {
|
|
934
963
|
firstUnitName = unitName;
|
|
@@ -937,7 +966,7 @@ const parseMs = (ms) => {
|
|
|
937
966
|
}
|
|
938
967
|
return false;
|
|
939
968
|
});
|
|
940
|
-
if (firstUnitName ===
|
|
969
|
+
if (firstUnitName === SMALLEST_UNIT_NAME) {
|
|
941
970
|
return {
|
|
942
971
|
primary: {
|
|
943
972
|
name: firstUnitName,
|
|
@@ -945,9 +974,9 @@ const parseMs = (ms) => {
|
|
|
945
974
|
},
|
|
946
975
|
};
|
|
947
976
|
}
|
|
948
|
-
const remainingMs = ms - firstUnitCount *
|
|
949
|
-
const remainingUnitName =
|
|
950
|
-
const remainingUnitCount = remainingMs /
|
|
977
|
+
const remainingMs = ms - firstUnitCount * UNIT_MS[firstUnitName];
|
|
978
|
+
const remainingUnitName = UNIT_KEYS[firstUnitIndex + 1];
|
|
979
|
+
const remainingUnitCount = remainingMs / UNIT_MS[remainingUnitName];
|
|
951
980
|
// - 1 year and 1 second is too much information
|
|
952
981
|
// so we don't check the remaining units
|
|
953
982
|
// - 1 year and 0.0001 week is awful
|
|
@@ -760,19 +760,47 @@ const setDecimalsPrecision = (
|
|
|
760
760
|
// return numberTruncated
|
|
761
761
|
// }
|
|
762
762
|
|
|
763
|
-
const
|
|
764
|
-
year:
|
|
765
|
-
month:
|
|
766
|
-
week:
|
|
767
|
-
day:
|
|
768
|
-
hour:
|
|
769
|
-
minute:
|
|
770
|
-
second:
|
|
763
|
+
const UNIT_MS = {
|
|
764
|
+
year: 31_557_600_000,
|
|
765
|
+
month: 2_629_000_000,
|
|
766
|
+
week: 604_800_000,
|
|
767
|
+
day: 86_400_000,
|
|
768
|
+
hour: 3_600_000,
|
|
769
|
+
minute: 60_000,
|
|
770
|
+
second: 1000,
|
|
771
|
+
};
|
|
772
|
+
const UNIT_KEYS = Object.keys(UNIT_MS);
|
|
773
|
+
const SMALLEST_UNIT_NAME = UNIT_KEYS[UNIT_KEYS.length - 1];
|
|
774
|
+
const TIME_DICTIONARY_EN = {
|
|
775
|
+
year: { long: "year", plural: "years", short: "y" },
|
|
776
|
+
month: { long: "month", plural: "months", short: "m" },
|
|
777
|
+
week: { long: "week", plural: "weeks", short: "w" },
|
|
778
|
+
day: { long: "day", plural: "days", short: "d" },
|
|
779
|
+
hour: { long: "hour", plural: "hours", short: "h" },
|
|
780
|
+
minute: { long: "minute", plural: "minutes", short: "m" },
|
|
781
|
+
second: { long: "second", plural: "seconds", short: "s" },
|
|
782
|
+
joinDuration: (primary, remaining) => `${primary} and ${remaining}`,
|
|
783
|
+
};
|
|
784
|
+
const TIME_DICTIONARY_FR = {
|
|
785
|
+
year: { long: "an", plural: "ans", short: "a" },
|
|
786
|
+
month: { long: "mois", plural: "mois", short: "m" },
|
|
787
|
+
week: { long: "semaine", plural: "semaines", short: "s" },
|
|
788
|
+
day: { long: "jour", plural: "jours", short: "j" },
|
|
789
|
+
hour: { long: "heure", plural: "heures", short: "h" },
|
|
790
|
+
minute: { long: "minute", plural: "minutes", short: "m" },
|
|
791
|
+
second: { long: "seconde", plural: "secondes", short: "s" },
|
|
792
|
+
joinDuration: (primary, remaining) => `${primary} et ${remaining}`,
|
|
771
793
|
};
|
|
772
794
|
|
|
773
795
|
const humanizeDuration = (
|
|
774
796
|
ms,
|
|
775
|
-
{
|
|
797
|
+
{
|
|
798
|
+
short,
|
|
799
|
+
rounded = true,
|
|
800
|
+
decimals,
|
|
801
|
+
lang = "en",
|
|
802
|
+
timeDictionnary = lang === "fr" ? TIME_DICTIONARY_FR : TIME_DICTIONARY_EN,
|
|
803
|
+
} = {},
|
|
776
804
|
) => {
|
|
777
805
|
// ignore ms below meaningfulMs so that:
|
|
778
806
|
// humanizeDuration(0.5) -> "0 second"
|
|
@@ -782,7 +810,9 @@ const humanizeDuration = (
|
|
|
782
810
|
// yes we could return "0.1 millisecond" but we choosed consistency over precision
|
|
783
811
|
// so that the prefered unit is "second" (and does not become millisecond when ms is super small)
|
|
784
812
|
if (ms < 1) {
|
|
785
|
-
return short
|
|
813
|
+
return short
|
|
814
|
+
? `0${timeDictionnary.second.short}`
|
|
815
|
+
: `0 ${timeDictionnary.second.long}`;
|
|
786
816
|
}
|
|
787
817
|
const { primary, remaining } = parseMs(ms);
|
|
788
818
|
if (!remaining) {
|
|
@@ -791,52 +821,51 @@ const humanizeDuration = (
|
|
|
791
821
|
decimals === undefined ? (primary.name === "second" ? 1 : 0) : decimals,
|
|
792
822
|
short,
|
|
793
823
|
rounded,
|
|
824
|
+
timeDictionnary,
|
|
794
825
|
});
|
|
795
826
|
}
|
|
796
|
-
|
|
827
|
+
const primaryText = humanizeDurationUnit(primary, {
|
|
797
828
|
decimals: decimals === undefined ? 0 : decimals,
|
|
798
829
|
short,
|
|
799
830
|
rounded,
|
|
800
|
-
|
|
831
|
+
timeDictionnary,
|
|
832
|
+
});
|
|
833
|
+
const remainingText = humanizeDurationUnit(remaining, {
|
|
801
834
|
decimals: decimals === undefined ? 0 : decimals,
|
|
802
835
|
short,
|
|
803
836
|
rounded,
|
|
804
|
-
|
|
837
|
+
timeDictionnary,
|
|
838
|
+
});
|
|
839
|
+
return timeDictionnary.joinDuration(primaryText, remainingText);
|
|
805
840
|
};
|
|
806
|
-
const humanizeDurationUnit = (
|
|
841
|
+
const humanizeDurationUnit = (
|
|
842
|
+
unit,
|
|
843
|
+
{ decimals, short, rounded, timeDictionnary },
|
|
844
|
+
) => {
|
|
807
845
|
const count = rounded
|
|
808
846
|
? setRoundedPrecision(unit.count, { decimals })
|
|
809
847
|
: setPrecision(unit.count, { decimals });
|
|
810
|
-
|
|
848
|
+
const name = unit.name;
|
|
811
849
|
if (short) {
|
|
812
|
-
|
|
813
|
-
return `${count}${
|
|
850
|
+
const unitText = timeDictionnary[name].short;
|
|
851
|
+
return `${count}${unitText}`;
|
|
814
852
|
}
|
|
815
853
|
if (count <= 1) {
|
|
816
|
-
|
|
854
|
+
const unitText = timeDictionnary[name].long;
|
|
855
|
+
return `${count} ${unitText}`;
|
|
817
856
|
}
|
|
818
|
-
|
|
819
|
-
}
|
|
820
|
-
const MS_PER_UNITS = {
|
|
821
|
-
year: 31_557_600_000,
|
|
822
|
-
month: 2_629_000_000,
|
|
823
|
-
week: 604_800_000,
|
|
824
|
-
day: 86_400_000,
|
|
825
|
-
hour: 3_600_000,
|
|
826
|
-
minute: 60_000,
|
|
827
|
-
second: 1000,
|
|
857
|
+
const unitText = timeDictionnary[name].plural;
|
|
858
|
+
return `${count} ${unitText}`;
|
|
828
859
|
};
|
|
829
860
|
|
|
830
861
|
const parseMs = (ms) => {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
const firstUnitIndex = unitNames.findIndex((unitName) => {
|
|
836
|
-
if (unitName === smallestUnitName) {
|
|
862
|
+
let firstUnitName = SMALLEST_UNIT_NAME;
|
|
863
|
+
let firstUnitCount = ms / UNIT_MS[SMALLEST_UNIT_NAME];
|
|
864
|
+
const firstUnitIndex = UNIT_KEYS.findIndex((unitName) => {
|
|
865
|
+
if (unitName === SMALLEST_UNIT_NAME) {
|
|
837
866
|
return false;
|
|
838
867
|
}
|
|
839
|
-
const msPerUnit =
|
|
868
|
+
const msPerUnit = UNIT_MS[unitName];
|
|
840
869
|
const unitCount = Math.floor(ms / msPerUnit);
|
|
841
870
|
if (unitCount) {
|
|
842
871
|
firstUnitName = unitName;
|
|
@@ -845,7 +874,7 @@ const parseMs = (ms) => {
|
|
|
845
874
|
}
|
|
846
875
|
return false;
|
|
847
876
|
});
|
|
848
|
-
if (firstUnitName ===
|
|
877
|
+
if (firstUnitName === SMALLEST_UNIT_NAME) {
|
|
849
878
|
return {
|
|
850
879
|
primary: {
|
|
851
880
|
name: firstUnitName,
|
|
@@ -853,9 +882,9 @@ const parseMs = (ms) => {
|
|
|
853
882
|
},
|
|
854
883
|
};
|
|
855
884
|
}
|
|
856
|
-
const remainingMs = ms - firstUnitCount *
|
|
857
|
-
const remainingUnitName =
|
|
858
|
-
const remainingUnitCount = remainingMs /
|
|
885
|
+
const remainingMs = ms - firstUnitCount * UNIT_MS[firstUnitName];
|
|
886
|
+
const remainingUnitName = UNIT_KEYS[firstUnitIndex + 1];
|
|
887
|
+
const remainingUnitCount = remainingMs / UNIT_MS[remainingUnitName];
|
|
859
888
|
// - 1 year and 1 second is too much information
|
|
860
889
|
// so we don't check the remaining units
|
|
861
890
|
// - 1 year and 0.0001 week is awful
|
|
@@ -360,19 +360,47 @@ const setDecimalsPrecision = (
|
|
|
360
360
|
// return numberTruncated
|
|
361
361
|
// }
|
|
362
362
|
|
|
363
|
-
const
|
|
364
|
-
year:
|
|
365
|
-
month:
|
|
366
|
-
week:
|
|
367
|
-
day:
|
|
368
|
-
hour:
|
|
369
|
-
minute:
|
|
370
|
-
second:
|
|
363
|
+
const UNIT_MS = {
|
|
364
|
+
year: 31_557_600_000,
|
|
365
|
+
month: 2_629_000_000,
|
|
366
|
+
week: 604_800_000,
|
|
367
|
+
day: 86_400_000,
|
|
368
|
+
hour: 3_600_000,
|
|
369
|
+
minute: 60_000,
|
|
370
|
+
second: 1000,
|
|
371
|
+
};
|
|
372
|
+
const UNIT_KEYS = Object.keys(UNIT_MS);
|
|
373
|
+
const SMALLEST_UNIT_NAME = UNIT_KEYS[UNIT_KEYS.length - 1];
|
|
374
|
+
const TIME_DICTIONARY_EN = {
|
|
375
|
+
year: { long: "year", plural: "years", short: "y" },
|
|
376
|
+
month: { long: "month", plural: "months", short: "m" },
|
|
377
|
+
week: { long: "week", plural: "weeks", short: "w" },
|
|
378
|
+
day: { long: "day", plural: "days", short: "d" },
|
|
379
|
+
hour: { long: "hour", plural: "hours", short: "h" },
|
|
380
|
+
minute: { long: "minute", plural: "minutes", short: "m" },
|
|
381
|
+
second: { long: "second", plural: "seconds", short: "s" },
|
|
382
|
+
joinDuration: (primary, remaining) => `${primary} and ${remaining}`,
|
|
383
|
+
};
|
|
384
|
+
const TIME_DICTIONARY_FR = {
|
|
385
|
+
year: { long: "an", plural: "ans", short: "a" },
|
|
386
|
+
month: { long: "mois", plural: "mois", short: "m" },
|
|
387
|
+
week: { long: "semaine", plural: "semaines", short: "s" },
|
|
388
|
+
day: { long: "jour", plural: "jours", short: "j" },
|
|
389
|
+
hour: { long: "heure", plural: "heures", short: "h" },
|
|
390
|
+
minute: { long: "minute", plural: "minutes", short: "m" },
|
|
391
|
+
second: { long: "seconde", plural: "secondes", short: "s" },
|
|
392
|
+
joinDuration: (primary, remaining) => `${primary} et ${remaining}`,
|
|
371
393
|
};
|
|
372
394
|
|
|
373
395
|
const humanizeDuration = (
|
|
374
396
|
ms,
|
|
375
|
-
{
|
|
397
|
+
{
|
|
398
|
+
short,
|
|
399
|
+
rounded = true,
|
|
400
|
+
decimals,
|
|
401
|
+
lang = "en",
|
|
402
|
+
timeDictionnary = lang === "fr" ? TIME_DICTIONARY_FR : TIME_DICTIONARY_EN,
|
|
403
|
+
} = {},
|
|
376
404
|
) => {
|
|
377
405
|
// ignore ms below meaningfulMs so that:
|
|
378
406
|
// humanizeDuration(0.5) -> "0 second"
|
|
@@ -382,7 +410,9 @@ const humanizeDuration = (
|
|
|
382
410
|
// yes we could return "0.1 millisecond" but we choosed consistency over precision
|
|
383
411
|
// so that the prefered unit is "second" (and does not become millisecond when ms is super small)
|
|
384
412
|
if (ms < 1) {
|
|
385
|
-
return short
|
|
413
|
+
return short
|
|
414
|
+
? `0${timeDictionnary.second.short}`
|
|
415
|
+
: `0 ${timeDictionnary.second.long}`;
|
|
386
416
|
}
|
|
387
417
|
const { primary, remaining } = parseMs(ms);
|
|
388
418
|
if (!remaining) {
|
|
@@ -391,52 +421,51 @@ const humanizeDuration = (
|
|
|
391
421
|
decimals === undefined ? (primary.name === "second" ? 1 : 0) : decimals,
|
|
392
422
|
short,
|
|
393
423
|
rounded,
|
|
424
|
+
timeDictionnary,
|
|
394
425
|
});
|
|
395
426
|
}
|
|
396
|
-
|
|
427
|
+
const primaryText = humanizeDurationUnit(primary, {
|
|
397
428
|
decimals: decimals === undefined ? 0 : decimals,
|
|
398
429
|
short,
|
|
399
430
|
rounded,
|
|
400
|
-
|
|
431
|
+
timeDictionnary,
|
|
432
|
+
});
|
|
433
|
+
const remainingText = humanizeDurationUnit(remaining, {
|
|
401
434
|
decimals: decimals === undefined ? 0 : decimals,
|
|
402
435
|
short,
|
|
403
436
|
rounded,
|
|
404
|
-
|
|
437
|
+
timeDictionnary,
|
|
438
|
+
});
|
|
439
|
+
return timeDictionnary.joinDuration(primaryText, remainingText);
|
|
405
440
|
};
|
|
406
|
-
const humanizeDurationUnit = (
|
|
441
|
+
const humanizeDurationUnit = (
|
|
442
|
+
unit,
|
|
443
|
+
{ decimals, short, rounded, timeDictionnary },
|
|
444
|
+
) => {
|
|
407
445
|
const count = rounded
|
|
408
446
|
? setRoundedPrecision(unit.count, { decimals })
|
|
409
447
|
: setPrecision(unit.count, { decimals });
|
|
410
|
-
|
|
448
|
+
const name = unit.name;
|
|
411
449
|
if (short) {
|
|
412
|
-
|
|
413
|
-
return `${count}${
|
|
450
|
+
const unitText = timeDictionnary[name].short;
|
|
451
|
+
return `${count}${unitText}`;
|
|
414
452
|
}
|
|
415
453
|
if (count <= 1) {
|
|
416
|
-
|
|
454
|
+
const unitText = timeDictionnary[name].long;
|
|
455
|
+
return `${count} ${unitText}`;
|
|
417
456
|
}
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
const MS_PER_UNITS = {
|
|
421
|
-
year: 31_557_600_000,
|
|
422
|
-
month: 2_629_000_000,
|
|
423
|
-
week: 604_800_000,
|
|
424
|
-
day: 86_400_000,
|
|
425
|
-
hour: 3_600_000,
|
|
426
|
-
minute: 60_000,
|
|
427
|
-
second: 1000,
|
|
457
|
+
const unitText = timeDictionnary[name].plural;
|
|
458
|
+
return `${count} ${unitText}`;
|
|
428
459
|
};
|
|
429
460
|
|
|
430
461
|
const parseMs = (ms) => {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const firstUnitIndex = unitNames.findIndex((unitName) => {
|
|
436
|
-
if (unitName === smallestUnitName) {
|
|
462
|
+
let firstUnitName = SMALLEST_UNIT_NAME;
|
|
463
|
+
let firstUnitCount = ms / UNIT_MS[SMALLEST_UNIT_NAME];
|
|
464
|
+
const firstUnitIndex = UNIT_KEYS.findIndex((unitName) => {
|
|
465
|
+
if (unitName === SMALLEST_UNIT_NAME) {
|
|
437
466
|
return false;
|
|
438
467
|
}
|
|
439
|
-
const msPerUnit =
|
|
468
|
+
const msPerUnit = UNIT_MS[unitName];
|
|
440
469
|
const unitCount = Math.floor(ms / msPerUnit);
|
|
441
470
|
if (unitCount) {
|
|
442
471
|
firstUnitName = unitName;
|
|
@@ -445,7 +474,7 @@ const parseMs = (ms) => {
|
|
|
445
474
|
}
|
|
446
475
|
return false;
|
|
447
476
|
});
|
|
448
|
-
if (firstUnitName ===
|
|
477
|
+
if (firstUnitName === SMALLEST_UNIT_NAME) {
|
|
449
478
|
return {
|
|
450
479
|
primary: {
|
|
451
480
|
name: firstUnitName,
|
|
@@ -453,9 +482,9 @@ const parseMs = (ms) => {
|
|
|
453
482
|
},
|
|
454
483
|
};
|
|
455
484
|
}
|
|
456
|
-
const remainingMs = ms - firstUnitCount *
|
|
457
|
-
const remainingUnitName =
|
|
458
|
-
const remainingUnitCount = remainingMs /
|
|
485
|
+
const remainingMs = ms - firstUnitCount * UNIT_MS[firstUnitName];
|
|
486
|
+
const remainingUnitName = UNIT_KEYS[firstUnitIndex + 1];
|
|
487
|
+
const remainingUnitCount = remainingMs / UNIT_MS[remainingUnitName];
|
|
459
488
|
// - 1 year and 1 second is too much information
|
|
460
489
|
// so we don't check the remaining units
|
|
461
490
|
// - 1 year and 0.0001 week is awful
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "40.12.
|
|
3
|
+
"version": "40.12.2",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -75,14 +75,14 @@
|
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
78
|
-
"@jsenv/ast": "6.7.
|
|
79
|
-
"@jsenv/js-module-fallback": "1.4.
|
|
80
|
-
"@jsenv/plugin-bundling": "2.10.
|
|
78
|
+
"@jsenv/ast": "6.7.17",
|
|
79
|
+
"@jsenv/js-module-fallback": "1.4.25",
|
|
80
|
+
"@jsenv/plugin-bundling": "2.10.4",
|
|
81
81
|
"@jsenv/plugin-minification": "1.7.3",
|
|
82
|
-
"@jsenv/plugin-supervisor": "1.7.
|
|
83
|
-
"@jsenv/plugin-transpilation": "1.5.
|
|
82
|
+
"@jsenv/plugin-supervisor": "1.7.11",
|
|
83
|
+
"@jsenv/plugin-transpilation": "1.5.65",
|
|
84
84
|
"@jsenv/server": "16.3.4",
|
|
85
|
-
"@jsenv/sourcemap": "1.3.
|
|
85
|
+
"@jsenv/sourcemap": "1.3.13",
|
|
86
86
|
"react-table": "7.8.0"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|