Skip to main content

Built and signed on GitHub Actions

Library to write out the contents of a JavaScript object structure to the file system in a granular directory structure.

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
3 months ago (0.1.4)
Package root>platform.ts
import { CurrentRuntime, Runtime } from "jsr:@cross/runtime@^1.1.0"; import { makeDenoPlatform } from "./platform_deno.ts"; import { makeNodePlatform } from "./platform_node.ts"; import type { DirectoryCreator, FileWriter } from "./interfaces.ts"; const nodeLikeRuntimes = [Runtime.Bun, Runtime.Node]; export function runtimeIsNodeLike(runtime: Runtime): boolean { return nodeLikeRuntimes.includes(runtime); } export interface Platform { fileWriter: FileWriter; directoryCreator: DirectoryCreator; } function getCurrentPlatform(): Platform { if (CurrentRuntime === Runtime.Deno) { return makeDenoPlatform(); } else if (runtimeIsNodeLike(CurrentRuntime)) { return makeNodePlatform(); } else { throw new Error("Unsupported platform/runtime"); } } export const platform: Platform = getCurrentPlatform();