5 releases (3 breaking)

0.4.0 May 23, 2023
0.3.0 May 13, 2023
0.2.0 Feb 2, 2023
0.1.1 Jan 3, 2023
0.1.0 Dec 29, 2022

#2386 in Parser implementations

Download history 287/week @ 2024-03-14 430/week @ 2024-03-21 243/week @ 2024-03-28 327/week @ 2024-04-04 322/week @ 2024-04-11 418/week @ 2024-04-18 312/week @ 2024-04-25 332/week @ 2024-05-02 234/week @ 2024-05-09 163/week @ 2024-05-16 440/week @ 2024-05-23 213/week @ 2024-05-30 238/week @ 2024-06-06 225/week @ 2024-06-13 346/week @ 2024-06-20 221/week @ 2024-06-27

1,046 downloads per month
Used in 8 crates (4 directly)

MIT license

25KB
436 lines

package-lock-json-parser

ActionsStatus Crates.io

Easily parse package-lock.json dependencies.

It supports lock file versions 1, 2, and 3.

Example

// Getting a full package lock json file.
// You'll get information about the lock file version and a list of v1 or v2 dependencies.
// v1 lock files will only have v1 dependencies while v3 lock files will only have v2 dependencies. 
// v2 lock files will get both v1 and v2 dependencies.
// Check this URL (https://docs.npmjs.com/cli/v9/configuring-npm/package-lock-json?v=true) if you want to learn more about package-lock.json fields.
use std::{error::Error, fs};
use package_lock_json::{parse, PackageLockJson};

fn main() -> Result<(), Box<dyn Error>> {
    let package_lock_json_text = fs::read_to_string("package-lock.json")?;
    let lock_file: PackageLockJson = parse(package_lock_json_text)?;
    println!("{:?}", lock_file);
    Ok(())
}
// If you just a new a simple list of dependencies try the parse_dependencies function.
use std::{error::Error, fs};
use package_lock_json::{parse_dependencies, SimpleDependency};

fn main() -> Result<(), Box<dyn Error>> {
    let package_lock_json_text = fs::read_to_string("package-lock.json")?;
    let dependencies: Vec<SimpleDependency> = parse_dependencies(package_lock_json_text)?;
    println!("{:?}", dependencies);
    Ok(())
}

Documentation

Visit https://docs.rs/package-lock-json-parser/.

Build

You will need cargo, the Rust package manager.

cargo build

Test

cargo test

Dependencies

~1–1.8MB
~37K SLoC