@jymfony/util
Advanced tools
Comparing version 0.1.0-alpha.19 to 0.1.0-alpha.20
@@ -8,3 +8,6 @@ require('./lib/Error/trigger_deprecated'); | ||
require('./lib/Array/values.polyfill'); | ||
require('./lib/Symbol/description.polyfill'); | ||
require('./lib/Iterator/EmptyIterator'); | ||
require('./lib/Iterator/RecursiveDirectoryIterator'); | ||
@@ -11,0 +14,0 @@ require('./lib/Object/polyfills/values'); |
@@ -8,3 +8,11 @@ if (! Symbol.asyncIterator) { | ||
const forAwait = (iterator, callback) => { | ||
if (isPromise(iterator)) { | ||
return iterator.then(resolved => forAwait(resolved, callback)); | ||
} | ||
const originalIterator = iterator; | ||
if (isArray(iterator)) { | ||
iterator = iterator.values(); | ||
} | ||
if (! iterator.next) { | ||
@@ -16,3 +24,3 @@ iterator = iterator[Symbol.asyncIterator] || iterator[Symbol.iterator]; | ||
throw new Error(Object.prototype.toString.call(originalIterator) + ' is not iterable'); | ||
} else if (isGeneratorFunction(iterator)) { | ||
} else if (! isFunction(iterator.next) && isFunction(iterator)) { | ||
iterator = iterator(); | ||
@@ -19,0 +27,0 @@ } |
@@ -62,2 +62,4 @@ global.isArray = Array.isArray; | ||
const objectPrototype = Object.getPrototypeOf({}); | ||
/** | ||
@@ -73,3 +75,10 @@ * @param {*} value | ||
return Object.getPrototypeOf(value) === Object.getPrototypeOf({}); | ||
let proto; | ||
try { | ||
proto = Object.getPrototypeOf(value); | ||
} catch (e) { | ||
return false; | ||
} | ||
return null === proto || proto === objectPrototype; | ||
}; | ||
@@ -76,0 +85,0 @@ |
@@ -90,3 +90,3 @@ const Mixins = require('./Mixins'); | ||
const mixins = o.constructor[Mixins.appliedInterfacesSymbol]; | ||
const mixins = o.constructor && o.constructor[Mixins.appliedInterfacesSymbol]; | ||
if (! mixins) { | ||
@@ -93,0 +93,0 @@ return false; |
@@ -56,2 +56,12 @@ 'use strict'; | ||
if ( | ||
value.constructor === HashTable || | ||
value.constructor === BTree || | ||
value.constructor === LinkedList || | ||
value.constructor === PriorityQueue | ||
) { | ||
return 'T[' + value.constructor.name + '](' + value.length + '):{' + | ||
value.toArray().map(serialize).join(';') + (value.length ? ';' : '') + '}'; | ||
} | ||
const reflClass = new ReflectionClass(value); | ||
@@ -149,2 +159,60 @@ if (! reflClass.name) { | ||
case 'T': { | ||
expect('['); | ||
const class_ = readUntil(']'); | ||
expect('('); | ||
length = readUntil(')'); | ||
expect(':'); | ||
expect('{'); | ||
const values = []; | ||
values.length = length; | ||
let idx = 0; | ||
while (idx < length) { | ||
values[idx++] = doUnserialize(); | ||
expect(';'); | ||
} | ||
expect('}'); | ||
let val; | ||
switch (class_) { | ||
case 'HashTable': | ||
val = new HashTable(); | ||
for (const [ key, value ] of values) { | ||
val.put(key, value); | ||
} | ||
return val; | ||
case 'LinkedList': | ||
val = new LinkedList(); | ||
for (const value of values) { | ||
val.push(value); | ||
} | ||
return val; | ||
case 'BTree': | ||
val = new BTree(); | ||
for (const [ key, value ] of values) { | ||
val.push(key, value); | ||
} | ||
return val; | ||
case 'PriorityQueue': | ||
val = new PriorityQueue(); | ||
for (const [ priority, value ] of values) { | ||
val.push(value, priority); | ||
} | ||
return val; | ||
} | ||
throw new Error('Invalid serialized value. Unknown structure class ' + class_); | ||
} | ||
case 'A': { | ||
@@ -151,0 +219,0 @@ expect('('); |
{ | ||
"name": "@jymfony/util", | ||
"version": "0.1.0-alpha.19", | ||
"version": "0.1.0-alpha.20", | ||
"description": "Jymfony util functions", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@jymfony/exceptions": "0.1.0-alpha.19" | ||
"@jymfony/exceptions": "0.1.0-alpha.20" | ||
}, | ||
@@ -23,0 +23,0 @@ "devDependencies": { |
@@ -286,2 +286,3 @@ /// <reference lib="esnext" /> | ||
EmptyIterator: Newable<EmptyIterator>; | ||
RecursiveDirectoryIterator: Newable<RecursiveDirectoryIterator>; | ||
@@ -372,6 +373,2 @@ getInterface<T extends Newable<any> = any>(definition: T): T & MixinInterface; | ||
interface Function { | ||
(...args: any[]): any; | ||
} | ||
declare type Invokable<T = any> = (...args: any[]) => T | { | ||
@@ -453,3 +450,3 @@ __invoke<A extends any[]>(...args: A): (...args: A) => T; | ||
declare class BoundFunction implements Function { | ||
declare interface BoundFunction extends Function { | ||
new(thisArg: Object, func: Invokable|Function|GeneratorFunction): Function; | ||
@@ -477,1 +474,23 @@ | ||
} | ||
declare class RecursiveDirectoryIterator implements Iterator<string>, Iterable<string> { | ||
private _path: string; | ||
private _dir: undefined|string[]; | ||
private _current: undefined|string; | ||
/** | ||
* Constructor. | ||
*/ | ||
__construct(filepath: string): void; | ||
constructor(filepath: string); | ||
/** | ||
* Make this object iterable. | ||
*/ | ||
[Symbol.iterator](): RecursiveDirectoryIterator; | ||
/** | ||
* Iterates over values. | ||
*/ | ||
next(): IteratorResult<string>; | ||
} |
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
140582
66
4110
4
+ Added@jymfony/exceptions@0.1.0-alpha.20(transitive)
- Removed@jymfony/exceptions@0.1.0-alpha.19(transitive)