Skip to content

A truncate() or dec() method could be very useful #46

@ronkorving

Description

@ronkorving

I have a situation where I have an API version and my web frontend is aware of that version at application start. When doing live updates of the backend, I want to be able to decide which connections coming from frontend can be considered API stable with my backend (does this make sense?).

Example

  1. Server runs version 0.1.2
  2. User starts and thus now runs on version 0.1.2
  3. Server application gets upgraded to 0.1.3
  4. User interacts with server, but now there is a version mismatch.

In this case, I want to say 0.1.2 satisfies 0.1.x, so the APIs are compatible. Because all version information comes from variables here, I'm wondering how I should go about generating the 0.1.x range, or >=0.1.0 <0.2.0 range. To generate the latter I was thinking of this:

var version = '0.1.2';
var str = '>=' + semver.truncate(version, 'patch') + ' <' + semver.inc(version, 'minor');
// now do a satisfies check

The inc() method already exists, but truncate() does not. Do you think it would make sense to add a method like that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions