Skip to main content

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