@tsdotnet/type
Advanced tools
Comparing version
@@ -217,9 +217,10 @@ /*! | ||
* Returns null if unable to convert to iterable. | ||
* @param {Iterable | ArrayLike} instance | ||
* @return {Iterable} | ||
* @param instance | ||
* @param {boolean} allowString | ||
* @return {Iterable<unknown> | null} | ||
*/ | ||
function asIterable(instance) { | ||
function asIterable(instance, allowString = false) { | ||
if (isIterable(instance)) | ||
return instance; | ||
if (isArrayLike(instance)) | ||
if ((allowString || typeof instance !== 'string') && isArrayLike(instance)) | ||
return { | ||
@@ -226,0 +227,0 @@ *[Symbol.iterator]() { |
@@ -222,15 +222,40 @@ /*! | ||
* Returns null if unable to convert to iterable. | ||
* @param {Iterable<T> | ArrayLike<T>} instance | ||
* @return {Iterable<T>} | ||
* @param {string} instance | ||
* @return {null} | ||
*/ | ||
export function asIterable<T>(instance: Iterable<T> | ArrayLike<T>): Iterable<T> | null; | ||
export function asIterable(instance: string): null; | ||
/** | ||
* Ensures an object is iterable if possible. | ||
* Returns null if unable to convert to iterable. | ||
* @param {string} instance | ||
* @param {false} allowString | ||
* @return {null} | ||
*/ | ||
export function asIterable(instance: string, allowString: false): null; | ||
/** | ||
* Ensures an object is iterable if possible. | ||
* Returns null if unable to convert to iterable. | ||
* @param {string} instance | ||
* @param {true} allowString | ||
* @return {string} | ||
*/ | ||
export function asIterable(instance: string, allowString: true): string; | ||
/** | ||
* Ensures an object is iterable if possible. | ||
* Returns null if unable to convert to iterable. | ||
* @param {Iterable<T> | ArrayLike<T>} instance | ||
* @return {Iterable<T>} | ||
* @param {boolean} allowString | ||
* @return {Iterable<T> | null} | ||
*/ | ||
export function asIterable<T = unknown>(instance: unknown): Iterable<T> | null; | ||
export function asIterable<T>(instance: Iterable<T> | ArrayLike<T>, allowString?: boolean): Iterable<T> | null; | ||
/** | ||
* Ensures an object is iterable if possible. | ||
* Returns null if unable to convert to iterable. | ||
* @param instance | ||
* @param {boolean} allowString | ||
* @return {Iterable<T> | null} | ||
*/ | ||
export function asIterable<T = unknown>(instance: unknown, allowString?: boolean): Iterable<T> | null; | ||
export {}; | ||
} | ||
export default type; |
@@ -220,9 +220,10 @@ "use strict"; | ||
* Returns null if unable to convert to iterable. | ||
* @param {Iterable | ArrayLike} instance | ||
* @return {Iterable} | ||
* @param instance | ||
* @param {boolean} allowString | ||
* @return {Iterable<unknown> | null} | ||
*/ | ||
function asIterable(instance) { | ||
function asIterable(instance, allowString = false) { | ||
if (isIterable(instance)) | ||
return instance; | ||
if (isArrayLike(instance)) | ||
if ((allowString || typeof instance !== 'string') && isArrayLike(instance)) | ||
return { | ||
@@ -229,0 +230,0 @@ *[Symbol.iterator]() { |
{ | ||
"name": "@tsdotnet/type", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "A set of useful utility functions for JavaScript run-time type checking and inspection.", | ||
@@ -5,0 +5,0 @@ "author": "electricessence", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37484
3.4%747
3.75%