UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

32 lines (25 loc) 945 B
'use strict'; var clone = require('clone'); var objFilter = require('../../../v1/basics/objFilter.cjs'); // @ts-nocheck /** * Creates a deep clone of a login object and attaches the given database name to it, * if the input types are valid. * * @param {string} database - The name of the database to associate with the user. * @param {Object} login - The login object that contains user data. * @param {Object} login.data - The nested data object inside the login object. * @returns {Object|null} A cloned and modified login object with the database name attached, or null if invalid input. */ function sameUser(database, login) { // Validator if (typeof database === 'string' && objFilter.objType(login, 'object') && objFilter.objType(login.data, 'object')) { // Result const result = clone(login); result.data.database = database; return result; } // Nope else return null; } module.exports = sameUser;