phpjs
Version:
52 lines (42 loc) • 1.68 kB
Markdown
layout: page
title: "JavaScript is_binary function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/is_binary:591
- /functions/view/is_binary
- /functions/view/591
- /functions/is_binary:591
- /functions/591
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's is_binary
{% codeblock var/is_binary.js lang:js https://raw.github.com/kvz/phpjs/master/functions/var/is_binary.js raw on github %}
function is_binary (vr) {
// + original by: Brett Zamir (http://brett-zamir.me)
// * example 1: is_binary('This could be binary as far as JavaScript knows...');
// * returns 1: true
return typeof vr === 'string'; // If it is a string of any kind, it could be binary
}
{% endcodeblock %}
- [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/var/is_binary.js)
Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are
the closest match to this hashtable-like data structure.
Please also note that php.js offers community built functions and goes by the
[McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online
functions that are far from perfect, in the hopes to spark better contributions.
Do you have one? Then please just:
- [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/var/is_binary.js)
### Example 1
This code
{% codeblock lang:js example %}
is_binary('This could be binary as far as JavaScript knows...');
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}
### Other PHP functions in the var extension
{% render_partial _includes/custom/var.html %}