1111/* eslint-disable local/prefer-eqeq-nullish-comparison */
1212/* eslint-disable prefer-rest-params */
1313
14- // #region Primitive
14+ // #region Helper
1515
1616/**
1717 * 1-byte version `undefined`, produces fewer bytes than `undefined` or `void 0` in output files.
@@ -23,6 +23,23 @@ export type _ = undefined; // eslint-disable-line local/no-shadow-underscore
2323 */
2424export const _ = undefined ; // eslint-disable-line local/no-shadow-underscore
2525
26+ export type Pretty < T > =
27+ & {
28+ [ P in keyof T ] : T [ P ] ;
29+ }
30+ & { } ;
31+
32+ /**
33+ * An extension of Extract for type predicates which falls back to the base
34+ * in order to narrow the `unknown` case.
35+ *
36+ * @example
37+ * function isMyType<T>(data: T | MyType): data is NarrowedTo<T, MyType> { ... }
38+ */
39+ export type NarrowedTo < T , Base > = Extract < T , Base > extends never ? Base
40+ : 0 extends 1 & NoInfer < T > ? Base
41+ : Extract < T , Base > ;
42+
2643// #endregion
2744
2845// #region Function
@@ -1007,28 +1024,21 @@ export function isTruthy<T>(data: T): data is Exclude<T, "" | 0 | false | null |
10071024
10081025// #endregion
10091026
1010- // #region Helper
1027+ // #region Object & Array
10111028
1012- export type Pretty < T > =
1013- & {
1014- [ P in keyof T ] : T [ P ] ;
1015- }
1016- & { } ;
1029+ export function chunk < T > ( array : T [ ] , size : number ) : T [ ] [ ] {
1030+ const chunks : T [ ] [ ] = [ ] ;
10171031
1018- /**
1019- * An extension of Extract for type predicates which falls back to the base
1020- * in order to narrow the `unknown` case.
1021- *
1022- * @example
1023- * function isMyType<T>(data: T | MyType): data is NarrowedTo<T, MyType> { ... }
1024- */
1025- export type NarrowedTo < T , Base > = Extract < T , Base > extends never ? Base
1026- : 0 extends 1 & NoInfer < T > ? Base
1027- : Extract < T , Base > ;
1032+ if ( size <= 0 ) {
1033+ return chunks ;
1034+ }
10281035
1029- // #endregion
1036+ for ( let i = 0 , j = array . length ; i < j ; i += size ) {
1037+ chunks . push ( array . slice ( i , i + size ) ) ;
1038+ }
10301039
1031- // #region Array
1040+ return chunks ;
1041+ }
10321042
10331043/**
10341044 * Creates a new array from two supplied arrays by calling the supplied function
0 commit comments