Comparing version 5.2.3 to 6.0.0
51
index.js
@@ -1,13 +0,9 @@ | ||
"use strict"; | ||
import { constants } from "node:fs"; | ||
import { access, mkdir, rename } from "node:fs/promises"; | ||
import { basename, dirname, extname, join } from "node:path"; | ||
import { promisify } from "node:util"; | ||
import { lock as lockCb, unlock as unlockCb } from "lockfile"; | ||
import { parseFile } from "music-metadata"; | ||
import slugify from "standard-slugify"; | ||
const { | ||
constants, | ||
promises: { access, mkdir, rename }, | ||
} = require("fs"); | ||
const { basename, dirname, extname, join } = require("path"); | ||
const { promisify } = require("util"); | ||
const { lock: lockCb, unlock: unlockCb } = require("lockfile"); | ||
const { parseFile } = require("music-metadata"); | ||
const slugify = require("standard-slugify"); | ||
const lock = promisify(lockCb); | ||
@@ -25,19 +21,3 @@ const unlock = promisify(unlockCb); | ||
/** | ||
* Renames an audio file using its metadata tags. Resolves with the new path. | ||
* | ||
* The first argument is the `path` of the file to be renamed. | ||
* | ||
* The second argument is an options object with the following properties: | ||
* | ||
* - `keepCase`: Keep the original case of the tags when renaming, | ||
* defaults to `false` | ||
* - `noop`: Perform a dry run without renaming the file, | ||
* defaults to `false` | ||
* - `separator`: The separator used to split the tags in the new name, | ||
* defaults to `"-"` | ||
* - `tags`: An array of the tags used in the new name, | ||
* defaults to `["artist", "title"]` | ||
*/ | ||
module.exports = async function ( | ||
export default async function ( | ||
path = "", | ||
@@ -49,5 +29,14 @@ { | ||
tags = ["artist", "title"], | ||
} = {} | ||
} = {}, | ||
) { | ||
const { common } = await parseFile(path); | ||
let common; | ||
try { | ||
({ common } = await parseFile(path)); | ||
} catch (error) { | ||
if (error.message.includes("ENOENT")) { | ||
throw Error(`Failed because '${path}' does not exist`); | ||
} else { | ||
throw Error(`Failed to parse file '${path}'`); | ||
} | ||
} | ||
const name = tags | ||
@@ -97,2 +86,2 @@ .reduce((tags, key) => { | ||
return newPath; | ||
}; | ||
} |
{ | ||
"name": "tagtoname", | ||
"version": "5.2.3", | ||
"version": "6.0.0", | ||
"description": "Renames audio files using the metadata tags", | ||
@@ -22,31 +22,37 @@ "keywords": [ | ||
"files": [ | ||
"bin/cli.js", | ||
"index.js" | ||
"cli.js", | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"main": "index.js", | ||
"bin": "bin/cli.js", | ||
"bin": { | ||
"tagtoname": "cli.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/rtomrud/tagtoname.git" | ||
"url": "git+https://github.com/rtomrud/tagtoname.git" | ||
}, | ||
"scripts": { | ||
"format": "prettier --check .", | ||
"lint": "eslint .", | ||
"start": "node bin/cli.js", | ||
"test": "jest", | ||
"posttest": "npm run lint" | ||
"start": "node ./cli.js", | ||
"test": "node --test --experimental-test-coverage", | ||
"posttest": "npm run lint && npm run format" | ||
}, | ||
"dependencies": { | ||
"getopts": "2.3.0", | ||
"glob": "10.3.12", | ||
"lockfile": "1.0.4", | ||
"music-metadata": "7.12.5", | ||
"standard-slugify": "3.1.1" | ||
"music-metadata": "7.14.0", | ||
"standard-slugify": "4.0.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "8.20.0", | ||
"eslint-config-pretty-strict": "8.1.1", | ||
"eslint-plugin-jest": "26.6.0", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"jest": "28.1.3", | ||
"prettier": "2.7.1" | ||
"@eslint/js": "9.1.1", | ||
"eslint": "8.57.0", | ||
"prettier": "3.2.5" | ||
}, | ||
"type": "module", | ||
"exports": { | ||
"types": "./index.d.ts", | ||
"default": "./index.js" | ||
} | ||
} |
# tagtoname | ||
[![build status](https://github.com/rtomrud/tagtoname/workflows/ci/badge.svg)](https://github.com/rtomrud/tagtoname/actions?query=branch%3Amaster+workflow%3Aci) | ||
[![npm version](https://badgen.net/npm/v/tagtoname)](https://www.npmjs.com/package/tagtoname) | ||
Renames audio files using the metadata tags | ||
@@ -17,3 +14,3 @@ | ||
``` | ||
Usage: tagtoname [-k] [-n] [-s separator] [-t tag]... file... | ||
Usage: tagtoname [-i] [-k] [-n] [-s separator] [-t tag]... file... | ||
@@ -24,2 +21,3 @@ Renames audio files using the metadata tags. | ||
-i, --ignore Ignore a glob pattern | ||
-k, --keep-case Keep the original case of the tags when renaming | ||
@@ -48,4 +46,7 @@ -n, --noop Dry run, show new paths without renaming the files | ||
# Rename all files in a folder. | ||
tagtoname folder/* | ||
# Rename all files in a directory. | ||
tagtoname directory/* | ||
# Rename all files in the current directory and its subdirectories | ||
tagtoname **/* | ||
``` | ||
@@ -59,4 +60,4 @@ | ||
# Dry run, output what would happen if we were to rename all files in a folder. | ||
tagtoname -n folder/* | ||
# Dry run, output what would happen if we were to rename all files in a directory. | ||
tagtoname -n directory/* | ||
@@ -66,3 +67,3 @@ # Rename a file using a custom separator. | ||
# "Reverie", the file will be renamed to "debussy/reverie.mp3" (since the | ||
# separator is "/", the folder "debussy" is created if needed). | ||
# separator is "/", the directory "debussy" is created if needed). | ||
tagtoname -s / file.mp3 | ||
@@ -108,3 +109,3 @@ | ||
// assuming the artist tag is "Queen" and the title tag is "Bohemian Rhapsody" | ||
// (since the separator is "/", the folder "queen" is created if needed). | ||
// (since the separator is "/", the directory "queen" is created if needed). | ||
tagtoname("/file.mp3", { separator: "/" }).then(console.log); | ||
@@ -111,0 +112,0 @@ // => /queen/bohemian-rhapsody.mp3 |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
11217
3
6
165
113
0
Yes
5
1
+ Addedglob@10.3.12
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedglob@10.3.12(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@2.3.6(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedmusic-metadata@7.14.0(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstandard-slugify@4.0.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removedmusic-metadata@7.12.5(transitive)
- Removedstandard-slugify@3.1.1(transitive)
Updatedmusic-metadata@7.14.0
Updatedstandard-slugify@4.0.0