findCommonPrefix Function

Defined in: packages/megadoc-plugin-markdown/lib/utils/findCommonPrefix.js

Given a list of strings, find the common substring they all start with. Very useful for extracting relative paths from a list of paths.

Signature

findCommonPrefix(array: Array.<String>, delim: String) -> String

Parameters (2)

array
Array.<String>

Your list of some-what related strings.

delim
String

If specified, the prefix will span until the last occurrence of this delimiter, like a '/' in a file-path so that any common characters after that last '/' don't get trimmed.

Defaults to: null

Return Value

String

The common prefix.

Contents