Giter VIP home page Giter VIP logo

node-orn's Introduction

orn npm-version

If you know JavaScript RegExp, you know orn, a file renamer just like String.prototype.replace(<pattern>, <replacement>) in cli.

Usage

Usage: orn <pattern> <replacement> [-d]

Arguments:

  <pattern>          The pattern to be replaced, could be a String or RegExp.
  <replacement>      The String to be replace with, Arrow Function is supported.

Options:

  -h, --help         Output usage information
  -v, --version      Output the version number
  -d, --dry-run      Show how the files will be renamed, but actually do nothing

Examples:

  orn 720p 1080P                        # Replace "720p" with "1080P".
  orn /720p/i 1080P                     # Replace "720p" or "720P" with "1080P".
  orn '/(\.js)$/i' '.min$1' -d          # Add ".min" to js files, in dry-run.
  orn '/\S+mp3$/' 'x=>x.toLowerCase()'  # Change mp3 filename to lowercase.

Switches

  • -d, --dry-run
    Show how the files will be renamed, but actually do nothing.

License

MIT © Amio

node-orn's People

Contributors

amio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-orn's Issues

2.0

  • commander -> minimist
  • mocha -> tape mocha is good.
  • standardjs
  • orn /regexp/g replacewith

Feature Enhancement - iteration and padding

I love orn, however it doesn't do everything I'd like it to do. I'd like to be able to generate number sequences and I'd like to be able to pad outputs. One use case for this sort of functionality is when you have a large number of shows you'd like to provide season / episode naming for.

Let's say you have a naming convention like:

001 - Episode name
...
101 - Episode name

and these episode are kept in folders like

Season1
Season2
...

Where season1 has 001 - 024, season2 has 025 - 048, etc.

One might want to change the naming to be formatted as follows:

S01E01 - Episode name
...
S01E024 - Episode name

S02E01 - Episode name
...
S02E24 - Episode name

Now I have modified my orm to allow me to do this. To accomplish this I changed the

return isArrowFn ? vm.runInNewContext(string) : string

line to

return isArrowFn ? vm.runInThisContext(string) : string

I added a global pad function (so you can access it from the new vm):

pad = function (n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}

I also added the global:

line = 0;

This allows me to use orm as follows:

orn '/\d\d\d/' 'x=>S01E${pad(++line, 2, 0)}'

Which changes

001 - Episode name ---> S01E01 - Episode name

I'm not altogether happy with my solution, but this was just me hacking things together for my personal needs. There's probably a better more general approach to adding iteration and padding. I think these two features would be a HUGE win for the tool. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.