all-sync.js 751 B

123456789101112131415161718192021222324252627282930313233
  1. import {isUint8Array, concatUint8Arrays} from '../utils/uint-array.js';
  2. import {stripNewline} from '../io/strip-newline.js';
  3. // Retrieve `result.all` with synchronous methods
  4. export const getAllSync = ([, stdout, stderr], options) => {
  5. if (!options.all) {
  6. return;
  7. }
  8. if (stdout === undefined) {
  9. return stderr;
  10. }
  11. if (stderr === undefined) {
  12. return stdout;
  13. }
  14. if (Array.isArray(stdout)) {
  15. return Array.isArray(stderr)
  16. ? [...stdout, ...stderr]
  17. : [...stdout, stripNewline(stderr, options, 'all')];
  18. }
  19. if (Array.isArray(stderr)) {
  20. return [stripNewline(stdout, options, 'all'), ...stderr];
  21. }
  22. if (isUint8Array(stdout) && isUint8Array(stderr)) {
  23. return concatUint8Arrays([stdout, stderr]);
  24. }
  25. return `${stdout}${stderr}`;
  26. };