Skip to content

Commit 01fa857

Browse files
committed
[schema] implemented lib0/schema, a fast & extremely small alternative to zod
1 parent 9529c21 commit 01fa857

File tree

12 files changed

+1117
-97
lines changed

12 files changed

+1117
-97
lines changed

array.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ export const from = Array.from
5555
* True iff condition holds on every element in the Array.
5656
*
5757
* @function
58-
* @template ITEM
59-
* @template {ArrayLike<ITEM>} ARR
58+
* @template {ArrayLike<any>} ARR
6059
*
6160
* @param {ARR} arr
62-
* @param {function(ITEM, number, ARR):boolean} f
61+
* @param {ARR extends ArrayLike<infer S> ? ((value:S, index:number, arr:ARR) => boolean) : any} f
6362
* @return {boolean}
6463
*/
6564
export const every = (arr, f) => {
@@ -75,10 +74,10 @@ export const every = (arr, f) => {
7574
* True iff condition holds on some element in the Array.
7675
*
7776
* @function
78-
* @template S
79-
* @template {ArrayLike<S>} ARR
77+
* @template {ArrayLike<any>} ARR
78+
*
8079
* @param {ARR} arr
81-
* @param {function(S, number, ARR):boolean} f
80+
* @param {ARR extends ArrayLike<infer S> ? ((value:S, index:number, arr:ARR) => boolean) : never} f
8281
* @return {boolean}
8382
*/
8483
export const some = (arr, f) => {

object.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ export const length = obj => keys(obj).length
6767
export const size = obj => keys(obj).length
6868

6969
/**
70-
* @param {Object<string,any>} obj
71-
* @param {function(any,string):boolean} f
70+
* @template {{ [key:string|number|symbol]: any }} T
71+
* @param {T} obj
72+
* @param {(v:T[keyof T],k:keyof T)=>boolean} f
7273
* @return {boolean}
7374
*/
7475
export const some = (obj, f) => {
@@ -92,8 +93,9 @@ export const isEmpty = obj => {
9293
}
9394

9495
/**
95-
* @param {Object<string,any>} obj
96-
* @param {function(any,string):boolean} f
96+
* @template {{ [key:string|number|symbol]: any }} T
97+
* @param {T} obj
98+
* @param {(v:T[keyof T],k:keyof T)=>boolean} f
9799
* @return {boolean}
98100
*/
99101
export const every = (obj, f) => {

object.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const testObject = _tc => {
1515
t.assert(object.equalFlat({ x: undefined }, { x: undefined }), 'flatEqual handles undefined')
1616
t.assert(!object.equalFlat({ x: undefined }, { y: {} }), 'flatEqual handles undefined')
1717
t.describe('object.every')
18+
// @ts-expect-error k has no overlap with "c"
1819
t.assert(object.every({ a: 1, b: 3 }, (v, k) => (v % 2) === 1 && k !== 'c'))
1920
t.assert(!object.every({ a: 1, b: 3, c: 5 }, (v, k) => (v % 2) === 1 && k !== 'c'))
2021
t.describe('object.some')

0 commit comments

Comments
 (0)