Compare commits
	
		
			No commits in common. "master" and "v1.0.1" have entirely different histories.
		
	
	
		
	
		
							
								
								
									
										41
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								LICENSE
									
									
									
									
									
								
							| @ -1,41 +0,0 @@ | |||||||
| Copyright 2018 AJ ONeal |  | ||||||
| 
 |  | ||||||
| This is open source software; you can redistribute it and/or modify it under the |  | ||||||
| terms of either: |  | ||||||
| 
 |  | ||||||
|    a) the "MIT License" |  | ||||||
|    b) the "Apache-2.0 License" |  | ||||||
| 
 |  | ||||||
| MIT License |  | ||||||
| 
 |  | ||||||
|    Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
|    of this software and associated documentation files (the "Software"), to deal |  | ||||||
|    in the Software without restriction, including without limitation the rights |  | ||||||
|    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
|    copies of the Software, and to permit persons to whom the Software is |  | ||||||
|    furnished to do so, subject to the following conditions: |  | ||||||
| 
 |  | ||||||
|    The above copyright notice and this permission notice shall be included in all |  | ||||||
|    copies or substantial portions of the Software. |  | ||||||
| 
 |  | ||||||
|    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
|    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
|    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
|    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
|    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
|    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |  | ||||||
|    SOFTWARE. |  | ||||||
| 
 |  | ||||||
| Apache-2.0 License Summary |  | ||||||
| 
 |  | ||||||
|    Licensed under the Apache License, Version 2.0 (the "License"); |  | ||||||
|    you may not use this file except in compliance with the License. |  | ||||||
|    You may obtain a copy of the License at |  | ||||||
| 
 |  | ||||||
|      http://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
| 
 |  | ||||||
|    Unless required by applicable law or agreed to in writing, software |  | ||||||
|    distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|    See the License for the specific language governing permissions and |  | ||||||
|    limitations under the License. |  | ||||||
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
								
							| @ -9,19 +9,11 @@ This works in both the Browser and SSJS. | |||||||
| 
 | 
 | ||||||
|     require('remedial'); |     require('remedial'); | ||||||
| 
 | 
 | ||||||
| Notes |  | ||||||
| ---- |  | ||||||
| 
 | 
 | ||||||
