or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

collection-validation.mdconfiguration.mddate-time.mdenvironment-detection.mdindex.mdnumeric-operations.mdpattern-matching.mdpresence-checking.mdstring-checking.mdtype-checking.md
tile.json

type-checking.mddocs/

0

# Type Checking

1

2

Core type validation functions for JavaScript primitives and objects. Essential for runtime type safety and input validation.

3

4

## Capabilities

5

6

### Basic Type Detection

7

8

#### Arguments Check

9

10

Checks if the given value is an Arguments object.

11

12

```javascript { .api }

13

/**

14

* Checks if the given value type is arguments

15

* @param value - Value to check

16

* @returns True if value is Arguments object

17

* Interfaces: not, all, any

18

*/

19

function arguments(value: any): boolean;

20

```

21

22

**Usage Example:**

23

24

```javascript

25

function getArguments() {

26

return arguments;

27

}

28

const args = getArguments('test');

29

30

is.arguments(args); // true

31

is.not.arguments({foo: 'bar'}); // true

32

is.all.arguments(args, 'bar'); // false

33

is.any.arguments(['foo'], args); // true

34

```

35

36

#### Array Check

37

38

Checks if the given value is an Array.

39

40

```javascript { .api }

41

/**

42

* Checks if the given value type is array

43

* @param value - Value to check

44

* @returns True if value is Array

45

* Interfaces: not, all, any

46

*/

47

function array(value: any): boolean;

48

```

49

50

**Usage Example:**

51

52

```javascript

53

is.array(['foo', 'bar', 'baz']); // true

54

is.not.array({foo: 'bar'}); // true

55

is.all.array(['foo'], 'bar'); // false

56

is.any.array(['foo'], 'bar'); // true

57

```

58

59

#### Boolean Check

60

61

Checks if the given value is a Boolean.

62

63

```javascript { .api }

64

/**

65

* Checks if the given value type is boolean

66

* @param value - Value to check

67

* @returns True if value is Boolean

68

* Interfaces: not, all, any

69

*/

70

function boolean(value: any): boolean;

71

```

72

73

**Usage Example:**

74

75

```javascript

76

is.boolean(true); // true

77

is.not.boolean({foo: 'bar'}); // true

78

is.all.boolean(true, 'bar'); // false

79

is.any.boolean(true, 'bar'); // true

80

```

81

82

#### Character Check

83

84

Checks if the given value is a single character string.

85

86

```javascript { .api }

87

/**

88

* Checks if the given value type is char

89

* @param value - Value to check

90

* @returns True if value is single character string

91

* Interfaces: not, all, any

92

*/

93

function char(value: any): boolean;

94

```

95

96

**Usage Example:**

97

98

```javascript

99

is.char('f'); // true

100

is.not.char(['foo']); // true

101

is.all.char('f', 1); // false

102

is.any.char('f', 2); // true

103

is.all.char(['f', 'o', 'o']); // true

104

```

105

106

#### Date Check

107

108

Checks if the given value is a Date object.

109

110

```javascript { .api }

111

/**

112

* Checks if the given value type is date

113

* @param value - Value to check

114

* @returns True if value is Date object

115

* Interfaces: not, all, any

116

*/

117

function date(value: any): boolean;

118

```

119

120

**Usage Example:**

121

122

```javascript

123

is.date(new Date()); // true

124

is.not.date({foo: 'bar'}); // true

125

is.all.date(new Date(), 'bar'); // false

126

is.any.date(new Date(), 'bar'); // true

127

```

128

129

#### Error Check

130

131

Checks if the given value is an Error object.

132

133

```javascript { .api }

134

/**

135

* Checks if the given value type is error

136

* @param value - Value to check

137

* @returns True if value is Error object

138

* Interfaces: not, all, any

139

*/

140

function error(value: any): boolean;

141

```

142

143

**Usage Example:**

144

145

```javascript

146

is.error(new Error()); // true

147

is.not.error({foo: 'bar'}); // true

148

is.all.error(new Error(), 'bar'); // false

149

is.any.error(new Error(), 'bar'); // true

150

```

151

152

#### Function Check

153

154

Checks if the given value is a Function.

155

156

```javascript { .api }

157

/**

158

* Checks if the given value type is function

159

* @param value - Value to check

160

* @returns True if value is Function

161

* Interfaces: not, all, any

162

*/

163

function function(value: any): boolean;

164

```

165

166

**Usage Example:**

167

168

```javascript

169

is.function(toString); // true

170

is.not.function({foo: 'bar'}); // true

171

is.all.function(toString, 'bar'); // false

172

is.any.function(toString, 'bar'); // true

173

```

174

175

#### NaN Check

176

177

Checks if the given value is NaN.

178

179

```javascript { .api }

180

/**

181

* Checks if the given value type is NaN

182

* @param value - Value to check

183

* @returns True if value is NaN

184

* Interfaces: not, all, any

185

*/

186

function nan(value: any): boolean;

187

```

188

189

**Usage Example:**

190

191

```javascript

192

is.nan(NaN); // true

193

is.not.nan(42); // true

194

is.all.nan(NaN, 1); // false

195

is.any.nan(NaN, 2); // true

196

```

197

198

#### Null Check

199

200

Checks if the given value is null.

201

202

```javascript { .api }

203

/**

204

* Checks if the given value type is null

205

* @param value - Value to check

206

* @returns True if value is null

207

* Interfaces: not, all, any

208

*/

209

function null(value: any): boolean;

210

```

211

212

**Usage Example:**

213

214

