npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@drovp/rename

v4.2.0

Published

Bulk rename files according to a configured template.

Downloads

32

Readme

@drovp/rename

Drovp plugin for bulk renaming files according to a configured template.

Features:

  • Powerful templating using JavaScript template literals.
  • Extensive variables and utilities available in template expressions.
  • Supports moving files up/down the directory tree, or between partitions/drives.
  • Computes crc32, md5, sha1, sha256, sha512 file checksums when template asks for it.
  • Extracts meta data (artist, title, ...) from media files when template asks for it.
  • Variables for paths to common platform folders such as home, downloads, documents, pictures, music, videos,...
  • Checks for file name conflicts before renaming.
  • If any error occurs during renaming, will attempt to revert all changes that happened before the error.

Templates

Templates are JavaScript template literals allowing embedded expressions.

All variables and utilities available in templates are documented in profile's instructions.

Examples

Serialize all dropped files with automatically padded 1 based index:

${N}${extname}

Offset the 1 based index by 10 and pad it to length of 4 with pad() util:

${pad(n + 10, 4)}${extname}

... which is just a shorthand for:

${String(n + 10).padStart(4, '0')}${extname}

Offset and determine pad length based on max index:

${pad(n + 10, String(files.length).length)}${extname}

Pad n to 4 letters while using underscore to fill gaps:

${pad(n, 4, '_')}${extname}

Replace all foo occurrences in a filename with bar:

${filename.replaceAll('foo', 'bar')}${extname}

Replace all foo or bar occurrences in a filename with baz:

${filename.replace(/foo|bar/gi, 'baz')}${extname}

Use audio file meta to name the file:

${meta.artist} - ${meta.album} - ${meta.title}${extname}

Use media file meta title to name the file, with a fallback to previous filename:

${meta.title || filename}${extname}

Requires On missing meta option to be set to Ignore, otherwise missing meta means error, and renaming will abort.

Uses ffprobe to retrive the meta, which considerably slows down renaming.


Prepend operation start time to each filename:

${Time(starttime).format('YYYY-MM-DD-HH.mm.ss')}-${basename}

Prepend file's creation time to each filename:

${Time(birthtime).format('YYYY-MM-DD-HH.mm.ss')}-${basename}

Serialize and prepend current seconds since unix epoch:

${Time(starttime).unix()} ${N}${basename}

Append CRC32 checksum to each filename:

${filename} [${CRC32}]${extname}

Same, but ensure the previous one is deleted (useful for re-encoded videos):

${filename.replace(/[\s\.\-_]*\[\w+\]\s*$/i, '')} [${CRC32}]${extname}

Note that generating file checksums will slow down renaming jobs, especially for big files.


Move files up one level in a directory tree, and prepend their original parent directory name to their filename:

../${dirbasename}-${basename}

Flatten files by placing them all into a common directory of all dropped files, and prepending their parent directory names relative from the common directory into their filename:

${commondir}/
${Path.relative(commondir, dirname).replace(/[\\\/\:]+/g, '-')}
-${basename}

(Big templates can be split into multiple lines to help with making sense of them. New lines will be removed in the final filename.)

Useful if you want to just throw a single directory into a profile with directory expansion enabled, and have it flatten all of the files inside.

If you drop in directory /foo with this structure:

/foo/
  ├ file1.jpg
  ├ bar/
  │ ├ file1.jpg
  │ └ file2.jpg
  └ baz/
    ├ file1.jpg
    ├ file2.jpg
    └ bam/
      ├ file1.jpg
      └ file2.jpg

You'll get:

/foo/
  ├ bar-file1.jpg
  ├ bar-file2.jpg
  ├ baz-bam-file1.jpg
  ├ baz-bam-file2.jpg
  ├ baz-file1.jpg
  ├ baz-file2.jpg
  └ file1.jpg

Move file into your platform's pictures folder, ensuring no conflicts by prepending it's original location to the file name:

${pictures}/${path.replace(/[\\\/\:]+/g, '-')}

Serialize all dropped files, using the filename of the 1st one as the base name for all:

${files[0].filename} ${N}${extname}

If you drop these files in:

bar.jpg
baz.jpg
foo.jpg

They'll be renamed to:

bar 1.jpg
bar 2.jpg
bar 3.jpg