Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding support for use on the web

  • Loading branch information...
commit d9af96c65470d27bd5f866e5929d8e826f1626bf 1 parent 6e96aac
@bahamas10 authored
Showing with 41 additions and 26 deletions.
  1. +5 −0 Makefile
  2. +1 −0  autocast.min.js
  3. +35 −26 index.js
View
5 Makefile
@@ -0,0 +1,5 @@
+default: min
+min:
+ uglifyjs -cm < index.js > autocast.min.js
+clean:
+ rm -f autocast.min.js
View
1  autocast.min.js
@@ -0,0 +1 @@
+(function(){function n(n){var r;if(n instanceof Date)return n;if((r=+n)==r)return r;for(r in e)if(n===r)return e[r];return n}var e={"true":!0,"false":!1,undefined:void 0,"null":null,NaN:0/0};"undefined"==typeof exports?window.autocast=n:module.exports=n})();
View
61 index.js
@@ -1,31 +1,40 @@
-/**
- * Common strings to cast
- */
-var common_strings = {
- 'true': true,
- 'false': false,
- 'undefined': undefined,
- 'null': null,
- 'NaN': NaN
-};
+(function() {
+ /**
+ * Common strings to cast
+ */
+ var common_strings = {
+ 'true': true,
+ 'false': false,
+ 'undefined': undefined,
+ 'null': null,
+ 'NaN': NaN
+ };
-/**
- * Given a value, try and cast it
- */
-module.exports = function(s) {
- var key;
+ /**
+ * Given a value, try and cast it
+ */
+ function autocast(s) {
+ var key;
- // Don't cast Date objects
- if (s instanceof Date) return s;
+ // Don't cast Date objects
+ if (s instanceof Date) return s;
- // Try to cast it to a number
- if ((key = +s) == key) return key;
+ // Try to cast it to a number
+ if ((key = +s) == key) return key;
- // Try to make it a common string
- for (key in common_strings) {
- if (s === key) return common_strings[key];
- }
+ // Try to make it a common string
+ for (key in common_strings) {
+ if (s === key) return common_strings[key];
+ }
+
+ // Give up
+ return s;
+ };
- // Give up
- return s;
-};
+ // export
+ if (typeof exports === 'undefined') {
+ window.autocast = autocast;
+ } else {
+ module.exports = autocast;
+ }
+}());
Please sign in to comment.
Something went wrong with that request. Please try again.