| `typeOf` is taken from `jQuery.type`, which is more accurate than Crockford's original and even simpler | Usage / API | ||||||
| than the ["Flanagan / Miller device"](http://groups.google.com/group/nodejs/msg/0670a986a2906aeb). |  | ||||||
| 
 |  | ||||||
| There is [a more specific typeof()](http://rolandog.com/archives/2007/01/18/typeof-a-more-specific-typeof/) implementation also worthy of consideration. |  | ||||||
| 
 |  | ||||||
| Globals |  | ||||||
| ==== | ==== | ||||||
| 
 | 
 | ||||||
| typeOf(o) | typeOf(o) | ||||||
| ---- |  | ||||||
| 
 | 
 | ||||||
| Since JavaScript is a loosely-typed language, it is sometimes necessary to examine a value to determine its type. (This is sometimes necessary in strongly typed languages as well.) JavaScript provides a typeof  operator to facilitate this, but typeof has problems. | Since JavaScript is a loosely-typed language, it is sometimes necessary to examine a value to determine its type. (This is sometimes necessary in strongly typed languages as well.) JavaScript provides a typeof  operator to facilitate this, but typeof has problems. | ||||||
| 
 | 
 | ||||||
| @ -44,8 +36,8 @@ isEmpty(v) | |||||||
| 
 | 
 | ||||||
| isEmpty(v) returns true if v is an object containing no enumerable members. | isEmpty(v) returns true if v is an object containing no enumerable members. | ||||||
| 
 | 
 | ||||||
| String Methods | **String Methods** | ||||||
| ==== | ---- | ||||||
| 
 | 
 | ||||||
| JavaScript provides some useful methods for strings, but leaves out some important ones. Fortunately, JavaScript allows us to add new methods to the basic types. | JavaScript provides some useful methods for strings, but leaves out some important ones. Fortunately, JavaScript allows us to add new methods to the basic types. | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,23 +1,20 @@ | |||||||
| /*jslint onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true */ | /*jslint onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true */ | ||||||
|  | "use strict"; | ||||||
| (function () { | (function () { | ||||||
|     "use strict"; |     function typeOf(value) { | ||||||
| 
 |         var s = typeof value; | ||||||
|     var global = Function('return this')() |         if (s === 'object') { | ||||||
|       , classes = "Boolean Number String Function Array Date RegExp Object".split(" ") |             if (value) { | ||||||
|       , i |                 if (typeof value.length === 'number' && | ||||||
|       , name |                         !(value.propertyIsEnumerable('length')) && | ||||||
|       , class2type = {} |                         typeof value.splice === 'function') { | ||||||
|       ; |                     s = 'array'; | ||||||
| 
 |                 } | ||||||
|     for (i in classes) { |             } else { | ||||||
|       if (classes.hasOwnProperty(i)) { |                 s = 'null'; | ||||||
|         name = classes[i]; |             } | ||||||
|         class2type["[object " + name + "]"] = name.toLowerCase(); |         } | ||||||
|       } |         return s; | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     function typeOf(obj) { |  | ||||||
|       return (null === obj || undefined === obj) ? String(obj) : class2type[Object.prototype.toString.call(obj)] || "object"; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function isEmpty(o) { |     function isEmpty(o) { | ||||||
| @ -95,11 +92,15 @@ | |||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // CommonJS / npm / Ender.JS
 |     // Boiler Plate
 | ||||||
|  |     if ('undefined' === typeof module) { module = {}; } | ||||||
|     module.exports = { |     module.exports = { | ||||||
|         typeOf: typeOf, |         typeOf: typeOf, | ||||||
|         isEmpty: isEmpty |         isEmpty: isEmpty | ||||||
|     }; |     }; | ||||||
|  |     if ('undefined' === typeof global) { global = window; } | ||||||
|     global.typeOf = global.typeOf || typeOf; |     global.typeOf = global.typeOf || typeOf; | ||||||
|     global.isEmpty = global.isEmpty || isEmpty; |     global.isEmpty = global.isEmpty || isEmpty; | ||||||
|  |     if ('undefined' === typeof provide) { provide = function () {}; } | ||||||
|  |     provide('remedial'); | ||||||
| }()); | }()); | ||||||
							
								
								
									
										31
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								package.json
									
									
									
									
									
								
							| @ -1,14 +1,21 @@ | |||||||
| { | { | ||||||
|   "name"          : "remedial", |   "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)", | ||||||
|   "description"   : "Deprecated. Utilities for ES3, most of which have been adopted or superseded in ES5.1. Adapted from Douglas Crockford's Remedial JavaScript", |   "contributors": [ "Douglas Crockford <douglas@crockford.com>" ], | ||||||
|   "url"           : "http://javascript.crockford.com/remedial.html", |   "dependencies": {}, | ||||||
|   "keywords"      : ["util", "isEmpty", "typeOf", "entityify", "quote", "supplant", "trim"], |   "description": "Deprecated. Utilities for ES3, most of which have been adopted or superseded in ES5.1. Adapted from Douglas Crockford's Remedial JavaScript", | ||||||
|   "author"        : "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)", |   "engines": { "node": "*" }, | ||||||
|   "contributors"  : [ "Douglas Crockford <douglas@crockford.com>" ], |   "keywords": [ | ||||||
|   "dependencies"  : {}, |     "util", | ||||||
|   "engines"       : { "node": "*" }, |     "isEmpty", | ||||||
|   "homepage"      : "https://git.coolaj86.com/coolaj86/remedial.js", |     "typeOf", | ||||||
|   "license"       : "(MIT OR Apache-2.0)", |     "entityify", | ||||||
|   "main"          : "./index", |     "quote", | ||||||
|   "version"       : "1.0.8" |     "supplant", | ||||||
|  |     "trim" | ||||||
|  |   ], | ||||||
|  |   "lib": "lib", | ||||||
|  |   "main": "./lib/remedial", | ||||||
|  |   "name": "remedial", | ||||||
|  |   "homepage": "https://git.coolaj86.com/coolaj86/remedial.js", | ||||||
|  |   "version": "1.0.1" | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,87 +0,0 @@ | |||||||
| // Firefox was tested using persevere's global-es5 for es5 emulation
 |  | ||||||
| (function () { |  | ||||||
|   require('../lib/remedial'); |  | ||||||
| 
 |  | ||||||
|   a = []; |  | ||||||
|   a[2] = 27; |  | ||||||
|   console.log(a); |  | ||||||
|   // Expected: [undefined, undefined, 27];
 |  | ||||||
|   // Node/V8: [ 27 ];
 |  | ||||||
|   // FF3: [undefined, undefined, 27];
 |  | ||||||
|   console.log(a.length); |  | ||||||
|   // 3
 |  | ||||||
|   console.log(typeOf(a)); |  | ||||||
|   // array
 |  | ||||||
|    |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   b = Object.create([]); |  | ||||||
|   b[2] = 27; |  | ||||||
|   console.log(b); |  | ||||||
|   // Expected: [undefined, undefined, 27];
 |  | ||||||
|   // Node/V8: [ 27 ]
 |  | ||||||
|   console.log(b.length); |  | ||||||
|   // Expected: 3
 |  | ||||||
|   // Node/V8/FF: 0
 |  | ||||||
|   console.log(typeOf(b)); |  | ||||||
|   // Expected: Object (with Flanagan / Miller device or jQuery's type)
 |  | ||||||
|   // Node/V8/FF: array (with Crockford's original)
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   c = Object.create([]); |  | ||||||
|   c.push(); |  | ||||||
|   c.push(); |  | ||||||
|   c.push(27); |  | ||||||
|   console.log(c); |  | ||||||
|   // Expected: [undefined, undefined, 27]
 |  | ||||||
|   // Node: [ 27, length: 1 ]
 |  | ||||||
|   // FF: []
 |  | ||||||
|   console.log(c.length); |  | ||||||
|   // Expected: 3
 |  | ||||||
|   // Node/V8/FF: 1
 |  | ||||||
|   console.log(typeOf(c)); |  | ||||||
|   // Expected: object
 |  | ||||||
|   // Node/V8/FF: object
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   d = Object.create(Array); |  | ||||||
|   // FF: Error: typeof prototype[function] != 'object'
 |  | ||||||
|   d[2] = 27; |  | ||||||
|   console.log(d); |  | ||||||
|   // Expected: [undefined, undefined, 27];
 |  | ||||||
|   // Node/V8: { '2': 27 }
 |  | ||||||
|   console.log(d.length); |  | ||||||
|   // Expected: 3
 |  | ||||||
|   // Node/V8/FF: 1
 |  | ||||||
|   console.log(typeOf(d)); |  | ||||||
|   // Expected: object
 |  | ||||||
|   // Node/V8: object
 |  | ||||||
| }()); |  | ||||||
| 
 |  | ||||||
| /* |  | ||||||
|   Exact Node Output: |  | ||||||
|   [ 27 ] |  | ||||||
|   3 |  | ||||||
|   array |  | ||||||
|   [ 27 ] |  | ||||||
|   0 |  | ||||||
|   array |  | ||||||
|   [ 27, length: 1 ] |  | ||||||
|   1 |  | ||||||
|   object |  | ||||||
| 
 |  | ||||||
|   Exact FF (firebug) Output (expanded): |  | ||||||
|   [undefined, undefined, 27] |  | ||||||
|     >   2         27 |  | ||||||
|   3 |  | ||||||
|   array |  | ||||||
|   [] |  | ||||||
|     >   2         27 |  | ||||||
|   0 |  | ||||||
|   array |  | ||||||
|   [27] |  | ||||||
|     >   0         27 |  | ||||||
|         length    1 |  | ||||||
|   1 |  | ||||||
|   object |  | ||||||
| */ |  | ||||||
| @ -1,31 +0,0 @@ | |||||||
| (function () { |  | ||||||
|   require('../lib/remedial'); |  | ||||||
|   var n = null, |  | ||||||
|     u; |  | ||||||
| 
 |  | ||||||
|   if ( |  | ||||||
|     'object' === typeOf(Object.create([])) && |  | ||||||
|     'object' === typeOf(Object.create(function () {})) && |  | ||||||
|     'array' === typeOf([]) && |  | ||||||
|     'string' === typeOf('') && |  | ||||||
|     'regexp' === typeOf(/ /) && |  | ||||||
|     'number' === typeOf(0) && |  | ||||||
|     'function' === typeOf(function () {}) && |  | ||||||
|     'function' === typeOf((function () { |  | ||||||
|       var a = function () {};  |  | ||||||
|       a.foo = 'bar'; |  | ||||||
|       return a; |  | ||||||
|     }())) && |  | ||||||
|     'boolean' === typeOf(true) && |  | ||||||
|     'boolean' === typeOf(false) && |  | ||||||
|     'date' === typeOf(new Date()) && |  | ||||||
|     'undefined' === typeOf(u) && |  | ||||||
|     'undefined' === typeOf(undefined) && |  | ||||||
|     'null' === typeOf(n) && |  | ||||||
|     'object' === typeOf({}) |  | ||||||
|       ) { |  | ||||||
|     console.log('passed type detections') |  | ||||||
|   } else { |  | ||||||
|     console.log('failed type detections') |  | ||||||
|   } |  | ||||||
| }()); |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user