Giter Club home page Giter Club logo

file-info-annotator's Introduction

file-info-annotator

https://circleci.com/gh/jkrmr/file-info-annotator.svg?style=svg

A Node.js command-line script that asynchronously reads files from a directory and creates an annotated copy of each file (renamed with a timestamp) in a given target directory.

Each file is annotated with four pieces of information:

  1. The name of the source file (e.g. file.json)
  2. The source file’s relative path (e.g. files/original)
  3. The name of the annotated target file (e.g. file_EDITED_2015-1-1_12-44.json)
  4. The target file’s relative path (e.g. files/moved)

Usage

The script can be run with npm start and outputs the results of the script, as follows:

% npm start

renamed 5 files, with 0 errors

or, for example,

% npm start

ENOENT: no such file or directory, open './files/moved/random-json-list_EDITED_2017-09-07_21-26.json'
ENOENT: no such file or directory, open './files/moved/random-json-file-two_EDITED_2017-09-07_21-26.json'
renamed 3 files, with 2 errors (random-json-list.json, random-json-file-two.json)
% npm start

./files/original/anothertext-file.json: Unexpected token h in JSON at position 1
renamed 4 files, with 1 error (anothertext-file.json)

The script currently handles .txt and .json files.

To specify source and target directories, pass the --source or --target flags. Defaults are as follows:

% npm start -- --source files/original --target files/moved
% npm start -- -s files/original -t files/moved

Dependencies

To install dependencies, run yarn install.

Testing

Tests are written using the following libraries:

Run tests from the project root by issuing npm test.

% npm test

  completionMessage
    ✓ given no errors, pluralizes correctly
    ✓ given one error, pluralizes correctly
    ✓ given multiple errors, pluralizes correctly
    ✓ given no successes, pluralizes correctly
    ✓ given one success, pluralizes correctly
    ✓ given multiple successes, pluralizes correctly

  FileInfo
    ✓ parses original file info
    ✓ parses target file info
    ✓ has an object prop with data to be appended to source files

  MoveAnnotated
    .fileWithInfo
      ✓ invokes txt file handler if given txt extension
      ✓ invokes json file handler if given json extension
      ✓ raises if given an unrecognized type
    .txt
      ✓ writes text from source file, annotated, to target file
    .json
      ✓ writes json from source file, annotated, to target file

  Results
    #success
      ✓ pushes onto a success stack
    #failure
      ✓ pushes onto a failure stack

  #timestamp
    ✓ returns an appropriately formatted timestamp string in UTC


  17 passing (81ms)

file-info-annotator's People

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.