or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array.mdcollection.mddate.mdfunction.mdindex.mdlang.mdmath.mdnumber.mdobject.mdseq.mdstring.mdutil.md
tile.json

lang.mddocs/

0

# Type Checking Functions

1

2

Comprehensive type checking utilities for validating data types, including primitives, objects, arrays, and special types.

3

4

## Capabilities

5

6

### Basic Type Checking

7

8

Core functions for checking primitive and common data types.

9

10

```javascript { .api }

11

/**

12

* Checks if value is classified as an Array object

13

* @param {*} value - The value to check

14

* @returns {boolean} Returns true if value is an array, else false

15

*/

16

function isArray(value);

17

18

/**

19

* Checks if value is the Object language type

20

* @param {*} value - The value to check

21

* @returns {boolean} Returns true if value is an object, else false

22

*/

23

function isObject(value);

24

25

/**

26

* Checks if value is classified as a String primitive or object

27

* @param {*} value - The value to check

28

* @returns {boolean} Returns true if value is a string, else false

29

*/

30

function isString(value);

31

32

/**

33

* Checks if value is classified as a Number primitive or object

34

* @param {*} value - The value to check

35

* @returns {boolean} Returns true if value is a number, else false

36

*/

37

function isNumber(value);

38

39

/**

40

* Checks if value is classified as a boolean primitive or object

41

* @param {*} value - The value to check

42

* @returns {boolean} Returns true if value is a boolean, else false

43

*/

44

function isBoolean(value);

45

46

/**

47

* Checks if value is classified as a Function object

48

* @param {*} value - The value to check

49

* @returns {boolean} Returns true if value is a function, else false

50

*/

51

function isFunction(value);

52

53

/**

54

* Checks if value is undefined

55

* @param {*} value - The value to check

56

* @returns {boolean} Returns true if value is undefined, else false

57

*/

58

function isUndefined(value);

59

60

/**

61

* Checks if value is null

62

* @param {*} value - The value to check

63

* @returns {boolean} Returns true if value is null, else false

64

*/

65

function isNull(value);

66

67

/**

68

* Checks if value is null or undefined

69

* @param {*} value - The value to check

70

* @returns {boolean} Returns true if value is nullish, else false

71

*/

72

function isNil(value);

73

74

/**

75

* Casts value as an array if it's not one already

76

* @param {*} value - The value to inspect

77

* @returns {Array} Returns the cast array

78

*/

79

function castArray(value);

80

```

81

82

### Number and Comparison Functions

83

84

Functions for number validation and value comparison.

85

86

```javascript { .api }

87

/**

88

* Checks if value is a finite primitive number

89

* @param {*} value - The value to check

90

* @returns {boolean} Returns true if value is a finite number, else false

91

*/

92

function isFinite(value);

93

94

/**

95

* Checks if value is an integer

96

* @param {*} value - The value to check

97

* @returns {boolean} Returns true if value is an integer, else false

98

*/

99

function isInteger(value);

100

101

/**

102

* Checks if value is a valid array-like length

103

* @param {*} value - The value to check

104

* @returns {boolean} Returns true if value is a valid length, else false

105

*/

106

function isLength(value);

107

108

/**

109

* Checks if value is NaN

110

* @param {*} value - The value to check

111

* @returns {boolean} Returns true if value is NaN, else false

112

*/

113

function isNaN(value);

114

115

/**

116

* Checks if value is a pristine native function

117

* @param {*} value - The value to check

118

* @returns {boolean} Returns true if value is a native function, else false

119

*/

120

function isNative(value);

121

122

/**

123

* Checks if value is a safe integer

124

* @param {*} value - The value to check

125

* @returns {boolean} Returns true if value is a safe integer, else false

126

*/

127

function isSafeInteger(value);

128

129

/**

130

* Checks if value is greater than other

131

* @param {*} value - The value to compare

132

* @param {*} other - The other value to compare

133

* @returns {boolean} Returns true if value is greater than other, else false

134

*/

135

function gt(value, other);

136

137

/**

138

* Checks if value is greater than or equal to other

139

* @param {*} value - The value to compare

140

* @param {*} other - The other value to compare

141

* @returns {boolean} Returns true if value is greater than or equal to other, else false

142

*/

143

function gte(value, other);

144

145

/**

146

* Checks if value is less than other

147

* @param {*} value - The value to compare

148

* @param {*} other - The other value to compare

149

* @returns {boolean} Returns true if value is less than other, else false

150

*/

151

function lt(value, other);

152

153

/**

154

* Checks if value is less than or equal to other

155

* @param {*} value - The value to compare

156

* @param {*} other - The other value to compare

157

* @returns {boolean} Returns true if value is less than or equal to other, else false

158

*/

159

function lte(value, other);

160

```

