├── node.js ├── History.md ├── package.json ├── LICENSE ├── README.md └── browser.js /node.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * For Node.js, simply re-export the core `util.deprecate` function. 4 | */ 5 | 6 | module.exports = require('util').deprecate; 7 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.0.2 / 2015-10-07 3 | ================== 4 | 5 | * use try/catch when checking `localStorage` (#3, @kumavis) 6 | 7 | 1.0.1 / 2014-11-25 8 | ================== 9 | 10 | * browser: use `console.warn()` for deprecation calls 11 | * browser: more jsdocs 12 | 13 | 1.0.0 / 2014-04-30 14 | ================== 15 | 16 | * initial commit 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "util-deprecate", 3 | "version": "1.0.2", 4 | "description": "The Node.js `util.deprecate()` function with browser support", 5 | "main": "node.js", 6 | "browser": "browser.js", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/TooTallNate/util-deprecate.git" 13 | }, 14 | "keywords": [ 15 | "util", 16 | "deprecate", 17 | "browserify", 18 | "browser", 19 | "node" 20 | ], 21 | "author": "Nathan Rajlich (http://n8.io/)", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/TooTallNate/util-deprecate/issues" 25 | }, 26 | "homepage": "https://github.com/TooTallNate/util-deprecate", 27 | "files": [ 28 | "browser.js", 29 | "node.js" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2014 Nathan Rajlich 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | util-deprecate 2 | ============== 3 | ### The Node.js `util.deprecate()` function with browser support 4 | 5 | In Node.js, this module simply re-exports the `util.deprecate()` function. 6 | 7 | In the web browser (i.e. via browserify), a browser-specific implementation 8 | of the `util.deprecate()` function is used. 9 | 10 | 11 | ## API 12 | 13 | A `deprecate()` function is the only thing exposed by this module. 14 | 15 | ``` javascript 16 | // setup: 17 | exports.foo = deprecate(foo, 'foo() is deprecated, use bar() instead'); 18 | 19 | 20 | // users see: 21 | foo(); 22 | // foo() is deprecated, use bar() instead 23 | foo(); 24 | foo(); 25 | ``` 26 | 27 | 28 | ## License 29 | 30 | (The MIT License) 31 | 32 | Copyright (c) 2014 Nathan Rajlich 33 | 34 | Permission is hereby granted, free of charge, to any person 35 | obtaining a copy of this software and associated documentation 36 | files (the "Software"), to deal in the Software without 37 | restriction, including without limitation the rights to use, 38 | copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | copies of the Software, and to permit persons to whom the 40 | Software is furnished to do so, subject to the following 41 | conditions: 42 | 43 | The above copyright notice and this permission notice shall be 44 | included in all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 47 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 48 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 49 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 50 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 51 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 52 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 53 | OTHER DEALINGS IN THE SOFTWARE. 54 | -------------------------------------------------------------------------------- /browser.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module exports. 4 | */ 5 | 6 | module.exports = deprecate; 7 | 8 | /** 9 | * Mark that a method should not be used. 10 | * Returns a modified function which warns once by default. 11 | * 12 | * If `localStorage.noDeprecation = true` is set, then it is a no-op. 13 | * 14 | * If `localStorage.throwDeprecation = true` is set, then deprecated functions 15 | * will throw an Error when invoked. 16 | * 17 | * If `localStorage.traceDeprecation = true` is set, then deprecated functions 18 | * will invoke `console.trace()` instead of `console.error()`. 19 | * 20 | * @param {Function} fn - the function to deprecate 21 | * @param {String} msg - the string to print to the console when `fn` is invoked 22 | * @returns {Function} a new "deprecated" version of `fn` 23 | * @api public 24 | */ 25 | 26 | function deprecate (fn, msg) { 27 | if (config('noDeprecation')) { 28 | return fn; 29 | } 30 | 31 | var warned = false; 32 | function deprecated() { 33 | if (!warned) { 34 | if (config('throwDeprecation')) { 35 | throw new Error(msg); 36 | } else if (config('traceDeprecation')) { 37 | console.trace(msg); 38 | } else { 39 | console.warn(msg); 40 | } 41 | warned = true; 42 | } 43 | return fn.apply(this, arguments); 44 | } 45 | 46 | return deprecated; 47 | } 48 | 49 | /** 50 | * Checks `localStorage` for boolean values for the given `name`. 51 | * 52 | * @param {String} name 53 | * @returns {Boolean} 54 | * @api private 55 | */ 56 | 57 | function config (name) { 58 | // accessing global.localStorage can trigger a DOMException in sandboxed iframes 59 | try { 60 | if (!global.localStorage) return false; 61 | } catch (_) { 62 | return false; 63 | } 64 | var val = global.localStorage[name]; 65 | if (null == val) return false; 66 | return String(val).toLowerCase() === 'true'; 67 | } 68 | --------------------------------------------------------------------------------