locutus
Version:
Locutus other languages' standard libraries to JavaScript for fun and educational purposes
25 lines (24 loc) • 1.18 kB
JavaScript
import { getPhpLocaleGroup } from "../_helpers/_phpRuntimeState.js";
import { setlocale } from "../strings/setlocale.js";
export function localeconv() {
// discuss at: https://locutus.io/php/localeconv/
// original by: Brett Zamir (https://brett-zamir.me)
// example 1: setlocale('LC_ALL', 'en_US')
// example 1: localeconv()
// returns 1: {decimal_point: '.', thousands_sep: '', positive_sign: '', negative_sign: '-', int_frac_digits: 2, frac_digits: 2, p_cs_precedes: 1, p_sep_by_space: 0, n_cs_precedes: 1, n_sep_by_space: 0, p_sign_posn: 1, n_sign_posn: 1, grouping: [], int_curr_symbol: 'USD ', currency_symbol: '$', mon_decimal_point: '.', mon_thousands_sep: ',', mon_grouping: [3, 3]}
const arr = {};
// ensure setup of localization variables takes place, if not already
setlocale('LC_ALL', 0);
// Make copies
const numeric = getPhpLocaleGroup('LC_NUMERIC', 'LC_NUMERIC');
if (!numeric) {
return arr;
}
Object.assign(arr, numeric);
const monetary = getPhpLocaleGroup('LC_MONETARY', 'LC_MONETARY');
if (!monetary) {
return arr;
}
Object.assign(arr, monetary);
return arr;
}