161

162

### Type Conversion Functions

163

164

Functions for converting values to different types.

165

166

```javascript { .api }

167

/**

168

* Converts value to an array

169

* @param {*} value - The value to convert

170

* @returns {Array} Returns the converted array

171

*/

172

function toArray(value);

173

174

/**

175

* Converts value to a finite number

176

* @param {*} value - The value to convert

177

* @returns {number} Returns the converted number

178

*/

179

function toFinite(value);

180

181

/**

182

* Converts value to an integer

183

* @param {*} value - The value to convert

184

* @returns {number} Returns the converted integer

185

*/

186

function toInteger(value);

187

188

/**

189

* Converts value to an integer suitable for use as the length of an array-like object

190

* @param {*} value - The value to convert

191

* @returns {number} Returns the converted integer

192

*/

193

function toLength(value);

194

195

/**

196

* Converts value to a number

197

* @param {*} value - The value to convert

198

* @returns {number} Returns the converted number

199

*/

200

function toNumber(value);

201

202

/**

203

* Converts value to a plain object flattening inherited enumerable string keyed properties

204

* @param {*} value - The value to convert

205

* @returns {Object} Returns the converted plain object

206

*/

207

function toPlainObject(value);

208

209

/**

210

* Converts value to a safe integer

211

* @param {*} value - The value to convert

212

* @returns {number} Returns the converted integer

213

*/

214

function toSafeInteger(value);

215

216

/**

217

* Converts value to a string

218

* @param {*} value - The value to convert

219

* @returns {string} Returns the converted string

220

*/

221

function toString(value);

222

```

223

224

### Object Validation

225

226

Functions for validating object properties and structure.

227

228

```javascript { .api }

229

/**

230

* Checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object

231

* @param {Object} object - The object to inspect

232

* @param {Object} source - The object of property predicates to conform to

233

* @returns {boolean} Returns true if object conforms, else false

234

*/

235

function conformsTo(object, source);

236

```

237

238

### Object Cloning

239

240

Functions for creating shallow and deep copies of values.

241

242

```javascript { .api }

243

/**

244

* Creates a shallow clone of value

245

* @param {*} value - The value to clone

246

* @returns {*} Returns the cloned value

247

*/

248

function clone(value);

249

250

/**

251

* Creates a deep clone of value

252

* @param {*} value - The value to recursively clone

253

* @returns {*} Returns the deep cloned value

254

*/

255

function cloneDeep(value);

256

257

/**

258

* Like clone but accepts a customizer which is invoked to produce the cloned value

259

* @param {*} value - The value to clone

260

* @param {Function} customizer - The function to customize cloning

261

* @returns {*} Returns the cloned value

262

*/

263

function cloneWith(value, customizer);

264

265

/**

266

* Like cloneDeep but accepts a customizer which is invoked to produce the cloned value

267

* @param {*} value - The value to recursively clone

268

* @param {Function} customizer - The function to customize cloning

269

* @returns {*} Returns the deep cloned value

270

*/

271

function cloneDeepWith(value, customizer);

272

```

273

274

### Specialized Type Checking

275

276

Functions for checking specific object types and browser APIs.

277

278

```javascript { .api }

279

/**

280

* Checks if value is classified as a Date object

281

* @param {*} value - The value to check

282

* @returns {boolean} Returns true if value is a date object, else false

283

*/

284

function isDate(value);

285

286

/**

287

* Checks if value is classified as a RegExp object

288

* @param {*} value - The value to check

289

* @returns {boolean} Returns true if value is a regexp, else false

290

*/

291

function isRegExp(value);

292

293

/**

294

* Checks if value is an Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, or URIError object

295

* @param {*} value - The value to check

296

* @returns {boolean} Returns true if value is an error object, else false

297

*/

298

function isError(value);

299

300

/**

301

* Checks if value is likely a DOM element

302

* @param {*} value - The value to check

303

* @returns {boolean} Returns true if value is a DOM element, else false

304

*/

305

function isElement(value);

306

307

/**

308

* Checks if value is classified as an arguments object

309

* @param {*} value - The value to check

310

* @returns {boolean} Returns true if value is an arguments object, else false

311

*/

312

function isArguments(value);

313

314

/**

315

* Checks if value is classified as a Symbol primitive or object

316

* @param {*} value - The value to check

317

* @returns {boolean} Returns true if value is a symbol, else false

318

*/

319

function isSymbol(value);

320

```

