keyValues
Manipulate object with key-values methods. This is convenient to convert free shaped objects to types compatible with GraphQL types.
objectToKeyValues
Converts an object to key values format
import { objectToKeyValues } from "@front-commerce/core/keyValues";
const object = {
product: "red",
color: "blue",
size: "XL",
};
console.log(objectToKeyValues(obj));
/**
* [
* {
* key: "product",
* value: "red"
* },
* {
* key: "color",
* value: "blue"
* },
* {
* key: "size",
* value: "XL"
* }
* ]
*/
keyValuesToObject
Converts a key values array to an object
import { keyValuesToObject } from "@front-commerce/core/keyValues";
const keyValues = [
{
key: "product",
value: "red",
},
{
key: "color",
value: "blue",
},
{
key: "size",
value: "XL",
},
];
console.log(keyValuesToObject(keyValues));
/**
* {
* product: "red",
* color: "blue",
* size: "XL"
* }
*/