A parser for Nodes semver in Rust

Overview

This crate is a pure Rust-based implementation of JavaScript's node-semver. That is, it's designed to be compatible with Node/NPM's particular flavor of semver (which the semver crate is not).

It is designed for Rust programs and libraries meant for JavaScript tooling, and does its best to stay compatible with node-semver.

It also supports serde serialization, converting versions and ranges to strings.

Usage

node-semver includes two main types: [Version] and [Range]. See the documentation for more details.:

use node_semver::{Range, Version};

let version: Version = "1.2.3".parse().unwrap();
let range: Range = "^1.2".parse().unwrap();

assert!(version.satisfies(&range));
Comments
  • Fix `.satisfies` bug for higher major/minor/path pre-release versions

    Fix `.satisfies` bug for higher major/minor/path pre-release versions

    Summary

    It seems satisfies doesn't take pre-releases into account:

    • 1.2.3-rc.0 will satisfy ^1.0.0 (but shouldn't)
    • 1.2.4-rc.0 will satisfy ^1.2.3-rc.0 (but shouldn't)

    This PR attempts to fix that!

    (I basically ported this over)

    opened by amitdahan 0
  • Unexpected panic

    Unexpected panic

    Parsing =0.7 causes a panic:

    internal error: entered unreachable code: Odd parsed version: (Exact, Partial { major: Some(0), minor: Some(7), patch: None, pre_release: [], build: [] })
    
    opened by road2react 0
  • Full proper loose parsing

    Full proper loose parsing

    Loose parsing is... interesting. This is what I found it translates to:

    * 01.02.03 -> 1.2.3
    * 1.2.3alpha -> 1.2.3-alpha
    * v 1.2.3 -> 1.2.3 (v1.2.3 is actually a valid "plain" version)
    * =1.2.3 -> 1.2.3 (already a valid range)
    * - 10 -> >=10.0.0 <11.0.0
    * 1.2.3 foo 4.5.6 -> 1.2.3 4.5.6
    * 1.2.3.4 -> invalid range
    * foo -> invalid range
    * 1.2beta4 -> invalid range
    

    The thing here is that NPM itself uses loose parsing for reading semver versions and ranges from packages. So if that's what you're using node-semver for (and it almost definitely is), then node-semver-rs needs to support it.

    In fact, I think it should be the ONLY parsing mode supported by node-semver-rs. Maybe we'll add a strict mode later.

    bug 
    opened by zkat 0
  • Fix error messaging

    Fix error messaging

    Right now, you get SemverErrorKind::Other a LOT, and that's... not great. We have a lot of the infra in place to have these be proper errors, but for some reason, it's not working. So fix it!

    bug 
    opened by zkat 0
  • internal error: entered unreachable code: This should not have parsed: ~0.x.0

    internal error: entered unreachable code: This should not have parsed: ~0.x.0

    The npm package querystring depends on phantomify ~0.x.0. Parsing this results in a panic.

    #9 before merging (3af6c068bc59f58683a536cbcf683c5cec69621f) did not panic.

    opened by danielhuang 0
Releases(v2.0.0)
  • v2.0.0(Sep 26, 2021)

    This is an almost full rewrite of the Range parser to make it work much more closely to how the JS node-semver parser works. Not by using regex, fortunately.

    As such, this is potentially a pretty breaking change, but it's a breaking change in the direction of compatibility.

    Please file issues for any compatibility issues you find and we'll fix them asap!

    Features

    • loose: rewrite to support loose mode better (#5) (20fb02d8)
      • BREAKING CHANGE: This accepts (and rejects) some semver strings that were valid before, and I'm not comfortable just calling thos e bugs. It also vastly reduces the number of "bad" semver parses by outright throwing out bad-looking data without warning you. This is literally what the JavaScript node-semver does. And so...
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Sep 26, 2021)

  • v1.0.0(Sep 24, 2021)

    Features

    • error: upgrade miette and change error API a bit (82625fd3)
      • BREAKING CHANGE: This changes the error API a bit. You may need to update code that handles errors by hand
    • version: add .satisfies() method to Version (da70b187)
    Source code(tar.gz)
    Source code(zip)
Owner
Felipe Seré
Felipe Seré
Lua bytecode parser written in Rust using nom, part of metaworm's lua decompiler

luac-parser (中文) lua字节码解析器, 目前支持 lua51, lua53, lua54 这是目前效果最好的lua反编译器 metaworm's luadec 的一部分 可以基于此代码定制你所需的lua字节码解析器,编译成WASM,让metaworm's luadec加载使用,来反编

metaworm 4 Mar 16, 2023
Slitter is a C- and Rust-callable slab allocator implemented primarily in Rust, with some C for performance or to avoid unstable Rust features.

Slitter is a less footgunny slab allocator Slitter is a classically structured thread-caching slab allocator that's meant to help write reliable long-

Backtrace Labs 133 Dec 5, 2022
A Rust crate for automatically generating C header files from Rust source file.

Please be aware that this crate is no longer actively maintained, please look into the much more feature rich cbindgen instead. rusty-cheddar rusty-ch

Sean Marshallsay 190 Nov 12, 2022
Rust-ffi-guide - A guide for doing FFI using Rust

Using unsafe for Fun and Profit A guide to traversing the FFI boundary between Rust and other languages. A rendered version is available here. This gu

Michael Bryan 261 Dec 1, 2022
Rust library for build scripts to compile C/C++ code into a Rust library

A library to compile C/C++/assembly into a Rust library/application.

Alex Crichton 1.3k Dec 21, 2022
Rust based WASM/JS bindings for ur-rust

ur-wasm-js WASM/JS bindings for the ur-rust rust library Getting started Installation Either build the library yourself with wasm-pack or install for

Lightning Digital Entertainment 5 Feb 28, 2024
A project for generating C bindings from Rust code

cbindgen   Read the full user docs here! cbindgen creates C/C++11 headers for Rust libraries which expose a public C API. While you could do this by h

Ryan Hunt 1.7k Jan 3, 2023
Automatically generates Rust FFI bindings to C (and some C++) libraries.

bindgen bindgen automatically generates Rust FFI bindings to C (and some C++) libraries. For example, given the C header doggo.h: typedef struct Doggo

The Rust Programming Language 3.2k Jan 4, 2023
Safe interop between Rust and C++

CXX — safe FFI between Rust and C++ This library provides a safe mechanism for calling C++ code from Rust and Rust code from C++, not subject to the m

David Tolnay 4.4k Jan 7, 2023
Safe Rust bridge for creating Erlang NIF functions

Rustler Documentation | Getting Started | Example Rustler is a library for writing Erlang NIFs in safe Rust code. That means there should be no ways t

Rusterlium 3.5k Jan 7, 2023
Bridge the gap between Haskell and Rust

Curryrs Curryrs (a play on the name of Haskell Curry, rs for Rust libraries, and it's pronunciation couriers) is a library for providing easy to use b

Michael Gattozzi 296 Oct 18, 2022
Rust in Haskell FFI Example

Provides an example for using Rust in Haskell. To use this you'll need cargo, rustc, cabal and GHC installed. To execute the example run the following

Michael Gattozzi 21 Oct 1, 2022
Run Java code from Rust!

Java Native Interface Bindings for Rust This library provides complete FFI bindings to the Java Native Interface, as well as a safe and intuitive wrap

Ben Anderson 66 Nov 28, 2022
Embedding Rust in Java

Java/Rust Example An example project showing how to call into Rust code from Java. OSX Linux Windows Requirements Java 7+ Rust (tested with 1.0, night

drrb 318 Jan 1, 2023
Rust-JDBC bindings

jdbc A Rust library that allows you to use JDBC and JDBC drivers. Usage First, add the following to your Cargo.toml: [dependencies] jdbc = "0.1" Next,

Aurora 18 Feb 9, 2022
Lua 5.3 bindings for Rust

rust-lua53 Aims to be complete Rust bindings for Lua 5.3 and beyond. Currently, master is tracking Lua 5.3.3. Requires a Unix-like environment. On Win

J.C. Moyer 150 Dec 14, 2022
Safe Rust bindings to Lua 5.1

rust-lua Copyright 2014 Lily Ballard Description This is a set of Rust bindings to Lua 5.1. The goal is to provide a (relatively) safe interface to Lu

Lily Ballard 124 Jan 5, 2023
Zero-cost high-level lua 5.3 wrapper for Rust

td_rlua This library is a high-level binding for Lua 5.3. You don't have access to the Lua stack, all you can do is read/write variables (including ca

null 47 May 4, 2022
Rust library to interface with Lua

hlua This library is a high-level binding for Lua 5.2. You don't have access to the Lua stack, all you can do is read/write variables (including callb

Pierre Krieger 488 Dec 26, 2022