Generate inline background-image CSS style based on provided URL.

backgroundImageStyle(url: string): Object
Since: 1.0.0
Parameters
url (string) Background image URL or web address.
Returns
Object: CSS style for the provided background image address.
Example
backgroundImageStyle( 'https://interactive-examples.mdn.mozilla.net/media/examples/lizard.png' );

// => Object { backgroundImage: 'url(https://interactive-examples.mdn.mozilla.net/media/examples/lizard.png)' }

Extracts block specific CSS class name generated by Gutenberg editor. By default the block CSS class name is prefixed with wp-block keyword.

blockClassName(classNames: string): string
Since: 1.0.0
Parameters
classNames (string) CSS class names assigned to the block.
Returns
string: CSS class name generated for the block.
Example
blockClassName( 'wp-block-sixa-spacer custom-class-name test-class-name' );

// => string 'wp-block-sixa-spacer'

Extracts selected block style slug from the provided block specific CSS class names.

blockStyleSlug(classNames: string): string
Since: 1.0.0
Parameters
classNames (string) CSS class names assigned to the block.
Returns
string: Style name associated or selected for this block.
Example
blockStyleSlug( 'wp-block-sixa-spacer is-style-fancy test-class-name' );

// => string 'fancy'

Converts a string (e.g. 'yes' or 'no') to a bool.

stringToBoolean(input: (string | number)): boolean
Since: 1.0.0
Parameters
input ((string | number)) String to convert. If a bool is passed it will be returned as-is.
Returns
boolean: Converted value.
Example
stringToBoolean( 'yes' );

// => boolean true

Converts a bool to a 'yes' or 'no'.

booleanToString(input: (boolean | string)): string
Since: 1.0.0
Parameters
input ((boolean | string)) Bool to convert. If a string is passed it will first be converted to a bool.
Returns
string: Converted value.
Example
booleanToString( true );

// => string 'yes'

Creates an object composed of the (nested) picked object properties.

deepPick(collection: Object, paths: Array): Object
Since: 1.0.0
Parameters
collection (Object) The source object.
paths (Array) The property paths to pick.
Returns
Object: Returns the new object.
Example
deepPick( { id: 1, title: { rendered: 'Hello world!' } }, [ 'title.rendered' ] );

// => Object { title: 'Hello world!' }

Generate dim CSS class name based on the provided ratio or opacity.

dimRatioClassName(value: number): string
Since: 1.0.0
Parameters
value (number) Dim ratio or opacity. [0-100]
Returns
string: CSS class name generated from the ratio value.
Example
dimRatioClassName( 30 );

// => string 'has-background-dim-30'

Utility to make WordPress REST API requests. It's a wrapper around window.fetch.

fetchRequest(endpoint: string, args: Object): Promise
Since: 1.0.0
Parameters
endpoint (string) The endpoint that is being appended to the REST API root URL for the current site.
args (Object = {per_page:-1}) Request arguments.
Returns
Promise: The object that represents the eventual completion (or failure) of an asynchronous operation.
Example
fetchRequest( 'https://wptest.io/demo/wp-json/wp/v2/posts' ).then( ( data ) => console.log( data ) );

// => Promise 'https://wptest.io/demo/wp-json/wp/v2/posts'

Creates a function that performs a partial deep comparison between the id of a given object to the passed value. Returns true if the object value is equivalent, otherwise false.

This function is used as the default predicate for filterCollectionByValues.

matchId
Parameters
value (any) A value to check for.
Returns
Function: Predicate comparison function.
Related
https://lodash.com/docs/4.17.15#matchesProperty

Iterates over elements of values and returns all entries from collection for which predicate returns truthy.

Notice that this function preserves the order of values in the result set and is thus most useful if a collection must be filtered in an order that is specified by another collection.

filterCollectionByValues(values: Array, collection: Array, predicate: Function): Array
Since: 1.2.0
Parameters
values (Array) The values to search for.
collection (Array) The collection to search elements in.
predicate (Function = matchId) The predicate function to be applied in every iteration.
Returns
Array: All matching entries in collection.
Example
filterCollectionByValues( [ 1, 3 ], [ { id: 1, content: {} }, { id: 2, content: {} }, { id: 3, content: {} } ] );

// => Array [ { id: 1, content: {} }, { id: 3, content: {} } ]

Generates corresponding CSS based on the provided focal point picker values. Example focal point picker value: { x: 0.5, y: 0.1 } Corresponding CSS: background-position: 50% 10%;

focalPointStyle(value: Object): string
Since: 1.0.0
Parameters
value (Object) Focal point object value.
Returns
string: Calculated X and Y position based on the focalpoint object provided.
Example
focalPointStyle( { x: 0.67, y: 0.65 } );

// => string '67% 65%'

Gets a formatted version of the post content provided.

formattedContent(content: string): string
Since: 1.0.0
Parameters
content (string) Post content.
Returns
string: Formatted post content.
Example
formattedContent( '<span class=\"amount\"><bdi><span class=\"currency\">&pound;<\/span>11.05<\/bdi><\/span>' );

// => string '<span class="amount"><bdi><span class="currency">£</span>11.05</bdi></span>'

Extracts email addresses from mailto href link.

getMailTo(mailto: string): Array
Since: 1.0.0
Parameters
mailto (string) The href attribute value.
Returns
Array: Extracted email-addresses from the provided href value.
Example
getMailTo( 'mailto:info@example.com,info@test.com' );

