/
Zertmark
/
site_for_practice
Обзор
Документация
Войти
/
Zertmark
/
site_for_practice
Код
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/read-pkg/index.js
32 строки
927 B
zertmark
Github Pages setup
23 апр 2025, 15:06
23 апр 2025, 15:06
93ee661
Код
Авторство
О чём код?
import process from 'node:process'; import fs, {promises as fsPromises} from 'node:fs'; import path from 'node:path'; import {fileURLToPath} from 'node:url'; import parseJson from 'parse-json'; import normalizePackageData from 'normalize-package-data'; const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath; export async function readPackage({cwd, normalize = true} = {}) { cwd = toPath(cwd) || process.cwd(); const filePath = path.resolve(cwd, 'package.json'); const json = parseJson(await fsPromises.readFile(filePath, 'utf8')); if (normalize) { normalizePackageData(json); } return json; } export function readPackageSync({cwd, normalize = true} = {}) { cwd = toPath(cwd) || process.cwd(); const filePath = path.resolve(cwd, 'package.json'); const json = parseJson(fs.readFileSync(filePath, 'utf8')); if (normalize) { normalizePackageData(json); } return json; }