├── .gitignore ├── .npmignore ├── .travis.yml ├── index.d.ts ├── index.js ├── test ├── method.js └── field.js ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | node_modules 4 | build 5 | *.node 6 | components -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | node_modules 4 | build 5 | *.node 6 | components -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.9" 4 | - "0.10" 5 | after_script: 6 | - npm run coveralls -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'deprecated' { 2 | export function method (msg: string, log: (...t: any[]) => void ,t: T): T 3 | export function field (msg: string, log: (...t: any[]) => void , t: T, prop: string, value: V): T 4 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var deprecated = { 2 | method: function(msg, log, fn) { 3 | var called = false; 4 | return function(){ 5 | if (!called) { 6 | called = true; 7 | log(msg); 8 | } 9 | return fn.apply(this, arguments); 10 | }; 11 | }, 12 | 13 | field: function(msg, log, parent, field, val) { 14 | var called = false; 15 | var getter = function(){ 16 | if (!called) { 17 | called = true; 18 | log(msg); 19 | } 20 | return val; 21 | }; 22 | var setter = function(v) { 23 | if (!called) { 24 | called = true; 25 | log(msg); 26 | } 27 | val = v; 28 | return v; 29 | }; 30 | Object.defineProperty(parent, field, { 31 | get: getter, 32 | set: setter, 33 | enumerable: true 34 | }); 35 | return; 36 | } 37 | }; 38 | 39 | module.exports = deprecated; -------------------------------------------------------------------------------- /test/method.js: -------------------------------------------------------------------------------- 1 | var deprecated = require('../'); 2 | var should = require('should'); 3 | require('mocha'); 4 | 5 | describe('method()', function() { 6 | it('should return a wrapped function that logs once', function(done) { 7 | var message = 'testing'; 8 | var scope = { 9 | a: 1 10 | }; 11 | var logged = false; 12 | var log = function(msg){ 13 | msg.should.equal(message); 14 | logged.should.equal(false); 15 | logged = true; 16 | }; 17 | var fn = deprecated.method(message, log, function(one, two){ 18 | this.should.equal(scope); 19 | one.should.equal(1); 20 | two.should.equal(2); 21 | return one+two; 22 | }); 23 | 24 | fn.bind(scope)(1,2).should.equal(3); 25 | fn.bind(scope)(1,2).should.equal(3); 26 | fn.bind(scope)(1,2).should.equal(3); 27 | fn.bind(scope)(1,2).should.equal(3); 28 | 29 | logged.should.equal(true); 30 | done(); 31 | }); 32 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deprecated", 3 | "description": "Tool for deprecating things", 4 | "version": "0.0.2", 5 | "homepage": "http://github.com/wearefractal/deprecated", 6 | "repository": "git://github.com/wearefractal/deprecated.git", 7 | "author": "Fractal (http://wearefractal.com/)", 8 | "main": "./index.js", 9 | "typings": "./index.d.ts", 10 | "dependencies": {}, 11 | "devDependencies": { 12 | "mocha": "~1.17.0", 13 | "should": "~3.1.0", 14 | "mocha-lcov-reporter": "~0.0.1", 15 | "coveralls": "~2.6.1", 16 | "istanbul": "~0.2.3", 17 | "rimraf": "~2.2.5", 18 | "jshint": "~2.4.1" 19 | }, 20 | "scripts": { 21 | "test": "mocha --reporter spec && jshint", 22 | "coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" 23 | }, 24 | "engines": { 25 | "node": ">= 0.9" 26 | }, 27 | "licenses": [ 28 | { 29 | "type": "MIT", 30 | "url": "http://github.com/wearefractal/deprecated/raw/master/LICENSE" 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Fractal 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /test/field.js: -------------------------------------------------------------------------------- 1 | var deprecated = require('../'); 2 | var should = require('should'); 3 | require('mocha'); 4 | 5 | describe('field()', function() { 6 | it('should return a wrapped function that logs once on get', function(done) { 7 | var message = 'testing'; 8 | var scope = { 9 | a: 1 10 | }; 11 | var obj = {}; 12 | var logged = false; 13 | var log = function(msg){ 14 | msg.should.equal(message); 15 | logged.should.equal(false); 16 | logged = true; 17 | }; 18 | deprecated.field(message, log, obj, 'a', 123); 19 | 20 | obj.a.should.equal(123); 21 | obj.a = 1234; 22 | obj.a.should.equal(1234); 23 | logged.should.equal(true); 24 | done(); 25 | }); 26 | it('should return a wrapped function that logs once on set', function(done) { 27 | var message = 'testing'; 28 | var scope = { 29 | a: 1 30 | }; 31 | var obj = {}; 32 | var logged = false; 33 | var log = function(msg){ 34 | msg.should.equal(message); 35 | logged.should.equal(false); 36 | logged = true; 37 | }; 38 | deprecated.field(message, log, obj, 'a', 123); 39 | 40 | obj.a = 1234; 41 | logged.should.equal(true); 42 | done(); 43 | }); 44 | }); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deprecated [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status][david-image]][david-url] 2 | 3 | 4 | ## Information 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
Packagedeprecated
DescriptionTool for deprecating things
Node Version>= 0.9
19 | 20 | ## Usage 21 | 22 | ```javascript 23 | var oldfn = function(a,b) { 24 | return a+b; 25 | }; 26 | 27 | // returns a new wrapper function that logs the deprecated function once 28 | var somefn = deprecated.method('dont use this anymore', console.log, oldfn); 29 | 30 | var someobj = {}; 31 | 32 | // set up a getter/set for field that logs deprecated message once 33 | deprecated.field('dont use this anymore', console.log, someobj, 'a', 123); 34 | 35 | console.log(someobj.a); // 123 36 | ``` 37 | 38 | [npm-url]: https://npmjs.org/package/deprecated 39 | [npm-image]: https://badge.fury.io/js/deprecated.png 40 | 41 | [travis-url]: https://travis-ci.org/wearefractal/deprecated 42 | [travis-image]: https://travis-ci.org/wearefractal/deprecated.png?branch=master 43 | 44 | [coveralls-url]: https://coveralls.io/r/wearefractal/deprecated 45 | [coveralls-image]: https://coveralls.io/repos/wearefractal/deprecated/badge.png 46 | 47 | [depstat-url]: https://david-dm.org/wearefractal/deprecated 48 | [depstat-image]: https://david-dm.org/wearefractal/deprecated.png 49 | 50 | [david-url]: https://david-dm.org/wearefractal/deprecated 51 | [david-image]: https://david-dm.org/wearefractal/deprecated.png?theme=shields.io --------------------------------------------------------------------------------