@jsenv/humanize 1.1.0 → 1.1.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.
@@ -7,6 +7,100 @@ const createDetailedMessage = (message, details = {}) => {
7
7
  return string;
8
8
  };
9
9
 
10
+ // https://github.com/Marak/colors.js/blob/master/lib/styles.js
11
+ // https://stackoverflow.com/a/75985833/2634179
12
+ const RESET = "\x1b[0m";
13
+ const createAnsi = ({
14
+ supported
15
+ }) => {
16
+ const ANSI = {
17
+ supported,
18
+ RED: "\x1b[31m",
19
+ GREEN: "\x1b[32m",
20
+ YELLOW: "\x1b[33m",
21
+ BLUE: "\x1b[34m",
22
+ MAGENTA: "\x1b[35m",
23
+ CYAN: "\x1b[36m",
24
+ GREY: "\x1b[90m",
25
+ color: (text, ANSI_COLOR) => {
26
+ return ANSI.supported && ANSI_COLOR ? "".concat(ANSI_COLOR).concat(text).concat(RESET) : text;
27
+ },
28
+ BOLD: "\x1b[1m",
29
+ UNDERLINE: "\x1b[4m",
30
+ STRIKE: "\x1b[9m",
31
+ effect: (text, ANSI_EFFECT) => {
32
+ return ANSI.supported && ANSI_EFFECT ? "".concat(ANSI_EFFECT).concat(text).concat(RESET) : text;
33
+ }
34
+ };
35
+ return ANSI;
36
+ };
37
+
38
+ const ANSI = createAnsi({
39
+ supported: true
40
+ });
41
+
42
+ // see also https://github.com/sindresorhus/figures
43
+
44
+ const createUnicode = ({
45
+ supported,
46
+ ANSI
47
+ }) => {
48
+ const UNICODE = {
49
+ supported,
50
+ get COMMAND_RAW() {
51
+ return UNICODE.supported ? "\u276F" : ">";
52
+ },
53
+ get OK_RAW() {
54
+ return UNICODE.supported ? "\u2714" : "\u221A";
55
+ },
56
+ get FAILURE_RAW() {
57
+ return UNICODE.supported ? "\u2716" : "\xD7";
58
+ },
59
+ get DEBUG_RAW() {
60
+ return UNICODE.supported ? "\u25C6" : "\u2666";
61
+ },
62
+ get INFO_RAW() {
63
+ return UNICODE.supported ? "\u2139" : "i";
64
+ },
65
+ get WARNING_RAW() {
66
+ return UNICODE.supported ? "\u26A0" : "\u203C";
67
+ },
68
+ get CIRCLE_CROSS_RAW() {
69
+ return UNICODE.supported ? "\u24E7" : "(\xD7)";
70
+ },
71
+ get COMMAND() {
72
+ return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
73
+ },
74
+ get OK() {
75
+ return ANSI.color(UNICODE.OK_RAW, ANSI.GREEN);
76
+ },
77
+ get FAILURE() {
78
+ return ANSI.color(UNICODE.FAILURE_RAW, ANSI.RED);
79
+ },
80
+ get DEBUG() {
81
+ return ANSI.color(UNICODE.DEBUG_RAW, ANSI.GREY);
82
+ },
83
+ get INFO() {
84
+ return ANSI.color(UNICODE.INFO_RAW, ANSI.BLUE);
85
+ },
86
+ get WARNING() {
87
+ return ANSI.color(UNICODE.WARNING_RAW, ANSI.YELLOW);
88
+ },
89
+ get CIRCLE_CROSS() {
90
+ return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
91
+ },
92
+ get ELLIPSIS() {
93
+ return UNICODE.supported ? "\u2026" : "...";
94
+ }
95
+ };
96
+ return UNICODE;
97
+ };
98
+
99
+ const UNICODE = createUnicode({
100
+ supported: true,
101
+ ANSI
102
+ });
103
+
10
104
  const inspectBoolean = value => value.toString();
11
105
 
12
106
  const inspectNull = () => "null";
