Refs: https://github.com/nodejs/node/issues/30674 PR-URL: https://github.com/nodejs/node/pull/33229 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
24 lines
432 B
JavaScript
24 lines
432 B
JavaScript
'use strict';
|
|
|
|
const { SafeMap } = primordials;
|
|
const { internalModuleReadJSON } = internalBinding('fs');
|
|
|
|
const cache = new SafeMap();
|
|
|
|
/**
|
|
*
|
|
* @param {string} path
|
|
*/
|
|
function read(path) {
|
|
if (cache.has(path)) {
|
|
return cache.get(path);
|
|
}
|
|
|
|
const [string, containsKeys] = internalModuleReadJSON(path);
|
|
const result = { string, containsKeys };
|
|
cache.set(path, result);
|
|
return result;
|
|
}
|
|
|
|
module.exports = { read };
|