Skip to content
jekr2 edited this page Jun 22, 2016 · 2 revisions

TOC

Modules

pkg2md

Classes

LogWrapper

Class which defines a logger wrapper usable in this module.

NOTE: This class is not to be intended to be called from outside this module!

MdWriter

Class which writes Markdown file.

Md

Utility class which wraps a Markdown string and provides useful operations on this string.

PkgReader

Class which reads an validates (by JSON schema) a package.json file.

PkgToMd

Class which converts a package.json to a MD file.

Constants

UTF8 : string

The 'utf8' constant.

DEFAULT_MD_FILE : string

The default Markdown file: 'README.md'.

DEFAULT_PKG_FILE : string

The default package file: 'package.json'.

DEFAULT_REGISTRY : string

The default registry: 'https://registry.npmjs.org/'.

DEPENDENCY_TYPE_PROD : string

The production dependency type: ''.

DEPENDENCY_TYPE_DEV : string

The development dependency type: 'dev'.

DEPENDENCY_TYPE_BUNDLED : string

The bundled dependency type: 'bundled'.

DEPENDENCY_TYPE_BUNDLE : string

The alternative bundled dependency type: 'bundle'.

DEPENDENCY_TYPE_OPTIONAL : string

The optional dependency type: 'optional'.

DEPENDENCY_TYPE_PEER : string

The peer dependency type: 'peer'.

NAME_REG_EXP : RegExp

A RegExp to parse a name in "flat" person strings, e.g. Barney Rubble in

Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)
EMAIL_REG_EXP : RegExp

A RegExp to parse an email in "flat" person strings, e.g. b@rubble.com in

Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)
URL_REG_EXP : RegExp

A RegExp to parse a URL in "flat" person strings, e.g. http://barnyrubble.tumblr.com/ in

Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)

Functions

createHeadlinePrefix(headlineDepth)Promise.<string>

Creates a headline prefix from given depth number.

personSort(person1, person2)number

Does a lower case person name sort.

loadPackageSchema()object

Loads the schema for package.json.

Typedefs

Person : object
Options : object

pkg2md

License: MIT

LogWrapper

Deprecated

Class which defines a logger wrapper usable in this module.

NOTE: This class is not to be intended to be called from outside this module!

Kind: global class
Access: protected

new LogWrapper([logger])

Constructs the LogWrapper.

Returns: LogWrapper - - The instance.

Param Type Default Description
[logger] logger | cli | console console Logger object.

Example

var logger = ...;
var logWrapper = new LogWrapper(logger);

logWrapper.logInstance : logger | cli | console

The logger instance.

Kind: instance property of LogWrapper
Access: private

logWrapper.info(msg)

Log the options with INFO level.

Kind: instance method of LogWrapper
Access: public

Param Type Description
msg string The message to log.

Example

var logger = ...;
var logWrapper = new LogWrapper(logger);
var msg = '...';
logWrapper.info(msg);

logWrapper.debug(msg)

Log the options with DEBUG level (if logger supports it, else with INFO).

Kind: instance method of LogWrapper
Access: public

Param Type Description
msg string The message to log.

Example

var logger = ...;
var logWrapper = new LogWrapper(logger);
var msg = '...';
logWrapper.debug(msg);

logWrapper.trace(msg)

Log the options with TRACE level (if logger supports it, else with DEBUG).

Kind: instance method of LogWrapper
Access: public
See: #debug

Param Type Description
msg string The message to log.

Example

var logger = ...;
var logWrapper = new LogWrapper(logger);
var msg = '...';
logWrapper.trace(msg);

logWrapper.error(msg)

Log the options with ERROR level.

Kind: instance method of LogWrapper
Access: public

Param Type Description
msg string The message to log.

Example

var logger = ...;
var logWrapper = new LogWrapper(logger);
var msg = '...';
logWrapper.error(msg);

logWrapper.verboseOptions(options) ⇒

Log the options with INFO level.

Kind: instance method of LogWrapper
Returns: A Promise containing the passed options object.
Access: public

Param Type Description
options Options The properties to log with INFO.

Example

var logger = ...;
var logWrapper = new LogWrapper(logger);
var options = {
    ...
};
logWrapper.verboseOptions(options)
    .then(function (options) {
        ...
    });

MdWriter

Class which writes Markdown file.

Kind: global class

new MdWriter()

Constructs the writer.

Returns: MdWriter - - The instance.

mdWriter.writeToFile(md, options, resolve, reject) ⇒ Promise.<string>

Writes a serialized object to file. Forces overwriting the destination file if options.force true.

Kind: instance method of MdWriter
Returns: Promise.<string> - - Containing the write success message to handle by caller (e.g. for logging).
Throws:

  • Error - If serialized JSON file could not be written due to any reason.

Access: private

Param Type Description
md Md The object holding markdown to write into file.
options Options The write options.
resolve function The Promise resolve callback.
reject function The Promise reject callback.

