Crates.io | package-lock-json-parser |
lib.rs | package-lock-json-parser |
version | 0.4.0 |
source | src |
created_at | 2022-12-29 21:18:32.337268 |
updated_at | 2023-05-23 09:54:15.621299 |
description | A parser for package-lock.json files |
homepage | |
repository | https://github.com/robertohuertasm/package-lock-json-parser |
max_upload_size | |
id | 747541 |
size | 25,802 |
Easily parse package-lock.json
dependencies.
It supports lock file versions 1, 2, and 3.
// 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(())
}
Visit https://docs.rs/package-lock-json-parser/.
You will need cargo, the Rust package manager.
cargo build
cargo test