Skip to content

epubknowledge/contents

Repository files navigation

Epub Knowledge Contents

Code Climate maintainability Code Climate issues Github code size GitHub issues GitHub last commit GitHub forks GitHub stars Version

This package is a foundation block intended to be used for other NPM packages and is designed to retrieve all contents of a passed directory and return it as an object.

Install

npm:

npm i @epubknowledge/contents

yarn:

yarn add @epubknowledge/contents

If either command cause an error in the terminal reference this issue.

Use

const contents = require('@epubknowledge/contents')

Options

Currently this takes two options:

contents(directory, arguments)

Returned Object

Explained parameters returned and with an example from Moby Dick's package.opf:

{
  path: {
    full: '/OPS/package.opf', ## Full path of file that includes filename
    file: '/OPS/' ## Path without filename
  },
  filename: 'package.opf', ## The name of the file
  ext: '.opf', ## The file extension, will default to null on hidden or files that dont have an extension
  size: 22175, ## The size of the file
  dirname: 'OPS' ## The directory the file or folder is located in
}

Directory

The first option directory is required and accepts two path types:

  • relative: desktop
  • absolute: /Users/username/desktop

If you're still unaware of what the differences are read:

When directory is passed into contents() it will validate if is directory and and if it exists. If both tests fail the code will error out. If the submitted directory is relative it will build it as an absolute path.

Arguments

Second option takes regex and it can be either a string or array. If the regex passed is invalid the then returned object will be empty. For further help with regex visit Examples.

Disclaimer

Test ePub source files used in the regex examples and as a test case come from IDPF's epub example "Moby Dick"*.

Reference: IDPF | "Moby Dick"