Home Reference Source Test
import Util from 'wpxml2md/src/lib/util.js'
public class | source

Util

Provides utility function.

Test:

Static Method Summary

Static Public Methods
public static

This method returns the first index at which a given element can be found in the array

public static

Get a datetime from WordPress XML GMT

public static

Escape a regexp syntaxes.

public static

Check the existence of a file or folder.

public static

formatDate(date: Date, format: String): String

Converts the value of the Date object to its equivalent string representation using the specified format.

public static

isBlockElement(node: Node): Boolean

Check the node of a block element.

public static

isVoidElement(node: Node): Boolean

Check the node of a void element.

public static

Asynchronous mkdir(2).

public static

outerHTML(node: Node, content: String): String

Get the HTML string of an element with its contents converted.

public static

trim(str: String): String

Remove whitespace from both sides of a string.

public static

If the file or folder to the same path on exists, generates a unique path that does not duplicate.

Static Public Methods

public static arrayIndexOf(arr: Array, obj: Object): Number source

This method returns the first index at which a given element can be found in the array

Params:

NameTypeAttributeDescription
arr Array

Array.

obj Object

Element to locate in the array.

Return:

Number

If the success index, otherwise -1.

public static datetimeFromWpGMT(gmt: String): Object source

Get a datetime from WordPress XML GMT

Params:

NameTypeAttributeDescription
gmt String

String of GMT.

Return:

Object

Datetime.

public static escapeRegExp(str: String): String source

Escape a regexp syntaxes.

Params:

NameTypeAttributeDescription
str String

Original string.

Return:

String

Escaped string.

See:

public static existsSync(path: String): Boolean source

Check the existence of a file or folder.

Params:

NameTypeAttributeDescription
path String

Path of the file or folder.

Return:

Boolean

True if exists. Otherwise false.

public static formatDate(date: Date, format: String): String source

Converts the value of the Date object to its equivalent string representation using the specified format.

Params:

NameTypeAttributeDescription
date Date

Date and time. Default is current date and time.

format String

Date and time format string. Default is "YYYY-MM-DD hh:mm:ss.SSS".

Return:

String

Formatted string.

See:

public static isBlockElement(node: Node): Boolean source

Check the node of a block element.

Params:

NameTypeAttributeDescription
node Node

Node.

Return:

Boolean

Block element if "true".

public static isVoidElement(node: Node): Boolean source

Check the node of a void element.

Params:

NameTypeAttributeDescription
node Node

Node.

Return:

Boolean

Void element if "true".

public static mkdirSync(path: String): Boolean source

Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. mode defaults to 0o777.

Params:

NameTypeAttributeDescription
path String

Directory path.

Return:

Boolean

Success if "true".

public static outerHTML(node: Node, content: String): String source

Get the HTML string of an element with its contents converted.

Params:

NameTypeAttributeDescription
node Node

DOM node.

content String

Text.

Return:

String

HTML text.

public static trim(str: String): String source

Remove whitespace from both sides of a string.

Params:

NameTypeAttributeDescription
str String

String.

Return:

String

New string.1

public static uniquePathWithSequentialNumber(path: String, min: Number, max: Number): String source

If the file or folder to the same path on exists, generates a unique path that does not duplicate. e.g. "./test" to "test-1", "./test.md" to "./test-1.md"

Params:

NameTypeAttributeDescription
path String

Original path.

min Number

The minimum value of the sequential number. Defailt is 1.

max Number

The maximum value of the sequential number. Defailt is 256.

Return:

String

Success is the unique path (full path), failure is null. If not duplicate returns the original path.