The map schema validates that the input is a map of keys and values that match the schemas. It fails for anything that is not a map, or for any key or value of the map that does not match the schemas.
map
import { map, string, number } from "typerun/schema";import { is } from "typerun";const mapEx = new Map([ ["a", 1], ["b", 2],]);const isMap = is(map(string, number))(mapEx);console.log(isMap); // trueconst isNotMap = is(map(string, number))({ a: 1, b: 2 });console.log(isNotMap); // falseconst isNotCorrectMapKeys = is(map(number, number))(mapEx);console.log(isNotCorrectMapKeys); // falseconst isNotCorrectMapValues = is(map(string, string))(mapEx);console.log(isNotCorrectMapValues); // false Copy
import { map, string, number } from "typerun/schema";import { is } from "typerun";const mapEx = new Map([ ["a", 1], ["b", 2],]);const isMap = is(map(string, number))(mapEx);console.log(isMap); // trueconst isNotMap = is(map(string, number))({ a: 1, b: 2 });console.log(isNotMap); // falseconst isNotCorrectMapKeys = is(map(number, number))(mapEx);console.log(isNotCorrectMapKeys); // falseconst isNotCorrectMapValues = is(map(string, string))(mapEx);console.log(isNotCorrectMapValues); // false
The schema to validate the keys of the map.
The schema to validate the values of the map.
The
map
schema validates that the input is a map of keys and values that match the schemas. It fails for anything that is not a map, or for any key or value of the map that does not match the schemas.Example