├── ness ├── arrow.js ├── class.js ├── true.js ├── false.js ├── freeze.js ├── args.js ├── function.js ├── symbol.js ├── identity.js ├── arguments.js ├── array.js ├── object.js ├── context.js └── index.js ├── .gitignore ├── LICENSE ├── package.json ├── README.md └── test.js /ness/arrow.js: -------------------------------------------------------------------------------- 1 | export default () => {}; 2 | -------------------------------------------------------------------------------- /ness/class.js: -------------------------------------------------------------------------------- 1 | export default class {}; 2 | -------------------------------------------------------------------------------- /ness/true.js: -------------------------------------------------------------------------------- 1 | export default () => true; 2 | -------------------------------------------------------------------------------- /ness/false.js: -------------------------------------------------------------------------------- 1 | export default () => false; 2 | -------------------------------------------------------------------------------- /ness/freeze.js: -------------------------------------------------------------------------------- 1 | export default Object.freeze; 2 | -------------------------------------------------------------------------------- /ness/args.js: -------------------------------------------------------------------------------- 1 | export default (...args) => args; 2 | -------------------------------------------------------------------------------- /ness/function.js: -------------------------------------------------------------------------------- 1 | export default function() {}; 2 | -------------------------------------------------------------------------------- /ness/symbol.js: -------------------------------------------------------------------------------- 1 | export default Symbol('empty'); 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .nyc_output 3 | coverage/ 4 | node_modules/ 5 | -------------------------------------------------------------------------------- /ness/identity.js: -------------------------------------------------------------------------------- 1 | export default any /* are you OK, are you OK */ => any; 2 | -------------------------------------------------------------------------------- /ness/arguments.js: -------------------------------------------------------------------------------- 1 | export default function () { 2 | return arguments; 3 | }; 4 | -------------------------------------------------------------------------------- /ness/array.js: -------------------------------------------------------------------------------- 1 | import freeze from './freeze.js'; 2 | 3 | export default freeze([]); 4 | -------------------------------------------------------------------------------- /ness/object.js: -------------------------------------------------------------------------------- 1 | import freeze from './freeze.js'; 2 | 3 | export default freeze({}); 4 | -------------------------------------------------------------------------------- /ness/context.js: -------------------------------------------------------------------------------- 1 | export default function () { 2 | 'use strict'; 3 | return this; 4 | }; 5 | -------------------------------------------------------------------------------- /ness/index.js: -------------------------------------------------------------------------------- 1 | import args from './args.js'; 2 | import Arguments from './arguments.js'; 3 | import array from './array.js'; 4 | import arrow from './arrow.js'; 5 | import Class from './class.js'; 6 | import context from './context.js'; 7 | import False from './false.js'; 8 | import Function from './function.js'; 9 | import identity from './identity.js'; 10 | import object from './object.js'; 11 | import symbol from './symbol.js'; 12 | import True from './true.js'; 13 | 14 | export { 15 | args, 16 | Arguments as arguments, 17 | array, 18 | arrow, 19 | Class as class, 20 | context, 21 | False as false, 22 | Function as function, 23 | identity, 24 | object, 25 | symbol, 26 | True as true, 27 | }; 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright © 2024-today, Andrea Giammarchi, @WebReflection 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the “Software”), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@webreflection/empty", 3 | "version": "1.0.0", 4 | "main": "./ness/index.js", 5 | "module": "./ness/index.js", 6 | "type": "module", 7 | "scripts": { 8 | "test": "c8 node test.js" 9 | }, 10 | "files": [ 11 | "./ness/*.js", 12 | "README.md", 13 | "LICENSE" 14 | ], 15 | "exports": { 16 | ".": "./index.js", 17 | "./args": "./ness/args.js", 18 | "./arguments": "./ness/arguments.js", 19 | "./array": "./ness/array.js", 20 | "./arrow": "./ness/arrow.js", 21 | "./class": "./ness/class.js", 22 | "./context": "./ness/context.js", 23 | "./function": "./ness/function.js", 24 | "./identity": "./ness/identity.js", 25 | "./object": "./ness/object.js", 26 | "./symbol": "./ness/symbol.js" 27 | }, 28 | "keywords": [ 29 | "empty", 30 | "array", 31 | "function", 32 | "utilities" 33 | ], 34 | "author": "Andrea Giammarchi", 35 | "license": "MIT", 36 | "description": "Just various empty and frozen references", 37 | "devDependencies": { 38 | "c8": "^10.1.2" 39 | }, 40 | "repository": { 41 | "type": "git", 42 | "url": "git+https://github.com/WebReflection/empty.git" 43 | }, 44 | "bugs": { 45 | "url": "https://github.com/WebReflection/empty/issues" 46 | }, 47 | "homepage": "https://github.com/WebReflection/empty#readme" 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @webreflection/empty 2 | 3 | **Social Media Photo by [Adlan](https://unsplash.com/@adlan7000) on [Unsplash](https://unsplash.com/)** 4 | 5 | This is basically the same as [empty](https://www.npmjs.com/package/empty) except it's a dual module and it doesn't care about freezing callbacks (for better or worse) but it does freeze other references, such as *array* or *object*, and even in production, where *IMHO* it matters most. 6 | 7 | ```js 8 | import { 9 | args, // (...args) => args 10 | arguments as Arguments, // function arguments 11 | array, // Object.freeze([]) 12 | context, // function context 13 | false as False, // () => false 14 | function as noop, // () => {} 15 | identity, // any => any 16 | object, // Object.freeze({}) 17 | string as str, // '' 18 | true as True // () => true 19 | } from '@webreflection/empty'; 20 | ``` 21 | 22 | ### isolated exports 23 | 24 | Each utility can be imported directly without bloating the outcome: 25 | 26 | ```js 27 | import args from '@webreflection/empty/args'; 28 | import arguments as Arguments from '@webreflection/empty/arguments'; 29 | import array from '@webreflection/empty/array'; 30 | import context from '@webreflection/empty/context'; 31 | import false as False from '@webreflection/empty/false'; 32 | import function as noop from '@webreflection/empty/function'; 33 | import identity from '@webreflection/empty/identity'; 34 | import object from '@webreflection/empty/object'; 35 | import string as str from '@webreflection/empty/string'; 36 | import true as True from '@webreflection/empty/true'; 37 | ``` 38 | 39 | ### ... but why? 40 | 41 | I use one of these utilities all over the place in my projects so I've decided that this approch would work better. 42 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | // all at once 2 | import * as empty from './ness/index.js'; 3 | 4 | // or each one a part 5 | import emptyArgs from './ness/args.js'; 6 | import emptyArguments from './ness/arguments.js'; 7 | import emptyArray from './ness/array.js'; 8 | import emptyArrow from './ness/arrow.js'; 9 | import emptyClass from './ness/class.js'; 10 | import emptyContext from './ness/context.js'; 11 | import emptyFalse from './ness/false.js'; 12 | import emptyFunction from './ness/function.js'; 13 | import emptyIdentity from './ness/identity.js'; 14 | import emptyObject from './ness/object.js'; 15 | import emptySymbol from './ness/symbol.js'; 16 | import emptyTrue from './ness/true.js'; 17 | 18 | console.assert(empty.args === emptyArgs); 19 | console.assert(emptyArgs(1, 2).join('-') === '1-2'); 20 | console.assert(empty.arguments === emptyArguments); 21 | console.assert(JSON.stringify(emptyArguments(1)) === '{"0":1}'); 22 | console.assert(empty.array === emptyArray); 23 | console.assert(Array.isArray(emptyArray)); 24 | console.assert(JSON.stringify(emptyArray) === '[]'); 25 | console.assert(empty.arrow === emptyArrow); 26 | console.assert(typeof emptyArrow === 'function'); 27 | console.assert(!emptyArrow()); 28 | console.assert(empty.class === emptyClass); 29 | console.assert(new emptyClass instanceof emptyClass); 30 | console.assert(empty.context === emptyContext); 31 | console.assert(emptyContext.call(1) === 1); 32 | console.assert(empty.false === emptyFalse); 33 | console.assert(emptyFalse() === false); 34 | console.assert(empty.function === emptyFunction); 35 | console.assert(emptyFunction() === void 0); 36 | console.assert(empty.identity === emptyIdentity); 37 | console.assert(emptyIdentity(123) === 123); 38 | console.assert(empty.object === emptyObject); 39 | console.assert(JSON.stringify(emptyObject) === '{}'); 40 | console.assert(empty.symbol === emptySymbol); 41 | console.assert(String(emptySymbol) === 'Symbol(empty)'); 42 | console.assert(empty.true === emptyTrue); 43 | console.assert(emptyTrue() === true); 44 | --------------------------------------------------------------------------------