Skip to content

Commit 7e83d67

Browse files
committed
[New] add types
1 parent ac86dd7 commit 7e83d67

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

Diff for: index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare function isString(value: unknown): value is string | String;
2+
3+
export = isString;

Diff for: index.js

+4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
var callBound = require('call-bind/callBound');
44

5+
/** @type {(receiver: ThisParameterType<typeof String.prototype.valueOf>, ...args: Parameters<typeof String.prototype.valueOf>) => ReturnType<typeof String.prototype.valueOf>} */
56
var $strValueOf = callBound('String.prototype.valueOf');
67

8+
/** @type {import('.')} */
79
var tryStringObject = function tryStringObject(value) {
810
try {
911
$strValueOf(value);
@@ -12,10 +14,12 @@ var tryStringObject = function tryStringObject(value) {
1214
return false;
1315
}
1416
};
17+
/** @type {(receiver: ThisParameterType<typeof Object.prototype.toString>, ...args: Parameters<typeof Object.prototype.toString>) => ReturnType<typeof Object.prototype.toString>} */
1518
var $toString = callBound('Object.prototype.toString');
1619
var strClass = '[object String]';
1720
var hasToStringTag = require('has-tostringtag/shams')();
1821

22+
/** @type {import('.')} */
1923
module.exports = function isString(value) {
2024
if (typeof value === 'string') {
2125
return true;

Diff for: package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"posttest": "npx npm@'>=10.2' audit --production",
2020
"prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')",
2121
"lint": "eslint --ext=js,mjs .",
22+
"postlint": "tsc -p . && attw -P",
2223
"version": "auto-changelog && git add CHANGELOG.md",
2324
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
2425
},
@@ -39,7 +40,12 @@
3940
"has-tostringtag": "^1.0.2"
4041
},
4142
"devDependencies": {
43+
"@arethetypeswrong/cli": "^0.17.0",
4244
"@ljharb/eslint-config": "^21.1.1",
45+
"@ljharb/tsconfig": "^0.2.0",
46+
"@types/call-bind": "^1.0.5",
47+
"@types/core-js": "^2.5.8",
48+
"@types/tape": "^5.6.5",
4349
"auto-changelog": "^2.5.0",
4450
"core-js": "^3.39.0",
4551
"eclint": "^2.8.1",
@@ -50,7 +56,8 @@
5056
"npmignore": "^0.3.1",
5157
"nyc": "^10.3.2",
5258
"safe-publish-latest": "^2.0.0",
53-
"tape": "^5.9.0"
59+
"tape": "^5.9.0",
60+
"typescript": "next"
5461
},
5562
"testling": {
5663
"files": "test/index.js",

Diff for: test/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var isString = require('../');
55
var hasToStringTag = require('has-tostringtag/shams')();
66

77
test('not Strings', function (t) {
8+
// @ts-expect-error
89
t.notOk(isString(), 'undefined is not String');
910
t.notOk(isString(null), 'null is not String');
1011
t.notOk(isString(false), 'false is not String');
@@ -23,6 +24,7 @@ test('not Strings', function (t) {
2324
});
2425

2526
test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
27+
/** @type {{ toString(): unknown; valueOf(): unknown; [Symbol.toStringTag]?: string; }} */
2628
var fakeString = {
2729
toString: function () { return '7'; },
2830
valueOf: function () { return '42'; }

Diff for: tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@ljharb/tsconfig",
3+
"compilerOptions": {
4+
"target": "ES2021",
5+
},
6+
"exclude": [
7+
"coverage"
8+
]
9+
}

0 commit comments

Comments
 (0)