Install via yarn add locutus and import:
import { assert_options } from 'locutus/php/info/assert_options'.
Or with CommonJS: const { assert_options } = require('locutus/php/info/assert_options')
Use a bundler that supports tree-shaking so you only ship the functions you actually use.
Vite,
webpack,
Rollup, and
Parcel
all handle this. For server-side use this is less of a concern.
Examples
These examples are extracted from test cases that automatically verify our functions against their native counterparts.
#
code
expected result
1
assert_options('ASSERT_CALLBACK')
null
Dependencies
This function uses the following Locutus functions:
exportfunctionassert_options(what: string, _value?: AssertOptionValue): string | number | null { // discuss at: https://locutus.io/php/assert_options/ // original by: Brett Zamir (https://brett-zamir.me) // example 1: assert_options('ASSERT_CALLBACK') // returns 1: null
letiniKey: string letdefaultVal: number | null switch (what) { case'ASSERT_ACTIVE': iniKey = 'assert.active' defaultVal = 1 break case'ASSERT_WARNING': { iniKey = 'assert.warning' defaultVal = 1 let msg = 'We have not yet implemented warnings for us to throw ' msg += 'in JavaScript (assert_options())' thrownewError(msg) } case'ASSERT_BAIL': iniKey = 'assert.bail' defaultVal = 0 break case'ASSERT_QUIET_EVAL': iniKey = 'assert.quiet_eval' defaultVal = 0 break case'ASSERT_CALLBACK': iniKey = 'assert.callback' defaultVal = null break default: thrownewError('Improper type for assert_options()') }
// I presume this is to be the most recent value, instead of the default value const iniVal = ini_get(iniKey) return iniVal === '' ? defaultVal : iniVal }
let iniKey let defaultVal switch (what) { case'ASSERT_ACTIVE': iniKey = 'assert.active' defaultVal = 1 break case'ASSERT_WARNING': { iniKey = 'assert.warning' defaultVal = 1 let msg = 'We have not yet implemented warnings for us to throw ' msg += 'in JavaScript (assert_options())' thrownewError(msg) } case'ASSERT_BAIL': iniKey = 'assert.bail' defaultVal = 0 break case'ASSERT_QUIET_EVAL': iniKey = 'assert.quiet_eval' defaultVal = 0 break case'ASSERT_CALLBACK': iniKey = 'assert.callback' defaultVal = null break default: thrownewError('Improper type for assert_options()') }
// I presume this is to be the most recent value, instead of the default value const iniVal = ini_get(iniKey) return iniVal === '' ? defaultVal : iniVal }
return { ini, locales, localeCategories, pointers, locale_default: localeDefault, } }
// php/info/ini_get (Locutus dependency module) functionini_get(varname: string): string { // discuss at: https://locutus.io/php/ini_get/ // original by: Brett Zamir (https://brett-zamir.me) // note 1: The ini values must be set by ini_set or manually within an ini file // example 1: ini_set('date.timezone', 'Asia/Hong_Kong') // example 1: ini_get('date.timezone') // returns 1: 'Asia/Hong_Kong'
if (entry && entry.local_value !== undefined) { if (entry.local_value === null) { return'' } returnString(entry.local_value) }
return'' }
// php/info/assert_options (target function module) typeAssertOptionValue = PhpRuntimeValue
functionassert_options(what: string, _value?: AssertOptionValue): string | number | null { // discuss at: https://locutus.io/php/assert_options/ // original by: Brett Zamir (https://brett-zamir.me) // example 1: assert_options('ASSERT_CALLBACK') // returns 1: null
letiniKey: string letdefaultVal: number | null switch (what) { case'ASSERT_ACTIVE': iniKey = 'assert.active' defaultVal = 1 break case'ASSERT_WARNING': { iniKey = 'assert.warning' defaultVal = 1 let msg = 'We have not yet implemented warnings for us to throw ' msg += 'in JavaScript (assert_options())' thrownewError(msg) } case'ASSERT_BAIL': iniKey = 'assert.bail' defaultVal = 0 break case'ASSERT_QUIET_EVAL': iniKey = 'assert.quiet_eval' defaultVal = 0 break case'ASSERT_CALLBACK': iniKey = 'assert.callback' defaultVal = null break default: thrownewError('Improper type for assert_options()') }
// I presume this is to be the most recent value, instead of the default value const iniVal = ini_get(iniKey) return iniVal === '' ? defaultVal : iniVal }
return { ini, locales, localeCategories, pointers, locale_default: localeDefault, } }
// php/info/ini_get (Locutus dependency module) functionini_get(varname) { // discuss at: https://locutus.io/php/ini_get/ // original by: Brett Zamir (https://brett-zamir.me) // note 1: The ini values must be set by ini_set or manually within an ini file // example 1: ini_set('date.timezone', 'Asia/Hong_Kong') // example 1: ini_get('date.timezone') // returns 1: 'Asia/Hong_Kong'
if (entry && entry.local_value !== undefined) { if (entry.local_value === null) { return'' } returnString(entry.local_value) }
return'' }
// php/info/assert_options (target function module) functionassert_options(what, _value) { // discuss at: https://locutus.io/php/assert_options/ // original by: Brett Zamir (https://brett-zamir.me) // example 1: assert_options('ASSERT_CALLBACK') // returns 1: null
let iniKey let defaultVal switch (what) { case'ASSERT_ACTIVE': iniKey = 'assert.active' defaultVal = 1 break case'ASSERT_WARNING': { iniKey = 'assert.warning' defaultVal = 1 let msg = 'We have not yet implemented warnings for us to throw ' msg += 'in JavaScript (assert_options())' thrownewError(msg) } case'ASSERT_BAIL': iniKey = 'assert.bail' defaultVal = 0 break case'ASSERT_QUIET_EVAL': iniKey = 'assert.quiet_eval' defaultVal = 0 break case'ASSERT_CALLBACK': iniKey = 'assert.callback' defaultVal = null break default: thrownewError('Improper type for assert_options()') }
// I presume this is to be the most recent value, instead of the default value const iniVal = ini_get(iniKey) return iniVal === '' ? defaultVal : iniVal }
Improve this function
Locutus is a community effort following
The McDonald's Theory:
we ship first iterations, hoping others will improve them.
If you see something that could be better, we'd love your contribution.