@jsenv/filesystem
Advanced tools
Comparing version 4.9.5 to 4.9.6
{ | ||
"name": "@jsenv/filesystem", | ||
"version": "4.9.5", | ||
"version": "4.9.6", | ||
"license": "MIT", | ||
@@ -34,3 +34,3 @@ "repository": { | ||
"dependencies": { | ||
"@jsenv/urls": "2.4.1", | ||
"@jsenv/urls": "2.5.0", | ||
"@jsenv/url-meta": "8.5.0", | ||
@@ -37,0 +37,0 @@ "@jsenv/abort": "4.3.0", |
@@ -0,1 +1,2 @@ | ||
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"; | ||
import { readFileSync as readFileSyncNode } from "node:fs"; | ||
@@ -5,4 +6,14 @@ | ||
export const readFileSync = (value, { as = "buffer" } = {}) => { | ||
export const readFileSync = (value, { as } = {}) => { | ||
const fileUrl = assertAndNormalizeFileUrl(value); | ||
if (as === undefined) { | ||
const contentType = CONTENT_TYPE.fromUrlExtension(fileUrl); | ||
if (CONTENT_TYPE.isJson(contentType)) { | ||
as = "json"; | ||
} else if (CONTENT_TYPE.isTextual(contentType)) { | ||
as = "string"; | ||
} else { | ||
as = "buffer"; | ||
} | ||
} | ||
const buffer = readFileSyncNode(new URL(fileUrl)); | ||
@@ -9,0 +20,0 @@ if (as === "buffer") { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
136510
3979
+ Added@jsenv/humanize@1.2.7(transitive)
+ Added@jsenv/urls@2.5.0(transitive)
- Removed@jsenv/humanize@1.2.6(transitive)
- Removed@jsenv/urls@2.4.1(transitive)
Updated@jsenv/urls@2.5.0