Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing build problems after last strnatcmp commit
- Loading branch information
Showing
6 changed files
with
90 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module.exports = function _phpCastString (value) { | ||
// original by: Rafał Kukawski | ||
// example 1: _phpCastString(true) | ||
// returns 1: '1' | ||
// example 2: _phpCastString(false) | ||
// returns 2: '' | ||
// example 3: _phpCastString('foo') | ||
// returns 3: 'foo' | ||
// example 4: _phpCastString(0/0) | ||
// returns 4: 'NAN' | ||
// example 5: _phpCastString(1/0) | ||
// returns 5: 'INF' | ||
// example 6: _phpCastString(-1/0) | ||
// returns 6: '-INF' | ||
// example 7: _phpCastString(null) | ||
// returns 7: '' | ||
// example 8: _phpCastString(undefined) | ||
// returns 8: '' | ||
// example 9: _phpCastString([]) | ||
// returns 9: 'Array' | ||
// example 10: _phpCastString({}) | ||
// returns 10: 'Object' | ||
// example 11: _phpCastString(0) | ||
// returns 11: '0' | ||
// example 12: _phpCastString(1) | ||
// returns 12: '1' | ||
// example 13: _phpCastString(3.14) | ||
// returns 13: '3.14' | ||
|
||
var type = typeof value | ||
|
||
switch (type) { | ||
case 'boolean': | ||
return value ? '1' : '' | ||
case 'string': | ||
return value | ||
case 'number': | ||
if (isNaN(value)) { | ||
return 'NAN' | ||
} | ||
|
||
if (!isFinite(value)) { | ||
return (value < 0 ? '-' : '') + 'INF' | ||
} | ||
|
||
return value + '' | ||
case 'undefined': | ||
return '' | ||
case 'object': | ||
if (Array.isArray(value)) { | ||
return 'Array' | ||
} | ||
|
||
if (value !== null) { | ||
return 'Object' | ||
} | ||
|
||
return '' | ||
case 'function': | ||
// fall through | ||
default: | ||
throw new Error('Unsupported value type') | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
module.exports['_bc'] = require('./_bc') | ||
module.exports['_php_cast_string'] = require('./_php_cast_string') | ||
module.exports['_phpCastString'] = require('./_phpCastString') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters