diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..72e0eba --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 2 +trim_trailing_whitespace = true diff --git a/.eslintrc b/.eslintrc index e862764..93978e7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,7 @@ "rules": { "max-lines-per-function": 0, + "multiline-comment-style": 1, "new-cap": [2, { "capIsNewExceptions": ["GetIntrinsic"] }], }, } diff --git a/index.js b/index.js index f1c4826..0e77d99 100644 --- a/index.js +++ b/index.js @@ -1,28 +1,30 @@ 'use strict'; -var GetIntrinsic = require('get-intrinsic'); -var callBound = require('call-bind/callBound'); var inspect = require('object-inspect'); +var bind = require('function-bind'); -var $TypeError = GetIntrinsic('%TypeError%'); -var $WeakMap = GetIntrinsic('%WeakMap%', true); -var $Map = GetIntrinsic('%Map%', true); +var $call = Function.prototype.call; -var $weakMapGet = callBound('WeakMap.prototype.get', true); -var $weakMapSet = callBound('WeakMap.prototype.set', true); -var $weakMapHas = callBound('WeakMap.prototype.has', true); -var $mapGet = callBound('Map.prototype.get', true); -var $mapSet = callBound('Map.prototype.set', true); -var $mapHas = callBound('Map.prototype.has', true); +var callBound = function (original) { + return $call.call(bind, $call, original); +}; + +var $TypeError = TypeError; +var $WeakMap = typeof WeakMap === 'function' ? WeakMap : undefined; +var $Map = typeof Map === 'function' ? Map : undefined; + +var $weakMapGet = $WeakMap ? callBound($WeakMap.prototype.get) : undefined; +var $weakMapSet = $WeakMap ? callBound($WeakMap.prototype.set) : undefined; +var $weakMapHas = $WeakMap ? callBound($WeakMap.prototype.has) : undefined; +var $mapGet = $Map ? callBound($Map.prototype.get) : undefined; +var $mapSet = $Map ? callBound($Map.prototype.set) : undefined; +var $mapHas = $Map ? callBound($Map.prototype.has) : undefined; /* - * This function traverses the list returning the node corresponding to the - * given key. - * - * That node is also moved to the head of the list, so that if it's accessed - * again we don't need to traverse the whole list. By doing so, all the recently - * used nodes can be accessed relatively quickly. - */ +* This function traverses the list returning the node corresponding to the given key. +* +* That node is also moved to the head of the list, so that if it's accessed again we don't need to traverse the whole list. By doing so, all the recently used nodes can be accessed relatively quickly. +*/ var listGetNode = function (list, key) { // eslint-disable-line consistent-return for (var prev = list, curr; (curr = prev.next) !== null; prev = curr) { if (curr.key === key) { @@ -109,11 +111,7 @@ module.exports = function getSideChannel() { $mapSet($m, key, value); } else { if (!$o) { - /* - * Initialize the linked list as an empty node, so that we don't have - * to special-case handling of the first node: we can always refer to - * it as (previous node).next, instead of something like (list).head - */ + // Initialize the linked list as an empty node, so that we don't have to special-case handling of the first node: we can always refer to it as (previous node).next, instead of something like (list).head $o = { key: {}, next: null }; } listSet($o, key, value); diff --git a/package.json b/package.json index ac81e74..b2b8e70 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "scripts": { "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", + "prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "tests-only": "nyc tape 'test/**/*.js'", @@ -47,14 +48,14 @@ "@ljharb/eslint-config": "^20.2.3", "aud": "^2.0.0", "auto-changelog": "^2.4.0", + "eclint": "^2.8.1", "eslint": "=8.8.0", "nyc": "^10.3.2", "safe-publish-latest": "^2.0.0", "tape": "^5.5.2" }, "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1", + "function-bind": "^1.1.1", "object-inspect": "^1.12.0" }, "auto-changelog": { diff --git a/test/index.js b/test/index.js index 3b92ef7..b663b03 100644 --- a/test/index.js +++ b/test/index.js @@ -39,6 +39,11 @@ test('has', function (t) { channel.set(o, 'foo'); t.equal(channel.has(o), true, 'existent value yields true'); + t.equal(channel.has('abc'), false, 'non object value non existent yields false'); + + channel.set('abc', 'foo'); + t.equal(channel.has('abc'), true, 'non object value that exists yields true'); + t.end(); });