writeToFile~mkdirAndWrite() ℗

Ensures that all dirs exists for dest and writes the file.

Kind: inner method of writeToFile
Access: private

mdWriter.write(md, options) ⇒ Promise.<string>

Kind: instance method of MdWriter
Access: public

Param
md
options

Md

Utility class which wraps a Markdown string and provides useful operations on this string.

Kind: global class

new Md(pkg, options, logger)

Constructs the Markdown string from given package object.

Returns: Md - - The instance.

Param Type Description
pkg object The package.json representation as object.
options Options The
logger logger The logger to use.

md.append(content, [amount]) ⇒ Md

Appends the given content to the Markdown string and adds newlines.

Kind: instance method of Md
Returns: Md - - This instance for concatenated calls.
Access: public

Param Type Default Description
content string The content to append.
[amount] number 2 The amount of newlines to add.

md.appendCodeBlock(content, [amount], [language]) ⇒ Promise.<Md>

Appends the given content to the Markdown string as code block and adds newlines.

Kind: instance method of Md
Returns: Promise.<Md> - - This instance for concatenated calls.
Access: public

Param Type Default Description
content string The content to append as code block.
[amount] number 2 The amount of newlines to add.
[language] string The language of the code.

md.nl([amount]) ⇒ Promise.<Md>

Adds newlines of the given amount.

Kind: instance method of Md
Returns: Promise.<Md> - - This instance for concatenated calls.
Access: public

Param Type Default Description
[amount] number 2 The amount of newlines to add.

md.headline(content, headlineDepth) ⇒ Promise.<Md>

Kind: instance method of Md
Returns: Promise.<Md> - - This instance for concatenated calls.
Access: public

Param Type Description
content string The content used as headline.
headlineDepth number The depth of the headline.

md.title() ⇒ Promise.<Md>

Creates a title for the target document. A title is either applied from:

  1. options.title (if exists) or
  2. pkg.name (from package.json) If pkg.homepage is set, the title will be turned into a link to its URL value automatically.

Kind: instance method of Md
Returns: Promise.<Md> - - This instance for concatenated calls.
Access: public

md.description() ⇒ Promise.<Md>

Writes a description if options.desc is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - The Promise resolving with this.
Access: public

md.parseStringifiedPerson(person) ⇒ Promise.<Person>

Parses a "flat" person info string, e.g. which has such a pattern:

Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)

Kind: instance method of Md
Returns: Promise.<Person> - - A Promise resolving the person object.
Access: public

Param Type Description
person string The person's string to parse.

md.repository([headline]) ⇒ Promise.<Md>

Writes the repository section (a table overview about configured repositories).

Kind: instance method of Md
Returns: Promise.<Md> - - The Promise resolving with this for concatenated calls.
Access: public

Param Type Default Description
[headline] string "Repository" The headline for this section.

md.staff([headline]) ⇒ Promise.<Md>

Writes the collaborators section (a table overview about configured persons) including their roles:

  1. The author
  2. Contributors
  3. Maintainers The first column is the role, the second the name linked by the URL and the last contains the email link.

Kind: instance method of Md
Returns: Promise.<Md> - - The Promise resolving with this for concatenated calls.
Access: public

Param Type Default Description
[headline] string "Collaborators" The headline for this section.

md.installation([headline]) ⇒ Promise.<Md>

Writes the installation section.

Kind: instance method of Md
Returns: Promise.<Md> - - The Promise resolving with this for concatenated calls.
Access: public

Param Type Default Description
[headline] string "Installation" The headline for this section.

md.tests([headline]) ⇒ Promise.<Md>

Writes the tests section.

Kind: instance method of Md
Returns: Promise.<Md> - - The Promise resolving with this for concatenated calls.
Access: public

Param Type Default Description
[headline] string "Installation" The headline for this section.

md.dependencies(depType) ⇒ Promise.<Md>

Writes the dependencies info for given dependency type if options.deps is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.
Access: public

Param Type Description
depType string The type of dependencies.

md.bin([headline]) ⇒ Promise.<Md>

Writes the binary mappings if options.bin is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.
Access: public

Param Type Default Description
[headline] string "Binary Mappings" A headline for the section.

md.main([headline]) ⇒ Promise.<Md>

Writes the main executable if options.main is set to true. Writes the main executable if options.main is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.
Access: public

Param Type Default Description
[headline] string "Main File" A headline for the section.

md.config([headline]) ⇒ Promise.<Md>

Writes the NPM configuration mappings if options.config is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.
Access: public

Param Type Default Description
[headline] string "NPM Configuration" A headline for the section.

md.scripts([headline]) ⇒ Promise.<Md>

Writes the NPM scripts mappings if options.scripts is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.
Access: public

Param Type Default Description
[headline] string "NPM Scripts" A headline for the section.

md.engines([headline]) ⇒ Promise.<Md>

Writes the engines info if options.engines is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.
Access: public