@@ -678,80 +772,6 @@ const compositeStringifiers = {
678
772
  String: inspectStringObject
679
773
  };
680
774
 
681
- // https://github.com/Marak/colors.js/blob/master/lib/styles.js
682
- // https://stackoverflow.com/a/75985833/2634179
683
- const RESET = "\x1b[0m";
684
- const ANSI = {
685
- supported: true,
686
- RED: "\x1b[31m",
687
- GREEN: "\x1b[32m",
688
- YELLOW: "\x1b[33m",
689
- BLUE: "\x1b[34m",
690
- MAGENTA: "\x1b[35m",
691
- CYAN: "\x1b[36m",
692
- GREY: "\x1b[90m",
693
- color: (text, ANSI_COLOR) => {
694
- return ANSI.supported && ANSI_COLOR ? "".concat(ANSI_COLOR).concat(text).concat(RESET) : text;
695
- },
696
- BOLD: "\x1b[1m",
697
- UNDERLINE: "\x1b[4m",
698
- STRIKE: "\x1b[9m",
699
- effect: (text, ANSI_EFFECT) => {
700
- return ANSI.supported && ANSI_EFFECT ? "".concat(ANSI_EFFECT).concat(text).concat(RESET) : text;
701
- }
702
- };
703
-
704
- // see also https://github.com/sindresorhus/figures
705
-
706
- const UNICODE = {
707
- supported: true,
708
- get COMMAND_RAW() {
709
- return UNICODE.supported ? "\u276F" : ">";
710
- },
711
- get OK_RAW() {
712
- return UNICODE.supported ? "\u2714" : "\u221A";
713
- },
714
- get FAILURE_RAW() {
715
- return UNICODE.supported ? "\u2716" : "\xD7";
716
- },
717
- get DEBUG_RAW() {
718
- return UNICODE.supported ? "\u25C6" : "\u2666";
719
- },
720
- get INFO_RAW() {
721
- return UNICODE.supported ? "\u2139" : "i";
722
- },
723
- get WARNING_RAW() {
724
- return UNICODE.supported ? "\u26A0" : "\u203C";
725
- },
726
- get CIRCLE_CROSS_RAW() {
727
- return UNICODE.supported ? "\u24E7" : "(\xD7)";
728
- },
729
- get COMMAND() {
730
- return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
731
- },
732
- get OK() {
733
- return ANSI.color(UNICODE.OK_RAW, ANSI.GREEN);
734
- },
735
- get FAILURE() {
736
- return ANSI.color(UNICODE.FAILURE_RAW, ANSI.RED);
737
- },
738
- get DEBUG() {
739
- return ANSI.color(UNICODE.DEBUG_RAW, ANSI.GREY);
740
- },
741
- get INFO() {
742
- return ANSI.color(UNICODE.INFO_RAW, ANSI.BLUE);
743
- },
744
- get WARNING() {
745
- return ANSI.color(UNICODE.WARNING_RAW, ANSI.YELLOW);
746
- },
747
- get CIRCLE_CROSS() {
748
- return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
749
- },
750
- get ELLIPSIS() {
751
- return UNICODE.supported ? "\u2026" : "...";
752
- }
753
- };
754
-
755
775
  const getPrecision = number => {
756
776
  if (Math.floor(number) === number) return 0;
757
777
  const [, decimals] = number.toString().split(".");
@@ -1228,4 +1248,4 @@ const fillLeft = (value, biggestValue, char = " ") => {
1228
1248
  return padded;
1229
1249
  };
1230
1250
 
1231
- export { ANSI, UNICODE, createDetailedMessage, determineQuote, distributePercentages, generateContentFrame, humanize, humanizeDuration, humanizeEllapsedTime, humanizeFileSize, humanizeMemory, humanizeMethodSymbol, inspectChar };
1251
+ export { ANSI, UNICODE, createDetailedMessage, distributePercentages, generateContentFrame, humanize, humanizeDuration, humanizeEllapsedTime, humanizeFileSize, humanizeMemory, humanizeMethodSymbol };