UNPKG

locutus

Version:

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

35 lines (34 loc) 875 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._phpCastString = _phpCastString; function _phpCastString(value) { // original by: Rafał Kukawski if (typeof value === 'boolean') { return value ? '1' : ''; } if (typeof value === 'string') { return value; } if (typeof value === 'number') { if (isNaN(value)) { return 'NAN'; } if (!isFinite(value)) { return (value < 0 ? '-' : '') + 'INF'; } return value + ''; } if (typeof value === 'undefined') { return ''; } if (typeof value === 'object') { if (Array.isArray(value)) { return 'Array'; } if (value !== null) { return 'Object'; } return ''; } throw new Error('Unsupported value type'); }