dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
997 stars 34 forks source link

Path API #94

Closed dsherret closed 1 year ago

dsherret commented 1 year ago

It would be nice if instead of writing stuff like this:

try {
  return JSON.parse(Deno.readTextFileSync(this.#filePath)) as { ip: string };
} catch (err) {
  if (err instanceof Deno.errors.NotFound) {
    return undefined;
  } else {
    throw err;
  }
}

...if I could instead do:

const maybeData = $.path(this.#filePath).maybeJsonSync<{ name: string }>();
const data = $.path(this.#filePath).jsonSync<{ name: string }>();

I will work on this probably this week.