@wixc3/common
Advanced tools
Comparing version 3.0.3 to 3.0.4
@@ -62,11 +62,11 @@ import { Flat, Mapping, Predicate } from './iterables'; | ||
export declare function chain<T, V extends NotIterable<T>>(value: V): ValueChain<V>; | ||
export declare type IterableChain<T> = Chain<T> & { | ||
export type IterableChain<T> = Chain<T> & { | ||
value: Iterable<T>; | ||
}; | ||
export declare type ValueChain<T> = Chain<T> & { | ||
export type ValueChain<T> = Chain<T> & { | ||
value: T; | ||
}; | ||
export declare type NotIterable<T> = T extends Iterable<unknown> ? never : T; | ||
export declare type Iter<T> = T extends Iterable<infer E> ? Iterable<E> : Iterable<T>; | ||
export declare type Chain<T> = { | ||
export type NotIterable<T> = T extends Iterable<unknown> ? never : T; | ||
export type Iter<T> = T extends Iterable<infer E> ? Iterable<E> : Iterable<T>; | ||
export type Chain<T> = { | ||
last: () => ValueChain<T>; | ||
@@ -73,0 +73,0 @@ first: () => ValueChain<T>; |
@@ -7,3 +7,9 @@ "use strict"; | ||
function chain(value) { | ||
const iterable = (value === undefined ? [] : value === null ? [null] : Symbol.iterator in value ? value : [value]); | ||
const iterable = (value === undefined | ||
? [] | ||
: value === null | ||
? [null] | ||
: typeof value === 'object' && Symbol.iterator in value | ||
? value | ||
: [value]); | ||
return iterable === value ? chainIter(iterable) : chainElement(value); | ||
@@ -10,0 +16,0 @@ } |
@@ -1,3 +0,3 @@ | ||
export declare type PromiseResolveCb<T> = (value: T | PromiseLike<T>) => void; | ||
export declare type PromiseRejectCb = (reason?: any) => void; | ||
export type PromiseResolveCb<T> = (value: T | PromiseLike<T>) => void; | ||
export type PromiseRejectCb = (reason?: any) => void; | ||
export interface IDeferredPromise<T> { | ||
@@ -4,0 +4,0 @@ promise: Promise<T>; |
import { Nullable } from './types'; | ||
export declare type Mapping<S, T> = (src: S) => T; | ||
export declare type Predicate<S, V = boolean> = (src: S) => V; | ||
export declare type Flat<T> = T extends Iterable<infer A> ? A : T; | ||
export type Mapping<S, T> = (src: S) => T; | ||
export type Predicate<S, V = boolean> = (src: S) => V; | ||
export type Flat<T> = T extends Iterable<infer A> ? A : T; | ||
/** | ||
@@ -6,0 +6,0 @@ * Picks the last element of an iterable |
@@ -15,4 +15,4 @@ import { Nullable } from './types'; | ||
export declare function has(obj: null | undefined, key: unknown | never): false; | ||
export declare type MapValue<T> = T extends Map<infer _, infer V> ? V : never; | ||
export declare type ObjValue<O extends object, K extends keyof O = keyof O> = O[K]; | ||
export type MapValue<T> = T extends Map<infer _, infer V> ? V : never; | ||
export type ObjValue<O extends object, K extends keyof O = keyof O> = O[K]; | ||
/** | ||
@@ -19,0 +19,0 @@ * Similar to Map.get, but works for plain objects, and returns undefined |
@@ -93,4 +93,4 @@ import type { UnionToIntersection } from './types'; | ||
declare const DELETE: unique symbol; | ||
export declare type Remap<T> = Partial<Record<keyof T, string | typeof DELETE>>; | ||
export declare type Remapped<T extends object, R> = UnionToIntersection<R extends Partial<Record<keyof T, string | typeof DELETE>> ? { | ||
export type Remap<T> = Partial<Record<keyof T, string | typeof DELETE>>; | ||
export type Remapped<T extends object, R> = UnionToIntersection<R extends Partial<Record<keyof T, string | typeof DELETE>> ? { | ||
[K in keyof T]: K extends keyof R ? R[K] extends string ? { | ||
@@ -102,3 +102,3 @@ [L in R[K]]: T[K]; | ||
}[keyof T] : never>; | ||
export declare type RemapFunc = { | ||
export type RemapFunc = { | ||
<T extends object, R extends Remap<T>>(obj: T, rename: R): Remapped<T, R>; | ||
@@ -105,0 +105,0 @@ readonly DELETE: typeof DELETE; |
/** | ||
* The resolved value of T (if a promise, otherwise simply T) | ||
*/ | ||
export declare type Awaited<T> = T extends PromiseLike<infer U> ? U : T; | ||
export type Awaited<T> = T extends PromiseLike<infer U> ? U : T; | ||
/** | ||
* T or null/undefined | ||
*/ | ||
export declare type Nullable<T> = T | null | undefined; | ||
export type Nullable<T> = T | null | undefined; | ||
/** | ||
@@ -37,3 +37,3 @@ * Validates s is an instance of Map | ||
*/ | ||
export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; | ||
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -62,11 +62,11 @@ import { Flat, Mapping, Predicate } from './iterables'; | ||
export declare function chain<T, V extends NotIterable<T>>(value: V): ValueChain<V>; | ||
export declare type IterableChain<T> = Chain<T> & { | ||
export type IterableChain<T> = Chain<T> & { | ||
value: Iterable<T>; | ||
}; | ||
export declare type ValueChain<T> = Chain<T> & { | ||
export type ValueChain<T> = Chain<T> & { | ||
value: T; | ||
}; | ||
export declare type NotIterable<T> = T extends Iterable<unknown> ? never : T; | ||
export declare type Iter<T> = T extends Iterable<infer E> ? Iterable<E> : Iterable<T>; | ||
export declare type Chain<T> = { | ||
export type NotIterable<T> = T extends Iterable<unknown> ? never : T; | ||
export type Iter<T> = T extends Iterable<infer E> ? Iterable<E> : Iterable<T>; | ||
export type Chain<T> = { | ||
last: () => ValueChain<T>; | ||
@@ -73,0 +73,0 @@ first: () => ValueChain<T>; |
import { at, concat, every, filter, find, first, flat, flatMap, forEach, includes, isEmpty, join, last, map, next, prev, reduce, size, skip, some, sort, unique, } from './iterables'; | ||
import { mapValues } from './objects'; | ||
export function chain(value) { | ||
const iterable = (value === undefined ? [] : value === null ? [null] : Symbol.iterator in value ? value : [value]); | ||
const iterable = (value === undefined | ||
? [] | ||
: value === null | ||
? [null] | ||
: typeof value === 'object' && Symbol.iterator in value | ||
? value | ||
: [value]); | ||
return iterable === value ? chainIter(iterable) : chainElement(value); | ||
@@ -6,0 +12,0 @@ } |
@@ -1,3 +0,3 @@ | ||
export declare type PromiseResolveCb<T> = (value: T | PromiseLike<T>) => void; | ||
export declare type PromiseRejectCb = (reason?: any) => void; | ||
export type PromiseResolveCb<T> = (value: T | PromiseLike<T>) => void; | ||
export type PromiseRejectCb = (reason?: any) => void; | ||
export interface IDeferredPromise<T> { | ||
@@ -4,0 +4,0 @@ promise: Promise<T>; |
import { Nullable } from './types'; | ||
export declare type Mapping<S, T> = (src: S) => T; | ||
export declare type Predicate<S, V = boolean> = (src: S) => V; | ||
export declare type Flat<T> = T extends Iterable<infer A> ? A : T; | ||
export type Mapping<S, T> = (src: S) => T; | ||
export type Predicate<S, V = boolean> = (src: S) => V; | ||
export type Flat<T> = T extends Iterable<infer A> ? A : T; | ||
/** | ||
@@ -6,0 +6,0 @@ * Picks the last element of an iterable |
@@ -15,4 +15,4 @@ import { Nullable } from './types'; | ||
export declare function has(obj: null | undefined, key: unknown | never): false; | ||
export declare type MapValue<T> = T extends Map<infer _, infer V> ? V : never; | ||
export declare type ObjValue<O extends object, K extends keyof O = keyof O> = O[K]; | ||
export type MapValue<T> = T extends Map<infer _, infer V> ? V : never; | ||
export type ObjValue<O extends object, K extends keyof O = keyof O> = O[K]; | ||
/** | ||
@@ -19,0 +19,0 @@ * Similar to Map.get, but works for plain objects, and returns undefined |
@@ -93,4 +93,4 @@ import type { UnionToIntersection } from './types'; | ||
declare const DELETE: unique symbol; | ||
export declare type Remap<T> = Partial<Record<keyof T, string | typeof DELETE>>; | ||
export declare type Remapped<T extends object, R> = UnionToIntersection<R extends Partial<Record<keyof T, string | typeof DELETE>> ? { | ||
export type Remap<T> = Partial<Record<keyof T, string | typeof DELETE>>; | ||
export type Remapped<T extends object, R> = UnionToIntersection<R extends Partial<Record<keyof T, string | typeof DELETE>> ? { | ||
[K in keyof T]: K extends keyof R ? R[K] extends string ? { | ||
@@ -102,3 +102,3 @@ [L in R[K]]: T[K]; | ||
}[keyof T] : never>; | ||
export declare type RemapFunc = { | ||
export type RemapFunc = { | ||
<T extends object, R extends Remap<T>>(obj: T, rename: R): Remapped<T, R>; | ||
@@ -105,0 +105,0 @@ readonly DELETE: typeof DELETE; |
/** | ||
* The resolved value of T (if a promise, otherwise simply T) | ||
*/ | ||
export declare type Awaited<T> = T extends PromiseLike<infer U> ? U : T; | ||
export type Awaited<T> = T extends PromiseLike<infer U> ? U : T; | ||
/** | ||
* T or null/undefined | ||
*/ | ||
export declare type Nullable<T> = T | null | undefined; | ||
export type Nullable<T> = T | null | undefined; | ||
/** | ||
@@ -37,3 +37,3 @@ * Validates s is an instance of Map | ||
*/ | ||
export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; | ||
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@wixc3/common", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Common utils, usable in all environments", | ||
@@ -23,6 +23,3 @@ "main": "dist/cjs/index.js", | ||
"@file-services/types": "^7.0.1" | ||
}, | ||
"devDependencies": { | ||
"@microsoft/api-documenter": "^7.19.22" | ||
} | ||
} |
@@ -93,3 +93,9 @@ import { | ||
const iterable = ( | ||
value === undefined ? [] : value === null ? [null] : Symbol.iterator in value ? value : [value] | ||
value === undefined | ||
? [] | ||
: value === null | ||
? [null] | ||
: typeof value === 'object' && Symbol.iterator in value | ||
? value | ||
: [value] | ||
) as Iter<T>; | ||
@@ -96,0 +102,0 @@ |
@@ -64,3 +64,3 @@ import { getIn } from './objects'; | ||
export const splitIntoWords = (str: string): string[] => { | ||
let words = str.match(/[a-z0-9]+/gi) ?? []; | ||
let words: string[] = str.match(/[a-z0-9]+/gi) ?? []; | ||
words = words.flatMap((w) => w.split(/(\d+)/g)); // Numbers | ||
@@ -92,3 +92,3 @@ words = words.flatMap((w) => w.split(/([A-Z]+)(?=[A-Z][a-z])/g)); // Acronyms | ||
* @example | ||
* @example | ||
* ```ts | ||
@@ -203,3 +203,3 @@ * toPascalCaseJsIdentifier("123helloWorld") // => "HelloWorld" | ||
* @param newline - | ||
* @returns | ||
* @returns | ||
*/ | ||
@@ -264,3 +264,3 @@ export function equalIdents(reference: string, modified: string, newline = '\n') { | ||
* @param value - | ||
* @returns | ||
* @returns | ||
*/ | ||
@@ -271,3 +271,3 @@ export const isString = (value: unknown): value is string => typeof value === 'string'; | ||
/** | ||
* Similar to templated string, | ||
* Similar to templated string, | ||
* given a fixed context object returns a function that parses strings in it | ||
@@ -274,0 +274,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
314094
0
5604