321

322

### Collection and Buffer Type Checking

323

324

Functions for checking collection types and buffer objects.

325

326

```javascript { .api }

327

/**

328

* Checks if value is array-like

329

* @param {*} value - The value to check

330

* @returns {boolean} Returns true if value is array-like, else false

331

*/

332

function isArrayLike(value);

333

334

/**

335

* Checks if value is array-like and object

336

* @param {*} value - The value to check

337

* @returns {boolean} Returns true if value is an array-like object, else false

338

*/

339

function isArrayLikeObject(value);

340

341

/**

342

* Checks if value is a buffer

343

* @param {*} value - The value to check

344

* @returns {boolean} Returns true if value is a buffer, else false

345

*/

346

function isBuffer(value);

347

348

/**

349

* Checks if value is classified as a typed array

350

* @param {*} value - The value to check

351

* @returns {boolean} Returns true if value is a typed array, else false

352

*/

353

function isTypedArray(value);

354

355

/**

356

* Checks if value is classified as an ArrayBuffer object

357

* @param {*} value - The value to check

358

* @returns {boolean} Returns true if value is an array buffer, else false

359

*/

360

function isArrayBuffer(value);

361

```

362

363

### ES6 Collection Types

364

365

Functions for checking ES6 Map, Set, WeakMap, and WeakSet objects.

366

367

```javascript { .api }

368

/**

369

* Checks if value is classified as a Map object

370

* @param {*} value - The value to check

371

* @returns {boolean} Returns true if value is a map, else false

372

*/

373

function isMap(value);

374

375

/**

376

* Checks if value is classified as a Set object

377

* @param {*} value - The value to check

378

* @returns {boolean} Returns true if value is a set, else false

379

*/

380

function isSet(value);

381

382

/**

383

* Checks if value is classified as a WeakMap object

384

* @param {*} value - The value to check

385

* @returns {boolean} Returns true if value is a weak map, else false

386

*/

387

function isWeakMap(value);

388

389

/**

390

* Checks if value is classified as a WeakSet object

391

* @param {*} value - The value to check

392

* @returns {boolean} Returns true if value is a weak set, else false

393

*/

394

function isWeakSet(value);

395

```

396

397

### Object State and Content Checking

398

399

Functions for checking object properties and emptiness.

400

401

```javascript { .api }

402

/**

403

* Checks if value is an empty object, collection, map, or set

404

* @param {*} value - The value to check

405

* @returns {boolean} Returns true if value is empty, else false

406

*/

407

function isEmpty(value);

408

409

/**

410

* Checks if value is a plain object

411

* @param {*} value - The value to check

412

* @returns {boolean} Returns true if value is a plain object, else false

413

*/

414

function isPlainObject(value);

415

416

/**

417

* Checks if value is object-like

418

* @param {*} value - The value to check

419

* @returns {boolean} Returns true if value is object-like, else false

420

*/

421

function isObjectLike(value);

422

```

423

424

### Value Comparison and Validation

425

426

Functions for deep equality checking and value matching.

427

428

```javascript { .api }

429

/**

430

* Performs a deep comparison between two values to determine if they are equivalent

431

* @param {*} value - The value to compare

432

* @param {*} other - The other value to compare

433

* @returns {boolean} Returns true if the values are equivalent, else false

434

*/

435

function isEqual(value, other);

436

437

/**

438

* Like isEqual but accepts customizer which is invoked to compare values

439

* @param {*} value - The value to compare

440

* @param {*} other - The other value to compare

441

* @param {Function} customizer - The function to customize comparisons

442

* @returns {boolean} Returns true if the values are equivalent, else false

443

*/

444

function isEqualWith(value, other, customizer);

445

446

/**

447

* Performs a partial deep comparison between object and source to determine if object contains equivalent property values

448

* @param {Object} object - The object to inspect

449

* @param {Object} source - The object of property values to match

450

* @returns {boolean} Returns true if object is a match, else false

451

*/

452

function isMatch(object, source);

453

454

/**

455

* Like isMatch but accepts customizer which is invoked to compare values

456

* @param {Object} object - The object to inspect

457

* @param {Object} source - The object of property values to match

458

* @param {Function} customizer - The function to customize comparisons

459

* @returns {boolean} Returns true if object is a match, else false

460

*/

461

function isMatchWith(object, source, customizer);

462

463

/**

464

* Performs SameValueZero comparison between two values to determine if they are equivalent

465

* @param {*} value - The value to compare

466

* @param {*} other - The other value to compare

467

* @returns {boolean} Returns true if the values are equivalent, else false

468

*/

469

function eq(value, other);

470

```

