Skip to content

[ENHANCEMENT] add ability to clone a semver instance #378

Open
@madhead

Description

@madhead

What / Why

I'm trying to compute a bunch of various increments for a specific version (TypeScript):

console.log(version.inc('major'))
console.log(version.inc('minor'))
console.log(version.inc('patch'))

The problem is the SemVer class itself is mutable, so each increment is computed against previous increment result. This is not what I need.

So, I need a way to clone this object, like.

console.log(new SemVer(version).inc('major'))
console.log(new SemVer(version).inc('minor'))
console.log(new SemVer(version).inc('patch'))

But the constructor of the SemVer (new SemVer(version)) doesn't create a new instance when passed another instance with the same options. So, again, the code doesn't work.

Is there a way to clone a SemVer?

Metadata

Metadata

Assignees

No one assigned

    Labels

    semver:majorbackwards-incompatible breaking changes

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions