@padhariyavishal/nextpress-config
Version:
Nextpress configuration
98 lines (97 loc) • 2.81 kB
JavaScript
;
/**
* Global variables
*
* src/globals.ts
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.formate_date = exports.array_pop = exports.array_push = exports.remove_duplicate = exports.json_filter = exports.json_decode = exports.json_encode = exports.prefix = void 0;
exports.prefix = "np_";
function json_encode(data) {
return JSON.stringify(data);
}
exports.json_encode = json_encode;
function json_decode(data) {
return JSON.parse(data);
}
exports.json_decode = json_decode;
/**
* Finds objects in an array that match a specified key-value pair.
* @param arr - The array of objects to search.
* @param key - The key to look for.
* @param value - The value to match.
* @returns An array of objects that contain the specified key-value pair.
*/
function json_filter(arr, key, value) {
return arr.filter((obj) => obj[key] === value);
}
exports.json_filter = json_filter;
/**
* Removes duplicate objects from an array based on a specified key.
* @param arr - The array of objects to filter.
* @param key - The key to determine uniqueness.
* @returns A new array with duplicates removed.
*/
function remove_duplicate(arr, key) {
const seenValues = new Set();
return arr.filter((obj) => {
const keyValue = obj[key];
if (seenValues.has(keyValue)) {
return false;
}
else {
seenValues.add(keyValue);
return true;
}
});
}
exports.remove_duplicate = remove_duplicate;
/**
* Pushes a new object to the end of the array.
* @param arr - The array to push the object to.
* @param item - The object to push to the array.
*/
function array_push(arr, item) {
arr.push(item);
}
exports.array_push = array_push;
/**
* Pops the last object from the array and returns it.
* @param arr - The array to pop the object from.
* @returns The last object in the array, or undefined if the array is empty.
*/
function array_pop(arr) {
return arr.pop();
}
exports.array_pop = array_pop;
/**
* Convert date into default date formate. example: Jan 1,2024
* @param date - The date to modify in default formate.
* @returns The date in a default formate.
*/
function formate_date(date) {
// Array of month names
const monthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
// Get the full year
const year = date.getFullYear();
// Get the month name
const month = monthNames[date.getMonth()];
// Get the day of the month
const day = date.getDate();
// Return the formatted date
return `${month} ${day}, ${year}`;
}
exports.formate_date = formate_date;