Home > @asl-19/js-utils > getFirstStringOrString
Given an array or a string, return its first string element.
Signature:
getFirstStringOrString: (arrayOrString?: Array<string> | string) => string | undefined|
Parameter |
Type |
Description |
|---|---|---|
|
arrayOrString |
Array<string> | string |
(Optional) |
Returns:
string | undefined
This is useful for normalizing Next.js router.query (ParsedUrlQuery) values, which can be either a string or an array of strings.
If possible you should use getNormalizedQuery() (which uses this function internally) for this, but there may be special cases where it makes sense to use this function directly.
getFirstStringOrString(["foo1","foo2"])
// "foo1"
getFirstStringOrString("foo1")
// "foo1"