version-track
Retrieve highest version from file(or dir) names if present
Last updated 2 years ago by vlad.blindu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install version-track 
SYNC missed versions from official npm registry.

VERSION_TRACK

Build Status Guven a path to the file system and a file name (or dir name) it will look for the highest version number present in the file name and return it

Example:

If the content of a folder is like the one below and we are requesting the last version of a "file-name.ext" file:

[
    ...
    file-name.ext
    file-name_v12.ext
    file-name_vers33.ext
    file-name_Vrs44-refactored.ext
    ...
]

getVersion will return 44 matching any combination of characters that could represent a version (_ver, _Ver, _vs, _VE...etc) as long as the pattern starts with an underscore and contains the v, e, r, s characters. An optional pattern can be provided to get a different match behaviour

For a folder:

[
    ...
    dummy-name.ext
    dummy-name_v12
    dummy-name_vers33.ext.another-ext
    dummy-name_vrs44-refactored.ext
    ...
]

getVersion will return 44

You get the idea.

Usage:

Usual

npm i file-version-track -S

Import/require and use it:

    import getLastVersion from 'version-track'

    const ver = getLastVersion(target, root, options)

Nothing fancy.

target is the base file name to be tracked (ex: my-amazing-video.mp4)

root is the directory to for (it will search recursively in nested dirs also)

options is optional and has the following props:

  • dirsOnly search for dirs only (surprisingly)
  • pattern set another match pattern
  • depth if you want to limit the search depth

Simple and easy. It's definitely not the package of the year but if it spares someone the time to write such functionality, it means it did the trick. Any improvement is welcomed.

Happy hacking

Current Tags

  • 1.0.1                                ...           latest (2 years ago)

2 Versions

  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (14)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |