UNPKG

express-ts-skeleton

Version:

This is a skeleton(boiler plate) for nodejs, express and typescript.

36 lines (35 loc) 1.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.pick = void 0; /* eslint-disable @typescript-eslint/no-explicit-any */ const joi_1 = __importDefault(require("joi")); //MARK: pick /** * Creates an object composed of the specified keys from the given object. * @param {object} object - The source object. * @param {string[]} keys - An array of keys to pick from the source object. * @returns {object} A new object with only the specified keys. */ const pick = (object, keys) => { return keys.reduce((obj, key) => { if (object && Object.prototype.hasOwnProperty.call(object, key)) { const value = object[key]; if (joi_1.default.isSchema(value) && value.type === "object" && !value._flags.unknown) { obj[key] = value.unknown(false); } else { obj[key] = object[key]; } } else { obj[key] = joi_1.default.object().keys({}).unknown(false); } return obj; }, {}); }; exports.pick = pick;