Skip to content

Commit

Permalink
Update all dependencies (#247)
Browse files Browse the repository at this point in the history
* Update all dependencies

* Update runner versions

* Prettify
  • Loading branch information
fatso83 authored Sep 12, 2024
1 parent 153c0a7 commit ca41112
Show file tree
Hide file tree
Showing 16 changed files with 3,553 additions and 4,632 deletions.
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 @@ -44,7 +44,7 @@ function createMatcher(expectation, message) {

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 @@ createMatcher.falsy = createMatcher(function (actual) {
}, "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 @@ createMatcher.instanceOf = function (type) {
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.some = function (predicate) {
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

0 comments on commit ca41112

Please sign in to comment.