array
Internal library of helpers for manipulating array and list.
convertArrayToMapObject()β
function convertArrayToMapObject<T>(list): Maybe<Record<string, T>>
Returns a k/v object from an array of objects with a name
property.
Type Parametersβ
β’ T
the type of objects the list contains.
Parametersβ
listβ
Maybe
<T
[]>
the list of objects of type { name: any }
to be converted.
Returnsβ
Maybe
<Record
<string
, T
>>
an array of object values with name
as key, or undefined
if list
is not a valid array.
Exampleβ
import { convertArrayToMapObject } from '@graphql-markdown/utils/array';
convertArrayToMapObject([
{ name: true },
{ name: "test" },
{ name: 123 },
{ name2: 1234 },
]);
// Expected result: {
// true: { name: true },
// test: { name: "test" },
// "123": { name: 123 },
// }
Defined inβ
array.ts:77
toArray()β
function toArray(recordMap): Maybe<unknown[]>
Returns an array of values from a k/v object.
Parametersβ
recordMapβ
Maybe
<Record
<string
, unknown
>>
the key/value record object to be converted.
Returnsβ
Maybe
<unknown
[]>
an array of object values, or undefined
if recordMap
is not a valid object.
Exampleβ
import { toArray } from '@graphql-markdown/utils/array';
toArray({
bool: true,
string: "test",
number: 123,
array: ["one", "two"],
child: { key: "value" },
});
// Expected result: [true, "test", 123, ["one", "two"], { key: "value" }]
Defined inβ
array.ts:35