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

Inline type-detect as a simple function #1544

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ Chai offers a robust Plugin architecture for extending Chai's assertions and int
- [chaijs / chai-docs](https://github.com/chaijs/chai-docs): The chaijs.com website source code.
- [chaijs / assertion-error](https://github.com/chaijs/assertion-error): Custom `Error` constructor thrown upon an assertion failing.
- [chaijs / deep-eql](https://github.com/chaijs/deep-eql): Improved deep equality testing for Node.js and the browser.
- [chaijs / type-detect](https://github.com/chaijs/type-detect): Improved typeof detection for Node.js and the browser.
koddsson marked this conversation as resolved.
Show resolved Hide resolved
- [chaijs / check-error](https://github.com/chaijs/check-error): Error comparison and information related utility for Node.js and the browser.
- [chaijs / loupe](https://github.com/chaijs/loupe): Inspect utility for Node.js and browsers.
- [chaijs / pathval](https://github.com/chaijs/pathval): Object value retrieval given a string path.
Expand Down
4 changes: 2 additions & 2 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ Assertion.addProperty('all', function () {
* ### .a(type[, msg])
*
* Asserts that the target's type is equal to the given string `type`. Types
* are case insensitive. See the `type-detect` project page for info on the
* type detection algorithm: https://github.com/chaijs/type-detect.
* are case insensitive. See the utility file `./type-detect.js` for info on the
* type detection algorithm.
*
* expect('foo').to.be.a('string');
* expect({a: 1}).to.be.an('object');
Expand Down
2 changes: 1 addition & 1 deletion lib/chai/utils/expectTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import AssertionError from 'assertion-error';
import {flag} from './flag.js';
import {default as type} from 'type-detect';
import {type} from './type-detect.js';

export function expectTypes(obj, types) {
var flagMsg = flag(obj, 'message');
Expand Down
3 changes: 1 addition & 2 deletions lib/chai/utils/getOperator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {flag} from './flag.js';
import type from 'type-detect';

import {type} from './type-detect.js';

function isObjectType(obj) {
var objectType = type(obj);
Expand Down
2 changes: 1 addition & 1 deletion lib/chai/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export {test} from './test.js';
* type utility
*/

export {default as type} from 'type-detect';
export {type} from './type-detect.js';

/*!
* expectTypes utility
Expand Down
18 changes: 18 additions & 0 deletions lib/chai/utils/type-detect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const typesToLowerCase = [
"Number",
"String",
"Boolean",
"Null",
"Undefined",
"Function",
"Symbol",
];

export function type(obj) {
const type = Object.prototype.toString.call(obj).slice(8, -1);
koddsson marked this conversation as resolved.
Show resolved Hide resolved

if (typesToLowerCase.includes(type)) {
return type.toLowerCase();
}
return type;
}
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
"check-error": "^2.0.0",
"deep-eql": "^5.0.0",
"loupe": "^2.3.1",
"pathval": "^2.0.0",
"type-detect": "^4.0.5"
"pathval": "^2.0.0"
},
"devDependencies": {
"bump-cli": "^1.1.3",
Expand Down