@map-colonies/read-pkg
    Preparing search index...

    @map-colonies/read-pkg

    read-pkg

    A lightweight utility to read and parse package.json files synchronously.

    npm install @mapcolonies/read-pkg
    
    import { readPackageJsonSync } from '@map-colonies/read-pkg';

    // Read package.json from current directory
    const packageJson = readPackageJsonSync();
    console.log(packageJson.name);

    // Read package.json from specific path
    const otherPackageJson = readPackageJsonSync('./path/to/package.json');
    console.log(otherPackageJson.version);

    Check the autogenerated documentation here.

    Synchronously reads and parses a package.json file.

    • path (optional): Path to the package.json file. Defaults to './package.json'
    • encoding (optional): File encoding to use. Defaults to 'utf-8'

    Returns a PackageJson object from the type-fest package.

    • SyntaxError: If the JSON content is invalid
    • Error: If the file cannot be read or does not exist