Param Type Default Description
[headline] string "Engine Support" A headline for the section.

md.keywords([headline]) ⇒ Promise.<Md>

Writes the keywords if options.keywords is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.

Param Type Default Description
[headline] string "Keywords" A headline for the section.

md.os([headline]) ⇒ Promise.<Md>

Writes the OS support if options.os is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.

Param Type Default Description
[headline] string "OS Support" A headline for the section.

md.cpu([headline]) ⇒ Promise.<Md>

Writes the CPU support if options.cpu is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.

Param Type Default Description
[headline] string "CPU Support" A headline for the section.

md.license([headline]) ⇒ Promise.<Md>

Writes the License(s) if options.lic is set to true.

Kind: instance method of Md
Returns: Promise.<Md> - - A Promise resolving with this.

Param Type Default Description
[headline] string "License Licenses"

md.end([amount]) ⇒ string

Returns the Markdown string (optionally adds newlines), ususally after creation has finished.

Kind: instance method of Md
Returns: string - - The Markdown created.

Param Type Description
[amount] number The final amount of newlines.

PkgReader

Class which reads an validates (by JSON schema) a package.json file.

Kind: global class

new PkgReader()

Constructs the constants.

Returns: PkgReader - - The instance.

pkgReader.validate(pkg, options) ⇒ Promise

If pkg is invalid it rejects with a proper validation error, else it resolves with pkg object.

Kind: instance method of PkgReader
Returns: Promise - - Resolves with the pkg object.
Access: private

Param Type Description
pkg object The package object to validate.
options object The validate/read options.

pkgReader.read(options) ⇒ Promise.<T>

Kind: instance method of PkgReader

Param
options

PkgToMd

Class which converts a package.json to a MD file.

Kind: global class

new PkgToMd()

Constructs the ....

Returns: PkgToMd - - The instance.

pkgToMd.writeMarkdown(options) ⇒ Promise

Kind: instance method of PkgToMd
Returns: Promise - -

Param
options

UTF8 : string

The 'utf8' constant.

Kind: global constant
Access: public

DEFAULT_MD_FILE : string

The default Markdown file: 'README.md'.

Kind: global constant
Access: public

DEFAULT_PKG_FILE : string

The default package file: 'package.json'.

Kind: global constant
Access: public

DEFAULT_REGISTRY : string

The default registry: 'https://registry.npmjs.org/'.

Kind: global constant
Access: public

DEPENDENCY_TYPE_PROD : string

The production dependency type: ''.

Kind: global constant
Access: public

DEPENDENCY_TYPE_DEV : string

The development dependency type: 'dev'.

Kind: global constant
Access: public

DEPENDENCY_TYPE_BUNDLED : string

The bundled dependency type: 'bundled'.

Kind: global constant
Access: public

DEPENDENCY_TYPE_BUNDLE : string

The alternative bundled dependency type: 'bundle'.

Kind: global constant
Access: public

DEPENDENCY_TYPE_OPTIONAL : string

The optional dependency type: 'optional'.

Kind: global constant
Access: public

DEPENDENCY_TYPE_PEER : string

The peer dependency type: 'peer'.

Kind: global constant
Access: public

NAME_REG_EXP : RegExp

A RegExp to parse a name in "flat" person strings, e.g. Barney Rubble in

Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)

Kind: global constant
Access: public

EMAIL_REG_EXP : RegExp

A RegExp to parse an email in "flat" person strings, e.g. b@rubble.com in

Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)

Kind: global constant
Access: public

URL_REG_EXP : RegExp

A RegExp to parse a URL in "flat" person strings, e.g. http://barnyrubble.tumblr.com/ in

Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)

Kind: global constant
Access: public

createHeadlinePrefix(headlineDepth) ⇒ Promise.<string>

Creates a headline prefix from given depth number.

Kind: global function
Returns: Promise.<string> - - A Promise resolving the created prefix.
Access: private

Param Type Description
headlineDepth number The amount of hash-signs forprefix.

personSort(person1, person2) ⇒ number

Does a lower case person name sort.

Kind: global function
Access: private

Param Type Description
person1 Person | string The one person to sort against person2, if type is Object then person1.name is used for sorting!
person2 Person | string The one person to sort against person1, if type is Object then person2.name is used for sorting!

loadPackageSchema() ⇒ object

Loads the schema for package.json.

Kind: global function
Returns: object - - The JSON schema.
Access: private

Person : object

Kind: global typedef
Properties

Name Type Description
name string The name of the person.
email string The email of the person.
url string The URL of the person's page.

Options : object

Kind: global typedef
Properties

Name Type Default Description
origin string "yaml" The origin type.
target string "js" The target type.
src string | Readable | object The source.
dest string | Writable | object The destination.
indent number 4 The indention in files.
imports string The exports name for reading from JS source file or objects only.
exports string The exports name for usage in JS destination files only.

Clone this wiki locally