// warning: This file is auto generated by `yarn build:tests` // Do not edit by hand! import { createRequire } from 'node:module' import { describe, it, expect } from 'vitest' process.env.TZ = 'UTC' const ini_set = require('../../../../src/php/info/ini_set.ts').ini_set const ini_get = require('../../../../src/php/info/ini_get.ts').ini_get const __locutus_source_fn = require('../../../../src/php/array/array_intersect_ukey.ts').array_intersect_ukey const __locutus_source_module_url = new URL("../../../../src/php/array/array_intersect_ukey.ts", import.meta.url) const __locutus_source_require = createRequire(__locutus_source_module_url) const __locutus_func_name = "array_intersect_ukey" const __locutus_module_js_code = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.array_intersect_ukey = array_intersect_ukey;\nconst _callbackResolver_ts_1 = require(\"../_helpers/_callbackResolver.ts\");\nconst _phpTypes_ts_1 = require(\"../_helpers/_phpTypes.ts\");\nfunction array_intersect_ukey(arr1, ...arraysAndCallback) {\n // discuss at: https://locutus.io/php/array_intersect_ukey/\n // original by: Brett Zamir (https://brett-zamir.me)\n // example 1: var $array1 = {blue: 1, red: 2, green: 3, purple: 4}\n // example 1: var $array2 = {green: 5, blue: 6, yellow: 7, cyan: 8}\n // example 1: array_intersect_ukey ($array1, $array2, function (key1, key2){ return (key1 === key2 ? 0 : (key1 > key2 ? 1 : -1)); })\n // returns 1: {blue: 1, green: 3}\n const retArr = {};\n const callback = arraysAndCallback.at(-1);\n if (typeof callback === 'undefined' || !(0, _phpTypes_ts_1.isPhpCallableDescriptor)(callback)) {\n throw new Error('array_intersect_ukey(): Invalid callback');\n }\n const arrays = arraysAndCallback.slice(0, -1).map((value) => (0, _phpTypes_ts_1.toPhpArrayObject)(value));\n const lastArrayIndex = arrays.length - 1;\n const keyComparator = (0, _callbackResolver_ts_1.resolveNumericComparator)(callback, 'array_intersect_ukey(): Invalid callback');\n arr1keys: for (const [k1, arr1Value] of (0, _phpTypes_ts_1.entriesOfPhpAssoc)(arr1)) {\n arrs: for (const [i, arr] of arrays.entries()) {\n for (const [k] of (0, _phpTypes_ts_1.entriesOfPhpAssoc)(arr)) {\n if (keyComparator(k, k1) === 0) {\n if (i === lastArrayIndex) {\n retArr[k1] = arr1Value;\n }\n // If the innermost loop always leads at least once to an equal value,\n // continue the loop until done\n continue arrs;\n }\n }\n // If it reaches here, it wasn't found in at least one array, so try next value\n continue arr1keys;\n }\n }\n return retArr;\n}" const __locutus_standalone_ts_code = "const entriesOfPhpAssoc = (value) => {\n return Object.entries(value);\n};\nfunction isObjectLike(value) {\n return typeof value === 'object' && value !== null;\n}\nfunction isPhpCallable(value) {\n return typeof value === 'function';\n}\nfunction isPhpCallableDescriptor(value) {\n if (typeof value === 'string') {\n return true;\n }\n if (isPhpCallable(value)) {\n return true;\n }\n if (!Array.isArray(value) || value.length < 2) {\n return false;\n }\n const callableDescriptor = value[1];\n return typeof callableDescriptor === 'string' || isPhpCallable(callableDescriptor);\n}\nfunction isPhpArrayObject(value) {\n return isObjectLike(value);\n}\nfunction toPhpArrayObject(value) {\n if (isPhpArrayObject(value)) {\n return value;\n }\n return {};\n}\nconst globalContext = typeof window === 'object' && window !== null ? window : typeof global === 'object' && global !== null ? global : {};\nfunction getPhpGlobalEntry(key) {\n const value = globalContext[key];\n return typeof value === 'undefined' ? undefined : value;\n}\nfunction getPhpObjectEntry(value, key) {\n if ((typeof value !== 'object' && typeof value !== 'function') || value === null) {\n return undefined;\n }\n let current = value;\n while (current) {\n const descriptor = Object.getOwnPropertyDescriptor(current, key);\n if (descriptor) {\n if (typeof descriptor.get === 'function') {\n const getterValue = descriptor.get.call(value);\n return typeof getterValue === 'undefined' ? undefined : getterValue;\n }\n const directValue = descriptor.value;\n return typeof directValue === 'undefined' ? undefined : directValue;\n }\n current = Object.getPrototypeOf(current);\n }\n return undefined;\n}\nfunction resolvePhpCallable(callback, options) {\n if (isPhpCallable(callback)) {\n return { fn: callback, scope: null };\n }\n if (typeof callback === 'string') {\n const candidate = getPhpGlobalEntry(callback);\n if (isPhpCallable(candidate)) {\n return { fn: candidate, scope: null };\n }\n throw new Error(options.invalidMessage);\n }\n if (Array.isArray(callback) && callback.length >= 2) {\n const scopeDescriptor = callback[0];\n const callableDescriptor = callback[1];\n let scope;\n if (typeof scopeDescriptor === 'string') {\n scope = getPhpGlobalEntry(scopeDescriptor);\n if (typeof scope === 'undefined' && options.missingScopeMessage) {\n throw new Error(options.missingScopeMessage(scopeDescriptor));\n }\n }\n else {\n scope = scopeDescriptor;\n }\n if (isPhpCallable(callableDescriptor)) {\n return { fn: callableDescriptor, scope };\n }\n if (typeof callableDescriptor === 'string' && (isObjectLike(scope) || typeof scope === 'function')) {\n const candidate = getPhpObjectEntry(scope, callableDescriptor);\n if (isPhpCallable(candidate)) {\n return { fn: candidate, scope };\n }\n }\n }\n throw new Error(options.invalidMessage);\n}\nfunction resolveNumericComparator(callback, invalidMessage) {\n const resolved = resolvePhpCallable(callback, { invalidMessage });\n return (left, right) => Number(resolved.fn.apply(resolved.scope, [left, right]));\n}\nfunction array_intersect_ukey(arr1, ...arraysAndCallback) {\n // discuss at: https://locutus.io/php/array_intersect_ukey/\n // original by: Brett Zamir (https://brett-zamir.me)\n // example 1: var $array1 = {blue: 1, red: 2, green: 3, purple: 4}\n // example 1: var $array2 = {green: 5, blue: 6, yellow: 7, cyan: 8}\n // example 1: array_intersect_ukey ($array1, $array2, function (key1, key2){ return (key1 === key2 ? 0 : (key1 > key2 ? 1 : -1)); })\n // returns 1: {blue: 1, green: 3}\n const retArr = {};\n const callback = arraysAndCallback.at(-1);\n if (typeof callback === 'undefined' || !isPhpCallableDescriptor(callback)) {\n throw new Error('array_intersect_ukey(): Invalid callback');\n }\n const arrays = arraysAndCallback.slice(0, -1).map((value) => toPhpArrayObject(value));\n const lastArrayIndex = arrays.length - 1;\n const keyComparator = resolveNumericComparator(callback, 'array_intersect_ukey(): Invalid callback');\n arr1keys: for (const [k1, arr1Value] of entriesOfPhpAssoc(arr1)) {\n arrs: for (const [i, arr] of arrays.entries()) {\n for (const [k] of entriesOfPhpAssoc(arr)) {\n if (keyComparator(k, k1) === 0) {\n if (i === lastArrayIndex) {\n retArr[k1] = arr1Value;\n }\n // If the innermost loop always leads at least once to an equal value,\n // continue the loop until done\n continue arrs;\n }\n }\n // If it reaches here, it wasn't found in at least one array, so try next value\n continue arr1keys;\n }\n }\n return retArr;\n}" const __locutus_standalone_js_code = "// php/_helpers/_phpTypes (Locutus helper dependency)\nfunction isObjectLike(value) {\n return typeof value === 'object' && value !== null;\n}\nfunction isPhpCallable(value) {\n return typeof value === 'function';\n}\nfunction isPhpCallableDescriptor(value) {\n if (typeof value === 'string') {\n return true;\n }\n if (isPhpCallable(value)) {\n return true;\n }\n if (!Array.isArray(value) || value.length < 2) {\n return false;\n }\n const callableDescriptor = value[1];\n return typeof callableDescriptor === 'string' || isPhpCallable(callableDescriptor);\n}\nfunction toPhpArrayObject(value) {\n if (isPhpArrayObject(value)) {\n return value;\n }\n return {};\n}\nconst isPhpArrayObject = isObjectLike;\n// php/_helpers/_phpRuntimeState (Locutus helper dependency)\nconst globalContext = typeof window === 'object' && window !== null ? window : typeof global === 'object' && global !== null ? global : {};\nfunction getPhpGlobalEntry(key) {\n const value = globalContext[key];\n return typeof value === 'undefined' ? undefined : value;\n}\nfunction getPhpObjectEntry(value, key) {\n if ((typeof value !== 'object' && typeof value !== 'function') || value === null) {\n return undefined;\n }\n let current = value;\n while (current) {\n const descriptor = Object.getOwnPropertyDescriptor(current, key);\n if (descriptor) {\n if (typeof descriptor.get === 'function') {\n const getterValue = descriptor.get.call(value);\n return typeof getterValue === 'undefined' ? undefined : getterValue;\n }\n const directValue = descriptor.value;\n return typeof directValue === 'undefined' ? undefined : directValue;\n }\n current = Object.getPrototypeOf(current);\n }\n return undefined;\n}\n// php/_helpers/_callbackResolver (Locutus helper dependency)\nfunction resolvePhpCallable(callback, options) {\n if (isPhpCallable(callback)) {\n return { fn: callback, scope: null };\n }\n if (typeof callback === 'string') {\n const candidate = getPhpGlobalEntry(callback);\n if (isPhpCallable(candidate)) {\n return { fn: candidate, scope: null };\n }\n throw new Error(options.invalidMessage);\n }\n if (Array.isArray(callback) && callback.length >= 2) {\n const scopeDescriptor = callback[0];\n const callableDescriptor = callback[1];\n let scope;\n if (typeof scopeDescriptor === 'string') {\n scope = getPhpGlobalEntry(scopeDescriptor);\n if (typeof scope === 'undefined' && options.missingScopeMessage) {\n throw new Error(options.missingScopeMessage(scopeDescriptor));\n }\n }\n else {\n scope = scopeDescriptor;\n }\n if (isPhpCallable(callableDescriptor)) {\n return { fn: callableDescriptor, scope };\n }\n if (typeof callableDescriptor === 'string' && (isObjectLike(scope) || typeof scope === 'function')) {\n const candidate = getPhpObjectEntry(scope, callableDescriptor);\n if (isPhpCallable(candidate)) {\n return { fn: candidate, scope };\n }\n }\n }\n throw new Error(options.invalidMessage);\n}\nfunction resolveNumericComparator(callback, invalidMessage) {\n const resolved = resolvePhpCallable(callback, { invalidMessage });\n return (left, right) => Number(resolved.fn.apply(resolved.scope, [left, right]));\n}\n// php/array/array_intersect_ukey (target function module)\nfunction array_intersect_ukey(arr1, ...arraysAndCallback) {\n // discuss at: https://locutus.io/php/array_intersect_ukey/\n // original by: Brett Zamir (https://brett-zamir.me)\n // example 1: var $array1 = {blue: 1, red: 2, green: 3, purple: 4}\n // example 1: var $array2 = {green: 5, blue: 6, yellow: 7, cyan: 8}\n // example 1: array_intersect_ukey ($array1, $array2, function (key1, key2){ return (key1 === key2 ? 0 : (key1 > key2 ? 1 : -1)); })\n // returns 1: {blue: 1, green: 3}\n const retArr = {};\n const callback = arraysAndCallback.at(-1);\n if (typeof callback === 'undefined' || !isPhpCallableDescriptor(callback)) {\n throw new Error('array_intersect_ukey(): Invalid callback');\n }\n const arrays = arraysAndCallback.slice(0, -1).map((value) => toPhpArrayObject(value));\n const lastArrayIndex = arrays.length - 1;\n const keyComparator = resolveNumericComparator(callback, 'array_intersect_ukey(): Invalid callback');\n arr1keys: for (const [k1, arr1Value] of Object.entries(arr1)) {\n arrs: for (const [i, arr] of arrays.entries()) {\n for (const [k] of Object.entries(arr)) {\n if (keyComparator(k, k1) === 0) {\n if (i === lastArrayIndex) {\n retArr[k1] = arr1Value;\n }\n // If the innermost loop always leads at least once to an equal value,\n // continue the loop until done\n continue arrs;\n }\n }\n // If it reaches here, it wasn't found in at least one array, so try next value\n continue arr1keys;\n }\n }\n return retArr;\n}" const __locutus_eval_function = (compiledCode: string): ((...args: unknown[]) => unknown) => { const evaluator = new Function('require', compiledCode + '\nreturn ' + __locutus_func_name + ';') return evaluator(__locutus_source_require) as (...args: unknown[]) => unknown } const __locutus_eval_module_export = (compiledCode: string, exportName: string): ((...args: unknown[]) => unknown) => { const module = { exports: {} as { [key: string]: unknown } } const exports = module.exports const evaluator = new Function('exports', 'module', 'require', compiledCode) evaluator(exports, module, __locutus_source_require) return module.exports[exportName] as (...args: unknown[]) => unknown } const __locutus_module_js_fn = __locutus_eval_module_export(__locutus_module_js_code, __locutus_func_name) const __locutus_standalone_ts_fn = __locutus_eval_function(__locutus_standalone_ts_code) const __locutus_standalone_js_fn = __locutus_eval_function(__locutus_standalone_js_code) describe('src/php/array/array_intersect_ukey.ts (tested in test/generated/php/array/array_intersect_ukey.vitest.ts)', function () { it('should pass example 1', function () { const expected = {blue: 1, green: 3} const __locutus_variants: Array<{ name: string; fn: (...args: unknown[]) => unknown }> = [ { name: "source", fn: __locutus_source_fn }, { name: "module-js", fn: __locutus_module_js_fn }, { name: "standalone-ts", fn: __locutus_standalone_ts_fn }, { name: "standalone-js", fn: __locutus_standalone_js_fn }, ] const __locutus_run_example = (array_intersect_ukey: typeof __locutus_source_fn) => { var $array1 = {blue: 1, red: 2, green: 3, purple: 4} var $array2 = {green: 5, blue: 6, yellow: 7, cyan: 8} return array_intersect_ukey ($array1, $array2, function (key1, key2){ return (key1 === key2 ? 0 : (key1 > key2 ? 1 : -1)); }) } for (const __locutus_variant of __locutus_variants) { ;(globalThis as { $locutus?: unknown }).$locutus = undefined const result = __locutus_run_example(__locutus_variant.fn as typeof __locutus_source_fn) expect(result).toEqual(expected) } }) })