Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all dependencies #247

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ overrides:
rules:
"@sinonjs/no-prototype-methods/no-prototype-methods": off
max-nested-callbacks: off

4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: mansona/npm-lockfile-version@v1
- uses: actions/setup-node@v2
with:
node-version: "16"
node-version: "22"
- name: Cache modules
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:

strategy:
matrix:
node-version: [14, 16, 18, 19]
node-version: [18, 20, 22]

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

$(npm bin)/lint-staged
lint-staged
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ samsam.match(
return "yeah";
},
},
"Yeah!"
"Yeah!",
); // true
```

Expand Down Expand Up @@ -278,7 +278,7 @@ samsam.match(
return "yeah!";
},
},
/yeah/
/yeah/,
); // true
samsam.match(234, /[a-z]/); // false
```
Expand All @@ -296,7 +296,7 @@ samsam.match(
return "42";
},
},
42
42,
); // true
samsam.match(234, 1234); // false
```
Expand Down Expand Up @@ -328,7 +328,7 @@ samsam.match(
},
function () {
return true;
}
},
);

// false
Expand Down Expand Up @@ -367,7 +367,7 @@ samsam.match(
},
{
name: "Chris",
}
},
);

// false
Expand Down
221 changes: 128 additions & 93 deletions lib/create-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var TYPE_MAP = require("./create-matcher/type-map")(createMatcher); // eslint-disable-line no-use-before-define

/**
* Creates a matcher object for the passed expectation

Check warning on line 30 in lib/create-matcher.js

View workflow job for this annotation

GitHub Actions / static-analysis

Expected only 0 line after block description
*
* @alias module:samsam.createMatcher
* @param {*} expectation An expecttation
Expand All @@ -44,7 +44,7 @@

if (arguments.length > 2) {
throw new TypeError(
`Expected 1 or 2 arguments, received ${arguments.length}`
`Expected 1 or 2 arguments, received ${arguments.length}`,
);
}

Expand Down Expand Up @@ -89,21 +89,27 @@
}, "falsy");

createMatcher.same = function (expectation) {
return createMatcher(function (actual) {
return expectation === actual;
}, `same(${valueToString(expectation)})`);
return createMatcher(
function (actual) {
return expectation === actual;
},
`same(${valueToString(expectation)})`,
);
};

createMatcher.in = function (arrayOfExpectations) {
if (typeOf(arrayOfExpectations) !== "array") {
throw new TypeError("array expected");
}

return createMatcher(function (actual) {
return some(arrayOfExpectations, function (expectation) {
return expectation === actual;
});
}, `in(${valueToString(arrayOfExpectations)})`);
return createMatcher(
function (actual) {
return some(arrayOfExpectations, function (expectation) {
return expectation === actual;
});
},
`in(${valueToString(arrayOfExpectations)})`,
);
};

createMatcher.typeOf = function (type) {
Expand All @@ -125,12 +131,15 @@
type,
Symbol.hasInstance,
"type",
"[Symbol.hasInstance]"
"[Symbol.hasInstance]",
);
}
return createMatcher(function (actual) {
return actual instanceof type;
}, `instanceOf(${functionName(type) || objectToString(type)})`);
return createMatcher(
function (actual) {
return actual instanceof type;
},
`instanceOf(${functionName(type) || objectToString(type)})`,
);
};

/**
Expand Down Expand Up @@ -259,111 +268,137 @@
createMatcher.array = createMatcher.typeOf("array");

createMatcher.array.deepEquals = function (expectation) {
return createMatcher(function (actual) {
// Comparing lengths is the fastest way to spot a difference before iterating through every item
var sameLength = actual.length === expectation.length;
return (
typeOf(actual) === "array" &&
sameLength &&
every(actual, function (element, index) {
var expected = expectation[index];
return typeOf(expected) === "array" &&
typeOf(element) === "array"
? createMatcher.array.deepEquals(expected).test(element)
: deepEqual(expected, element);
})
);
}, `deepEquals([${iterableToString(expectation)}])`);
return createMatcher(
function (actual) {
// Comparing lengths is the fastest way to spot a difference before iterating through every item
var sameLength = actual.length === expectation.length;
return (
typeOf(actual) === "array" &&
sameLength &&
every(actual, function (element, index) {
var expected = expectation[index];
return typeOf(expected) === "array" &&
typeOf(element) === "array"
? createMatcher.array.deepEquals(expected).test(element)
: deepEqual(expected, element);
})
);
},
`deepEquals([${iterableToString(expectation)}])`,
);
};

createMatcher.array.startsWith = function (expectation) {
return createMatcher(function (actual) {
return (
typeOf(actual) === "array" &&
every(expectation, function (expectedElement, index) {
return actual[index] === expectedElement;
})
);
}, `startsWith([${iterableToString(expectation)}])`);
return createMatcher(
function (actual) {
return (
typeOf(actual) === "array" &&
every(expectation, function (expectedElement, index) {
return actual[index] === expectedElement;
})
);
},
`startsWith([${iterableToString(expectation)}])`,
);
};

createMatcher.array.endsWith = function (expectation) {
return createMatcher(function (actual) {
// This indicates the index in which we should start matching
var offset = actual.length - expectation.length;

return (
typeOf(actual) === "array" &&
every(expectation, function (expectedElement, index) {
return actual[offset + index] === expectedElement;
})
);
}, `endsWith([${iterableToString(expectation)}])`);
return createMatcher(
function (actual) {
// This indicates the index in which we should start matching
var offset = actual.length - expectation.length;

return (
typeOf(actual) === "array" &&
every(expectation, function (expectedElement, index) {
return actual[offset + index] === expectedElement;
})
);
},
`endsWith([${iterableToString(expectation)}])`,
);
};

createMatcher.array.contains = function (expectation) {
return createMatcher(function (actual) {
return (
typeOf(actual) === "array" &&
every(expectation, function (expectedElement) {
return arrayIndexOf(actual, expectedElement) !== -1;
})
);
}, `contains([${iterableToString(expectation)}])`);
return createMatcher(
function (actual) {
return (
typeOf(actual) === "array" &&
every(expectation, function (expectedElement) {
return arrayIndexOf(actual, expectedElement) !== -1;
})
);
},
`contains([${iterableToString(expectation)}])`,
);
};

createMatcher.map = createMatcher.typeOf("map");

createMatcher.map.deepEquals = function mapDeepEquals(expectation) {
return createMatcher(function (actual) {
// Comparing lengths is the fastest way to spot a difference before iterating through every item
var sameLength = actual.size === expectation.size;
return (
typeOf(actual) === "map" &&
sameLength &&
every(actual, function (element, key) {
return expectation.has(key) && expectation.get(key) === element;
})
);
}, `deepEquals(Map[${iterableToString(expectation)}])`);
return createMatcher(
function (actual) {
// Comparing lengths is the fastest way to spot a difference before iterating through every item
var sameLength = actual.size === expectation.size;
return (
typeOf(actual) === "map" &&
sameLength &&
every(actual, function (element, key) {
return (
expectation.has(key) && expectation.get(key) === element
);
})
);
},
`deepEquals(Map[${iterableToString(expectation)}])`,
);
};

createMatcher.map.contains = function mapContains(expectation) {
return createMatcher(function (actual) {
return (
typeOf(actual) === "map" &&
every(expectation, function (element, key) {
return actual.has(key) && actual.get(key) === element;
})
);
}, `contains(Map[${iterableToString(expectation)}])`);
return createMatcher(
function (actual) {
return (
typeOf(actual) === "map" &&
every(expectation, function (element, key) {
return actual.has(key) && actual.get(key) === element;
})
);
},
`contains(Map[${iterableToString(expectation)}])`,
);
};

createMatcher.set = createMatcher.typeOf("set");

createMatcher.set.deepEquals = function setDeepEquals(expectation) {
return createMatcher(function (actual) {
// Comparing lengths is the fastest way to spot a difference before iterating through every item
var sameLength = actual.size === expectation.size;
return (
typeOf(actual) === "set" &&
sameLength &&
every(actual, function (element) {
return expectation.has(element);
})
);
}, `deepEquals(Set[${iterableToString(expectation)}])`);
return createMatcher(
function (actual) {
// Comparing lengths is the fastest way to spot a difference before iterating through every item
var sameLength = actual.size === expectation.size;
return (
typeOf(actual) === "set" &&
sameLength &&
every(actual, function (element) {
return expectation.has(element);
})
);
},
`deepEquals(Set[${iterableToString(expectation)}])`,
);
};

createMatcher.set.contains = function setContains(expectation) {
return createMatcher(function (actual) {
return (
typeOf(actual) === "set" &&
every(expectation, function (element) {
return actual.has(element);
})
);
}, `contains(Set[${iterableToString(expectation)}])`);
return createMatcher(
function (actual) {
return (
typeOf(actual) === "set" &&
every(expectation, function (element) {
return actual.has(element);
})
);
},
`contains(Set[${iterableToString(expectation)}])`,
);
};

createMatcher.bool = createMatcher.typeOf("boolean");
Expand Down
Loading
Loading