```javascript

215

is.null(null); // true

216

is.not.null(42); // true

217

is.all.null(null, 1); // false

218

is.any.null(null, 2); // true

219

```

220

221

#### Number Check

222

223

Checks if the given value is a Number (excluding NaN).

224

225

```javascript { .api }

226

/**

227

* Checks if the given value type is number

228

* @param value - Value to check

229

* @returns True if value is Number and not NaN

230

* Interfaces: not, all, any

231

*/

232

function number(value: any): boolean;

233

```

234

235

**Usage Example:**

236

237

```javascript

238

is.number(42); // true

239

is.number(NaN); // false

240

is.not.number('42'); // true

241

is.all.number('foo', 1); // false

242

is.any.number({}, 2); // true

243

```

244

245

#### Object Check

246

247

Checks if the given value is an Object.

248

249

```javascript { .api }

250

/**

251

* Checks if the given value type is object

252

* @param value - Value to check

253

* @returns True if value is Object (including functions)

254

* Interfaces: not, all, any

255

*/

256

function object(value: any): boolean;

257

```

258

259

**Usage Example:**

260

261

```javascript

262

is.object({foo: 'bar'}); // true

263

is.object(toString); // true (functions are objects)

264

is.not.object('foo'); // true

265

is.all.object({}, 1); // false

266

is.any.object({}, 2); // true

267

```

268

269

#### RegExp Check

270

271

Checks if the given value is a RegExp.

272

273

```javascript { .api }

274

/**

275

* Checks if the given value type is RegExp

276

* @param value - Value to check

277

* @returns True if value is RegExp

278

* Interfaces: not, all, any

279

*/

280

function regexp(value: any): boolean;

281

```

282

283

**Usage Example:**

284

285

```javascript

286

is.regexp(/test/); // true

287

is.not.regexp(['foo']); // true

288

is.all.regexp(/test/, 1); // false

289

is.any.regexp(new RegExp('ab+c'), 2); // true

290

```

291

292

#### String Check

293

294

Checks if the given value is a String.

295

296

```javascript { .api }

297

/**

298

* Checks if the given value type is string

299

* @param value - Value to check

300

* @returns True if value is String

301

* Interfaces: not, all, any

302

*/

303

function string(value: any): boolean;

304

```

305

306

**Usage Example:**

307

308

```javascript

309

is.string('foo'); // true

310

is.not.string(['foo']); // true

311

is.all.string('foo', 1); // false

312

is.any.string('foo', 2); // true

313

```

314

315

#### Undefined Check

316

317

Checks if the given value is undefined.

318

319

```javascript { .api }

320

/**

321

* Checks if the given value type is undefined

322

* @param value - Value to check

323

* @returns True if value is undefined

324

* Interfaces: not, all, any

325

*/

326

function undefined(value: any): boolean;

327

```

328

329

**Usage Example:**

330

331

```javascript

332

is.undefined(undefined); // true

333

is.not.undefined(null); // true

334

is.all.undefined(undefined, 1); // false

335

is.any.undefined(undefined, 2); // true

336

```

337

338

### Advanced Type Checks

339

340

#### DOM Node Check

341

342

Checks if the given object is a DOM node.

343

344

```javascript { .api }

345

/**

346

* Checks if the given object is a dom node

347

* @param object - Object to check

348

* @returns True if object is DOM node

349

* Interfaces: not, all, any

350

*/

351

function domNode(object: any): boolean;

352

```

353

354

**Usage Example:**

355

356

```javascript

357

const obj = document.createElement('div');

358

is.domNode(obj); // true

359

is.domNode({nope: 'nope'}); // false

360

is.not.domNode({}); // true

361

is.all.domNode(obj, obj); // true

362

is.any.domNode(obj, {nope: 'nope'}); // true

363

```

364

365

#### JSON Object Check

366

367

Checks if the given value is a pure JSON object.

368

369

```javascript { .api }

370

/**

371

* Checks if the given value type is pure json object

372

* @param value - Value to check

373

* @returns True if value is pure JSON object

374

* Interfaces: not, all, any

375

*/

376

function json(value: any): boolean;

377

```

378

379

**Usage Example:**

380

381

```javascript

382

is.json({foo: 'bar'}); // true

383

is.json(toString); // false (functions are not JSON)

384

is.not.json([]); // true

385

is.all.json({}, 1); // false

386

is.any.json({}, 2); // true

387

```

388

389

#### Same Type Check

390

391

Checks if the given values are the same type.

392

393

```javascript { .api }

394

/**

395

* Checks if the given value types are same type

396

* @param value - First value to compare

397

* @param other - Second value to compare

398

* @returns True if values are same type

399

* Interfaces: not

400

*/

401

function sameType(value: any, other: any): boolean;

402

```

403

404

**Usage Example:**

405

406

```javascript

407

is.sameType(42, 7); // true

408

is.sameType(42, '7'); // false

409

is.not.sameType(42, 7); // false

410

```

411

412

#### Window Object Check

413

414

Checks if the given object is a window object.

415

416

```javascript { .api }

417

/**

418

* Checks if the given object is window object

419

* @param value - Value to check

420

* @returns True if value is window object

421

* Interfaces: not, all, any

422

*/

423

function windowObject(value: any): boolean;

424

```

425

426

**Usage Example:**

427

428

```javascript

429

is.windowObject(window); // true

430

is.windowObject({nope: 'nope'}); // false

431

is.not.windowObject({}); // true

432

is.all.windowObject(window, {nope: 'nope'}); // false

433

is.any.windowObject(window, {nope: 'nope'}); // true

434

```