UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

18 lines (17 loc) 749 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.array_key_first = array_key_first; const _phpTypes_ts_1 = require("../_helpers/_phpTypes.js"); function array_key_first(input) { // discuss at: https://locutus.io/php/array_key_first/ // parity verified: PHP 8.3 // original by: Kevin van Zonneveld (https://kvz.io) // example 1: array_key_first({ a: 1, b: 2 }) // returns 1: 'a' // example 2: array_key_first(['x', 'y']) // returns 2: 0 // example 3: array_key_first([]) // returns 3: null const [firstKey] = Object.keys(input); return typeof firstKey === 'string' ? (0, _phpTypes_ts_1.normalizeArrayKey)(firstKey) : null; }