Home Reference Source
import ProjextRollupUtils from 'projext-plugin-rollup/src/plugins/utils.js'
public class | source

ProjextRollupUtils

This is a set of utility methods the Projext Rollup plugins use.

Static Method Summary

Static Public Methods
public static

cloneRegex(expression: RegExp, injectFlags: string): RegExp

Copies a regular expression and, if specified, inject extra flags.

public static

createLogger(plugin: string, logger: Logger): Logger

Validate and create a Logger instance for a plugin.

public static

escapeRegex(expression: string): string

Escapes special characters from a string in order to be used on a RegExp.

public static

formatPlaceholder(placeholder: string, info: Object): string

Formats a string path by replacing the [name] and [ext] placeholders.

Static Public Methods

public static cloneRegex(expression: RegExp, injectFlags: string): RegExp source

Copies a regular expression and, if specified, inject extra flags.

Params:

NameTypeAttributeDescription
expression RegExp

The expression to copy.

injectFlags string
  • optional
  • default: ''

Extra flags to add to the new expression. For example 'ig'.

Return:

RegExp

public static createLogger(plugin: string, logger: Logger): Logger source

Validate and create a Logger instance for a plugin. If the logger the plugin received on its options is an instance of Logger or has the same interface, it will "accept it" and return it; If the plugin didn't receive a logger, it will create a new instance of Logger and return it, but if the received logger is an invalid object, it will throw an error.

Params:

NameTypeAttributeDescription
plugin string

The plugin's instance name.

logger Logger
  • nullable: true

The logger the plugin received on its options.

Return:

Logger

Throw:

Error

If the logger the plugin received is not an instance of Logger and it doesn't have the same methods.

public static escapeRegex(expression: string): string source

Escapes special characters from a string in order to be used on a RegExp.

Params:

NameTypeAttributeDescription
expression string

The string to escape.

Return:

string

public static formatPlaceholder(placeholder: string, info: Object): string source

Formats a string path by replacing the [name] and [ext] placeholders. It uses the information path.parse would return.

Params:

NameTypeAttributeDescription
placeholder string

The string to format.

info Object

The result of path.parse on a file name.

info.name string

The name of the file.

info.ext string

The file extension.

Return:

string