Skip to content
You are viewing an outdated version of the documentation.
Click here to switch to the stable version (v6.6), or use the version switcher on the left to navigate between versions.

Utils

This is an overview of all the utility functions bound to the shopware global object. Utility functions provide many useful shortcuts for common tasks, see how to use them in your plugin here. Or see the code that registers them here

General functions

FunctionDescriptionLink
createIdReturns a uuid string in hex format. Generated with uuidlink
throttleCreates a throttled function that only invokes func at most once per every wait milliseconds.link
debounceCreates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.link
flowCreates a function that returns the result of invoking the given functions with the this binding of the created function, where each successive invocation is supplied the return value of the previous.link
getGets the value at path of objectlink

Object

FunctionDescriptionLink
deepCopyObjectDeep copy an object
hasOwnPropertyShorthand method for Object.prototype.hasOwnProperty
getObjectDiffGets a simple recursive diff of two objects. Does not consider an entity schema or entity related logic.
getArrayChangesCheck if the compared array has changes.
cloneDeepCreates recursively a clone of value.link
mergeThis method is like _.assign except that it recursively merges own and inherited enumerable string keyed properties of source objects into the destination object.link
mergeWithThis method is like _.merge except that it accepts customizer which is invoked to produce the merged values of the destination and source properties.link
deepMergeObjectDeep merge two objects
getGets the value at path of objectlink
setSets the value at path of objectlink
pickCreates an object composed of the picked object properties.link

Debug

FunctionDescription
warnGeneral logging function which provides a unified style of log messages for developers. Please keep the log in mind. Messages will be displayed in the developer console when they're running the application in development mode.
debugThe same as warn but instead of console.warn it uses console.error.

Format

FunctionDescription
currencyConverts a number to a formatted currency. Especially helpful for template filters.
dateFormats a Date object to a localized string with the native Intl.DateTimeFormat method
fileSizeFormats a number of bytes to a string with a unit
md5Generates a md5 hash with md5-es of a given value.

Dom

FunctionDescription
getScrollbarHeightReturns the scrollbar height of an HTML element.
getScrollbarWidthReturns the scrollbar width of an HTML element.
copyToClipboardUses the browser's copy function to copy a string

String

FunctionDescriptionLink
capitalizeStringConverts the first character of string to upper case and the remaining to lower case.link
camelCaseConverts string to camel case.link
kebabCaseConverts string to kebab case.link
snakeCaseConverts string to snake case.link
md5Generates a md5 hash with md5-es of a given value.
isEmptyOrSpacesGets if the content of the string is really empty. This does also removes any whitespaces that might exist in the text.
isUrlChecks if the provided value is a URL
isValidIpChecks if the provided value is an IP with this Regex

Type

FunctionDescriptionLink
isObjectChecks if value is the language type of Object. (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))link
isPlainObjectChecks if value is a plain object, that is, an object created by the Object constructor or one with a [[Prototype]] of null.link
isEmptyChecks if value is an empty object, collection, map, or set.link
isRegExpChecks if value is classified as a RegExp object.link
isArrayChecks if value is classified as an Array object.link
isFunctionChecks if value is classified as a Function object.link
isDateChecks if value is classified as a Date object.link
isStringChecks if value is classified as a String primitive or object.link
isBooleanChecks if value is classified as a boolean primitive or object.link
isEqualPerforms a deep comparison between two values to determine if they are equivalent.link
isNumberChecks if value is classified as a Number primitive or object.link
isUndefinedChecks if value is undefined.link

FileReader

FunctionDescriptionLink
readAsArrayBufferReads a file as an ArrayBufferlink
readAsDataURLReads a file as a Data-URLlink
readAsTextReads a file as textlink
getNameAndExtensionFromFileGets the name and extension from a file
getNameAndExtensionFromUrlGets the name and extension from a URL

Sort

FunctionDescription
afterSortSorts the elements by their after id property chain

Array

FunctionDescriptionLink
flattenDeepRecursively flattens array.link
removeRemoves all elements from array that predicate returns truthy for and returns an array of the removed elementslink
sliceCreates a slice of array from start up to, but not including, end.link
uniqByThis method is like _.uniq except that it accepts iteratee which is invoked for each element in array to generate the criterion by which uniqueness is computed.link