@jsenv/humanize 1.8.0 → 1.8.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.
@@ -3072,7 +3072,9 @@ const toLocalDayKey = (date) => {
3072
3072
  * Coerces what `<Time>` accepts as a value — a Date, a ms timestamp, a
3073
3073
  * parseable string — into a Date, or null when it cannot. `parseString`
3074
3074
  * lets a caller claim the string forms it recognizes ("HH:MM" for a
3075
- * time-of-day, "YYYY-MM" for a month…) before the generic ones apply.
3075
+ * time-of-day, "YYYY-MM" for a month…) before the generic ones apply; the
3076
+ * strings it does not claim (it answers null) still go through them, so a
3077
+ * caller shaping one form never has to re-implement ISO parsing.
3076
3078
  */
3077
3079
  const toDate = (value, parseString) => {
3078
3080
  if (value instanceof Date) {
@@ -3083,7 +3085,10 @@ const toDate = (value, parseString) => {
3083
3085
  }
3084
3086
  if (typeof value === "string") {
3085
3087
  if (parseString) {
3086
- return parseString(value);
3088
+ const parsed = parseString(value);
3089
+ if (parsed) {
3090
+ return parsed;
3091
+ }
3087
3092
  }
3088
3093
  // "YYYY-MM-DD" — use local midnight to avoid UTC shift
3089
3094
  if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
@@ -3815,7 +3820,7 @@ const createDynamicLog = ({
3815
3820
  };
3816
3821
 
3817
3822
  let lastOutput = "";
3818
- let lastOutputFromOutside = "";
3823
+ let wroteFromOutside = false;
3819
3824
  let clearAttemptResult;
3820
3825
  let writing = false;
3821
3826
 
@@ -3864,7 +3869,7 @@ const createDynamicLog = ({
3864
3869
  }
3865
3870
  let stringToWrite = string;
3866
3871
  if (lastOutput) {
3867
- if (lastOutputFromOutside) {
3872
+ if (wroteFromOutside) {
3868
3873
  // We don't want to clear logs written by other code,
3869
3874
  // it makes output unreadable and might erase precious information
3870
3875
  // To detect this we put a spy on the stream.
@@ -3872,7 +3877,7 @@ const createDynamicLog = ({
3872
3877
  // something else than this code has written in the stream
3873
3878
  // so we just write without clearing (append instead of replacing)
3874
3879
  lastOutput = "";
3875
- lastOutputFromOutside = "";
3880
+ wroteFromOutside = false;
3876
3881
  } else {
3877
3882
  stringToWrite = `${getErasePreviousOutput()}${string}`;
3878
3883
  }
@@ -3903,7 +3908,7 @@ const createDynamicLog = ({
3903
3908
  update(ouputAfterCallback);
3904
3909
  };
3905
3910
 
3906
- const writeFromOutsideEffect = (value) => {
3911
+ const writeFromOutsideEffect = () => {
3907
3912
  if (!lastOutput) {
3908
3913
  // we don't care if the log never wrote anything
3909
3914
  // or if last update() wrote an empty string
@@ -3912,8 +3917,10 @@ const createDynamicLog = ({
3912
3917
  if (writing) {
3913
3918
  return;
3914
3919
  }
3915
- lastOutputFromOutside = value;
3916
- dynamicLog.onWriteFromOutside(value);
3920
+ wroteFromOutside = true;
3921
+ // the outside output is already in the stream: whoever reacts to this must
3922
+ // leave it alone, only stop refreshing above it
3923
+ dynamicLog.onWriteFromOutside();
3917
3924
  };
3918
3925
 
3919
3926
  let removeStreamSpy;
@@ -3940,7 +3947,7 @@ const createDynamicLog = ({
3940
3947
  removeStreamSpy();
3941
3948
  removeStreamSpy = null;
3942
3949
  lastOutput = "";
3943
- lastOutputFromOutside = "";
3950
+ wroteFromOutside = false;
3944
3951
  }
3945
3952
  };
3946
3953
 
@@ -3958,27 +3965,20 @@ const createDynamicLog = ({
3958
3965
  // is that node.js will later throw error if stream gets closed
3959
3966
  // while something listening data on it
3960
3967
  const spyStreamOutput = (stream, callback) => {
3961
- let output = "";
3962
3968
  let installed = true;
3963
3969
  const originalWrite = stream.write;
3964
3970
  stream.write = function (...args /* chunk, encoding, callback */) {
3965
- output += args;
3966
- callback(output);
3971
+ callback();
3967
3972
  return originalWrite.call(this, ...args);
3968
3973
  };
3969
3974
 
3970
- const uninstall = () => {
3975
+ return () => {
3971
3976
  if (!installed) {
3972
3977
  return;
3973
3978
  }
3974
3979
  stream.write = originalWrite;
3975
3980
  installed = false;
3976
3981
  };
3977
-
3978
- return () => {
3979
- uninstall();
3980
- return output;
3981
- };
3982
3982
  };
3983
3983
 
3984
3984
  const startSpinner = ({
@@ -4043,10 +4043,15 @@ const startSpinner = ({
4043
4043
  spinner.stop = stop;
4044
4044
 
4045
4045
  if (stopOnVerticalOverflow) {
4046
- dynamicLog.onVerticalOverflow = stop;
4046
+ dynamicLog.onVerticalOverflow = () => {
4047
+ stop();
4048
+ };
4047
4049
  }
4048
4050
  if (stopOnWriteFromOutside) {
4049
- dynamicLog.onWriteFromOutside = stop;
4051
+ // the spinner freezes on its current frame and the other output goes below
4052
+ dynamicLog.onWriteFromOutside = () => {
4053
+ stop();
4054
+ };
4050
4055
  }
4051
4056
 
4052
4057
  return spinner;