js-randomness-predictor
Version:
Predict Math.random output in Node, Deno, Bun, Chrome, Firefox, and Safari
2 lines (1 loc) • 1.07 kB
JavaScript
import s from"node:fs";import i from"node:path";function a(o,e){const t=i.resolve(process.cwd(),o.export.toString()),n=i.dirname(t),r=s.existsSync(t),c=s.existsSync(n);if(r&&!s.statSync(t).isFile()){e._warnings?.push(`Export path must be to a file! ${t}`);return}if(i.extname(t)!==".json"){e._warnings?.push(`Export path must be to a .json file! ${t}`);return}if(r&&!o.force){e._warnings?.push("Export path already exists and '--force' was not used! Use '--force' to overwrite existing files.");return}if(!c&&!o.force){e._warnings?.push("One or more directories does not exist in export path and '--force' was not used! Use '--force' to create full path if it does not exist.");return}!c&&o.force&&s.mkdirSync(n,{recursive:!0}),f(t,e)}function f(o,e){try{const t={sequence:e.sequence,predictions:e.predictions,actual:e.actual};e.isCorrect!==void 0&&(t.isCorrect=e.isCorrect),s.writeFileSync(o,JSON.stringify(t,null,2),{encoding:"utf-8"}),e._info?.push(`Exported results to '${o}'`)}catch(t){e._warnings?.push(`Unable to export results! ${t.message}`)}}export{a as default};