471

472

## Usage Examples

473

474

### Basic Type Checking

475

476

```javascript

477

import { isArray, isObject, isString, isNumber, isFunction } from "lodash-es";

478

479

// Basic type checks

480

console.log(isArray([1, 2, 3])); // true

481

console.log(isArray("hello")); // false

482

483

console.log(isObject({})); // true

484

console.log(isObject(null)); // false

485

486

console.log(isString("hello")); // true

487

console.log(isString(123)); // false

488

489

console.log(isNumber(42)); // true

490

console.log(isNumber("42")); // false

491

492

console.log(isFunction(() => {})); // true

493

console.log(isFunction({})); // false

494

495

// Basic type checking examples

496

const userData = { name: "Alice", age: 25 };

497

console.log(isObject(userData)); // true

498

console.log(isString(userData.name)); // true

499

console.log(isNumber(userData.age)); // true

500

```

501

502

### Collection and Object Validation

503

504

```javascript

505

import { isEmpty, isPlainObject, isArrayLike, isEqual } from "lodash-es";

506

507

// Check if values are empty

508

console.log(isEmpty([])); // true

509

console.log(isEmpty({})); // true

510

console.log(isEmpty("")); // true

511

console.log(isEmpty([1, 2, 3])); // false

512

513

// Check for plain objects (not class instances)

514

console.log(isPlainObject({})); // true

515

console.log(isPlainObject(new Date())); // false

516

console.log(isPlainObject(Object.create(null))); // true

517

518

// Check array-like objects

519

console.log(isArrayLike([1, 2, 3])); // true

520

console.log(isArrayLike("hello")); // true

521

console.log(isArrayLike({ 0: 'a', 1: 'b', length: 2 })); // true

522

console.log(isArrayLike({})); // false

523

524

// Deep equality comparison

525

const obj1 = { a: 1, b: { c: 2 } };

526

const obj2 = { a: 1, b: { c: 2 } };

527

const obj3 = { a: 1, b: { c: 3 } };

528

529

console.log(isEqual(obj1, obj2)); // true

530

console.log(isEqual(obj1, obj3)); // false

531

console.log(obj1 === obj2); // false (reference comparison)

532

```

533

534

### Complex Validation Example

535

536

```javascript

537

import {

538

isString, isNumber, isBoolean, isArray,

539

isEmpty

540

} from "lodash-es";

541

542

// Example of combining multiple type checks

543

const formData = {

544

name: "Alice",

545

age: 25,

546

active: true,

547

tags: ["developer", "javascript"]

548

};

549

550

// Validate each field

551

console.log(isString(formData.name) && !isEmpty(formData.name)); // true

552

console.log(isNumber(formData.age) && formData.age > 0); // true

553

console.log(isBoolean(formData.active)); // true

554

console.log(isArray(formData.tags) && formData.tags.every(isString)); // true

555

```

556

557

### Object Cloning Examples

558

559

```javascript

560

import { clone, cloneDeep, cloneWith, cloneDeepWith } from "lodash-es";

561

562

// Shallow cloning

563

const original = { a: 1, b: { c: 2 } };

564

const shallowCopy = clone(original);

565

566

console.log(shallowCopy === original); // false

567

console.log(shallowCopy.b === original.b); // true (shallow)

568

569

// Deep cloning

570

const deepCopy = cloneDeep(original);

571

console.log(deepCopy.b === original.b); // false (deep)

572

573

// Arrays

574

const arr = [1, 2, [3, 4]];

575

const shallowArr = clone(arr);

576

const deepArr = cloneDeep(arr);

577

578

console.log(shallowArr[2] === arr[2]); // true (shallow)

579

console.log(deepArr[2] === arr[2]); // false (deep)

580

581

// Custom cloning

582

const customClone = cloneWith(original, (value) => {

583

if (typeof value === 'number') {

584

return value * 2; // Double all numbers

585

}

586

});

587

588

// Deep custom cloning

589

const customDeepClone = cloneDeepWith(original, (value) => {

590

if (typeof value === 'number') {

591

return value * 2;

592

}

593

});

594

```