// => Array '[ 'info@example.com', 'info@test.com' ]'

Converts a given hex-unicode into an Emoji icon.

hexToEmoji(value: string): any
Since: 1.0.0
Parameters
value (string) Emoji specific hex code.
Returns
any: Rendered Emoji.
Example
hexToEmoji( '1F603' );

// => string 😃

Insert an item into an array at a specific index.

insertAtIndex(input: Array, value: any, index: number): Array
Since: 1.0.0
Parameters
input (Array) The array to add to.
value (any) The value to insert.
index (number) Given array index to insert the value.
Returns
Array: Returns the new updated array.
Example
insertAtIndex( [ 'a', 'd', 'c' ], 'b', 1 );

// => Array [ 'a', 'b', 'c' ]

Check if value is classified as an array object and is not empty.

isNonEmptyArray(value: Array): boolean
Since: 1.0.0
Parameters
value (Array) The value to check.
Returns
boolean: Whether the argument provided is a non-empty array.
Example
isNonEmptyArray( [] );

// => boolean false

Determine whether the content is center positioned.

isPositionCenter(position: string): boolean
Since: 1.0.0
Parameters
position (string) The value to check.
Returns
boolean: Return true if content is center positioned.
Example
isPositionCenter( 'center' );

// => boolean true

Parses a JSON string, constructing the JavaScript value or object described by the string.

jsonify(input: string): Object
Since: 1.0.0
Parameters
input (string) The string to parse as JSON.
Returns
Object: Converted value to object.
Example
jsonify( '[{"id":1,"title":"sunt aut facere"},{"id":2,"title":"qui est esse"}]' );

// => Object [ { id: 1, title: 'sunt aut facere' }, { id: 2, title: 'qui est esse' } ]

Generates content-position CSS class name based on provided value.

positionToClassName(value: string): string
Since: 1.0.0
Parameters
value (string) CSS position value.
Returns
string: Corresponding CSS class name based on the provided position.
Example
positionToClassName( 'center right' );

// => string 'is-position-center-right'

Determines which element has the highest occurrence (mode) in the given array.

pullMode(input: Array): (null | string)
Since: 1.1.0
Parameters
input (Array) The array to process.
Returns
(null | string): Mode element or null.
Example
pullMode( ['pear', 'apple', 'orange', 'apple'] );

// => string "apple"

Removes an item from the array at a specific index.

removeAtIndex(input: Array, index: number): Array
Since: 1.0.0
Parameters
input (Array) The array to remove from.
index (number) Given array index to remove the value from.
Returns
Array: Returns the new updated array.
Example
removeAtIndex( [ 'a', 'd', 'b' ], 1 );

// => Array [ 'a', 'b' ]

Generates an array of objects to be passed to the SelectControl component. SelectControl allow users to select from a single-option menu. It functions as a wrapper around the browser’s native <select> element.

selectOptions(posts: Array, paths: string, none: Array): Array
Since: 1.0.0
Parameters
posts (Array) The response on the API call of array of post objects.
paths (string) The property paths to pick.
none (Array = optionNone) Text to display for showing no options being selected.
Returns
Array: An array of objects containing the label to be shown to the user, and value used to choose the selected value.
Example
selectOptions( [ { id: 1, title: { rendered: 'sunt aut facere' } }, { id: 2, title: { rendered: 'qui est esse' } } ], { id: 'value', 'title.rendered': 'label' } );

// => Array [ { value: 1, label: 'Hello world!' }, { value: 2, label: 'qui est esse' } ]

Generate shortcode.

shortcode(tagName: string, attributes: Object): string
Since: 1.0.0
Parameters
tagName (string) Shortcode tag name.
attributes (Object) Shortcode attributes.
Returns
string: Generated shortcode.
Example
shortcode( 'sixa_teams', { posts: [1, 2], number: 2 } );

// => string '[sixa_teams posts="1,2" number="2"]'

Slugifies every string, even when it contains unicode! Properly strips all HTML tags including script and style.

slugify(input: string): string
Since: 1.0.0
Parameters
input (string) The value to slugify.
Returns
string: Converted value to slug.
Example
slugify( 'unicode is ♥' );

// => string 'unicode-is-love'

Converts empty spaces to its corresponsding HTML character entity ( ). A non-breaking space is a space that will not break into a new line. Two words separated by a non-breaking space will stick together (not break into a new line). This method is handy when breaking the words might be disruptive.

spaceToNbsp(input: string): string
Since: 1.0.0
Parameters
input (string) String to convert.
Returns
string: Converted value.
Example
spaceToNbsp( 'Hello World! This is an example.' );

// => string 'Hello&nbsp;World!&nbsp;This&nbsp;is&nbsp;an&nbsp;example.'

Stringify an array of objects into a query string.

stringifyQuery(input: Array): string
Since: 1.0.0
Parameters
input (Array) The array of objects to query stringify.
Returns
string: Returns a stringified query.
Example
stringifyQuery( [ { product: '1885' }, { action: 'hook_name' } ] );

// => string 'product=1885&action=hook_name'

Converts a JavaScript object or value to a JSON string.

stringify(input: Object): string
Since: 1.0.0
Parameters
input (Object) The value to convert to a JSON object.
Returns
string: Converted value to string.
Example
stringify( [ { id: 1, title: 'sunt aut facere' }, { id: 2, title: 'qui est esse' } ] );

// => string '[{"id":1,"title":"sunt aut facere"},{"id":2,"title":"qui est esse"}]'