pax_global_header00006660000000000000000000000064120123765340014515gustar00rootroot0000000000000052 comment=24d8872e21b44a9211e1809f0b42fea2364d2f48 once-1.1.1/000077500000000000000000000000001201237653400124415ustar00rootroot00000000000000once-1.1.1/LICENSE000066400000000000000000000024361201237653400134530ustar00rootroot00000000000000Copyright (c) Isaac Z. Schlueter ("Author") All rights reserved. The BSD License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. once-1.1.1/README.md000066400000000000000000000010451201237653400137200ustar00rootroot00000000000000# once Only call a function once. ## usage ```javascript var once = require('once') function load (file, cb) { cb = once(cb) loader.load('file') loader.once('load', cb) loader.once('error', cb) } ``` Or add to the Function.prototype in a responsible way: ```javascript // only has to be done once require('once').proto() function load (file, cb) { cb = cb.once() loader.load('file') loader.once('load', cb) loader.once('error', cb) } ``` Ironically, the prototype feature makes this module twice as complicated as necessary. once-1.1.1/once.js000066400000000000000000000005321201237653400137230ustar00rootroot00000000000000module.exports = once once.proto = once(function () { Object.defineProperty(Function.prototype, 'once', { value: function () { return once(this) }, configurable: true }) }) function once (fn) { var called = false return function () { if (called) return called = true return fn.apply(this, arguments) } } once-1.1.1/package.json000066400000000000000000000010111201237653400147200ustar00rootroot00000000000000{ "name": "once", "version": "1.1.1", "description": "Run a function exactly one time", "main": "once.js", "directories": { "test": "test" }, "dependencies": {}, "devDependencies": { "tap": "~0.3.0" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "git://github.com/isaacs/once" }, "keywords": [ "once", "function", "one", "single" ], "author": "Isaac Z. Schlueter (http://blog.izs.me/)", "license": "BSD" } once-1.1.1/test/000077500000000000000000000000001201237653400134205ustar00rootroot00000000000000once-1.1.1/test/once.js000066400000000000000000000005461201237653400147070ustar00rootroot00000000000000var test = require('tap').test var once = require('../once.js') test('once', function (t) { var f = 0 var foo = once(function (g) { t.equal(f, 0) f ++ return f + g + this }) for (var i = 0; i < 1E3; i++) { t.same(f, i === 0 ? 0 : 1) var g = foo.call(1, 1) t.same(g, i === 0 ? 3 : undefined) t.same(f, 1) } t.end() })