asort
Renaming files in ascending order
!Build Statustravis-badgetravis-url !Versionversion-badgeversion-url !Downloadsdownloads-badgedownloads-url !MIT Licensemit-license-badgemit-license-url !Dependency Statusdaviddm-badgedaviddm-url !NSP Statusnsp-badgensp-url !Greenkeeper badgegreenkeeper-badgegreenkeeper-url
!Code of Conductcoc-badgecoc-url
A package helps renaming files in an ascending order. Each renamed file will contain its own index starting from 1.
Pre-requisite
- Node.jsnode-js-url >= 8.6.0
- NPMnpm-url >= 5.3.0 (NPMnpm-url comes Node.jsnode-js-url so there is no need to install separately.)
How to use
It can be used as a dependency or as a CLI directly from your favorite terminal.To use it as a dependency
# Install it as a dependency in your project
npm install --save asort
# Import the package via 'require'
const { asort } = require('asort'); # OR const asort = require('asort').default;
# Import the package with ES module
import asort from 'asort';
To install the CLI
You can choose to either use the CLI directly with npxnpx-url or to install the CLI globally with NPMnpm-url.\ Please note that as of npxnpx-url is bundled with NPMnpm-url as of the version of 5.2.0npx-the-npm-package-runner-url.
# Use CLI with npx
$ npx asort <command>
# Install globally via NPM
$ npm install -g asort
Commands
- Show help via
-h
or--help
.
```bash # asort --help $ asort -h ```
- Show version via
-v
or--version
.
```bash # asort --version $ asort -v ```
- Rename files
```bash # Rename files in current directory $ asort ./
# Rename files with defined directory path $ asort ~/my-videos/
# Rename files with defined language for sorting files before renaming $ asort ~/my-videos/ -l "ja-JP"
# Rename files with RegExp + replacer function $ asort ~/my-videos/ -r "/^(\\S+)\\s\\S?(\\d)\\.(\\w+)\$/i" -p "\$1 - \$2.\$3" ```
API reference
asort(dirName, lang = 'en-US', regex, replace)
dirname
<stringstring-mdn-url> Path to the directory that contains files to be renamed.lang
<stringstring-mdn-url> Language of the files to be renamed. This is needed for sorting the files before renaming. Defaults toen-US
.regex
<stringstring-mdn-url|Regexregex-mdn-url> Custom RegExp to filter files that need to be renamed.replacer
<stringstring-mdn-url|Functionstring-replace-mdn-url> Custom replacer string or functionstring-replace-mdn-url when renaming the files.