locutus
Version:
Locutus other languages' standard libraries to JavaScript for fun and educational purposes
20 lines (19 loc) • 804 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.current = current;
const _arrayPointers_ts_1 = require("../_helpers/_arrayPointers.js");
function current(arr) {
// discuss at: https://locutus.io/php/current/
// parity verified: PHP 8.3
// original by: Brett Zamir (https://brett-zamir.me)
// note 1: Uses global: locutus to store the array pointer
// example 1: var $transport = ['foot', 'bike', 'car', 'plane']
// example 1: current($transport)
// returns 1: 'foot'
const state = (0, _arrayPointers_ts_1.getPointerState)(arr, true);
if (!state) {
return false;
}
const entry = (0, _arrayPointers_ts_1.getEntryAtCursor)(arr, state.cursor);
return entry ? entry[1] : false;
}