diff options
| author | 迷渡 <justjavac@gmail.com> | 2019-06-14 23:46:07 +0800 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-14 08:46:07 -0700 |
| commit | 52448f351d7b0882ac67e2974b93c1e730f5dbb3 (patch) | |
| tree | 57a67c325eae79b63d395dbea325959baec0ae2f /js/util.ts | |
| parent | dc60fe9f300043f191286ef804a365e16e455f87 (diff) | |
feat: URLSearchParams should work with custom iterator (#2512)
Diffstat (limited to 'js/util.ts')
| -rw-r--r-- | js/util.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/js/util.ts b/js/util.ts index a035d761a..da56465a2 100644 --- a/js/util.ts +++ b/js/util.ts @@ -122,6 +122,19 @@ export function isObject(o: unknown): o is object { return o != null && typeof o === "object"; } +// Returns whether o is iterable. +export function isIterable<T, P extends keyof T, K extends T[P]>( + o: T +): o is T & Iterable<[P, K]> { + // checks for null and undefined + if (o == null) { + return false; + } + return ( + typeof ((o as unknown) as Iterable<[P, K]>)[Symbol.iterator] === "function" + ); +} + // @internal export function requiredArguments( name: string, |
