version-track

Retrieve highest version from file(or dir) names if present

Usage no npm install needed!

<script type="module">
  import versionTrack from 'https://cdn.skypack.dev/version-track';
</script>

README

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