This article shows how to use Peaka functions in JEXL
It makes your value to string.
stringConcat(123456);
// => '123456'
It makes your value to string with your locale.
{
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
convertLocaleString(123456.789, "de", {
style: "currency",
currency: "EUR",
});
// => 123.456,79 €
It makes your value to string with your locale.
{
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
convertLocaleDateString("Tue Aug 15 2023 10:23:41", "de", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
});
// => Dienstag, 15. August 2023
It adds a new value to the array.
push([1, 2, 3, 4, 5], 6);
// => [1, 2, 3, 4, 5, 6]
It adds a new key and value to your object
addKey(
{
weekday: "long",
year: "numeric",
month: "long",
},
"day",
"numberic"
);
/* =>
{
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
}
*/
It deletes a key of your object.
removeKey(
{
weekday: "long",
year: "numeric",
month: "long",
},
"month"
);
/* =>
{
weekday: "long",
year: "numeric",
}
*/
It brings value of key that you want.
mapToKey([{ value: 11 }, { value: 22 }], "value");
// => [11,22]
It filters by your keys.
filterByKeys(
[
{ name: "Joe", surname: "Doe" },
{ name: "Can", surname: "Tuna" },
],
["surname"]
);
// => [{surname:'Doe'},{surname: 'Tuna'}]
It returns your object keys and values in arrays.
fromEntries({
a: "somestring",
b: 42,
});
// => [['a', 'something'], ['b', 42]]
It creates an object with your keys and values. You need to enter them by your order.
fromKeysAndValues(["one", "two", "three"], [1, 2, 3]);
// => { one: 1, two: 2, three: 3}
It return an unique id.
uuid();
// => 4d85bbb9-f602-40f9-bd07-48eda130a1b5
It return length of array.
len([1, 2, 3, 4, 5, 6]);
// => 6
It updates a key that you want. It find your old key by oldKey and replace with newKey.
updateKey(
{
a: "somestring",
b: 42,
},
"b",
"newKeyC"
);
/* =>
{
a: "somestring",
newKeyC: 42
}
*/
It finds your value by searchKey and returns value of it. If it doesn't find it or value of searchKey doesn't equal to value, it returns 'undefined'.
findDeep(
{
item: "string",
children: [
{
item: "string2",
children: [{ valueKey: "myValue" }],
},
],
},
"children",
"valueKey",
"myValue"
);
// => {valueKey: "myValue"}
It removes the element of given index.
removeIndex(["one", "two", "three"], 0);
// => ['two'. 'three']
It makes string your value.
value may be any type and it's required.
jsonStringify({ name: "John", age: 30, city: "New York" });
// => "{ name: "John", age: 30, city: "New York" }"
It parses your value.
value may be any type and it's required.
jsonStringify("{ name: 'John', age: 30, city: 'New York' }");
// => { name: "John", age: 30, city: "New York" }
It adds withQuotes from start and end of the string.
withQuotes("can tuna");
// => "can tuna"
It removes backslash from start and end of the string.
trimQuotes("\"How to add doublequotes\"");
// => can tuna
It sends a request.
fetch("https://jsonplaceholder.typicode.com/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
It returns an query parameter.
getQueryParameter("https://example.com?foo=1&bar=2", "foo");
// => 1
It returns all query parameters.
getQueryParameter("https://example.com?foo=1&foo=2", "foo");
// => [1, 2]
It returns date of now.
now();
// => 2023-08-15T12:53:50.862Z