Beispiel #1
0
const kept = function kept( path, mode, synchronous ){
	/*;
		@meta-configuration:
			{
				"path:require": "string",
				"mode": "string"
				"synchronous": "boolean"
			}
		@end-meta-configuration
	*/

	if( falzy( path ) || typeof path != "string" ){
		throw new Error( "invalid path" );
	}

	let parameter = raze( arguments );

	mode = depher( parameter, [ EXIST, READ, WRITE, EXECUTE ], EXIST );

	let type = fs.constants? fs.constants : fs;
	if( mode == READ ){
		mode = type.R_OK;

	}else if( mode == WRITE ){
		mode = type.W_OK;

	}else if( mode == EXECUTE ){
		mode = type.X_OK;

	}else if( mode == EXIST ){
		mode = type.F_OK;
	}

	synchronous = depher( parameter, BOOLEAN, false );

	if( synchronous ){
		try{
			fs.accessSync( path, mode );

		}catch( error ){
			return false;
		}

		return true;

	}else{
		return letgo.bind( zelf( this ) )( function later( callback ){
			fs.access( path, mode, function done( error ){
				if( error instanceof Error ){
					callback( error, false );

				}else{
					callback( null, true );
				}
			} );
		} );
	}
};
	child.prototype.initialize = function initialize() {var _this = this;
		var parameter = raze(arguments);

		return initializer.reduce(function (result, initialize) {
			try {
				return initialize.apply(_this, parameter);

			} catch (error) {
				throw new Error("failed initialize, " + initialize[BLUEPRINT] + ", " + error.stack);
			}
		}, this);
	};
Beispiel #3
0
	child.prototype.initialize = function initialize( ){
		let parameter = raze( arguments );

		return initializer.reduce( ( result, initialize ) => {
			try{
				return initialize.apply( this, parameter );

			}catch( error ){
				throw new Error( `failed initialize, ${ initialize[ BLUEPRINT ] }, ${ error.stack }` )
			}
		}, this );
	};
Beispiel #4
0
const outre = function outre( array, indexer ){
	/*;
		@meta-configuration:
			{
				"array:required": Array,
				"indexer": "function"
			}
		@end-meta-configuration
	*/

	indexer = indexer || ( ( array, element ) => array.indexOf( element ) );

	if( typeof indexer != "function" ){
		throw new Error( "invalid indexer" );
	}

	return raze( array ).filter( ( element, index, array ) => ( indexer( array, element ) === index ) );
};
var decrease = function decrease(array, method, value) {
	/*;
                                                        	@meta-configuration:
                                                        		{
                                                        			"array:required": Array,
                                                        			"method": "function",
                                                        			"value": "*"
                                                        		}
                                                        	@end-meta-configuration
                                                        */

	if (falzy(array) || !doubt(array, AS_ARRAY)) {
		array = [];

	} else {
		array = raze(array);
	}

	if (falzy(method) || typeof method != "function") {
		method = function reduce(accumulator, current, index, array) {
			if (index == array.length - 1) {
				array.pop();

				return array;
			}

			return current;
		};
	}

	if (falzy(value)) {
		value = array[0];
	}

	value = array.reduce(method, value);

	if (!doubt(value, ARRAY)) {
		value = [value];
	}

	return value.filter(truly);
};
var plough = function plough(array) {
	/*;
                                     	@meta-configuration:
                                     		{
                                     			"array:required": [
                                     				"[*]",
                                     				"..."
                                     			]
                                     		}
                                     	@end-meta-configuration
                                     */

	array = raze(arguments);

	if (arid(array)) {
		return array;
	}

	return decrease(array, function flatten(previous, current) {
		var element = doubt(current, AS_ARRAY) ? plough.apply(null, current) : current;

		return previous.concat(element);
	}, []);
};
Beispiel #7
0
	var delegate = function delegate(option, callback) {
		var parameter = raze(arguments);

		/*;
                                   	@note:
                                   		Do not execute if the first parameter is not an object
                                   			and if the first parameter is not an object then it should
                                   			not be in chain mode.
                                   	@end-note
                                   */
		if (!protype(parameter[0], OBJECT) && (
		falzy(this.option) ||
		!clazof(this.option, "Option") ||
		!this.chained()))
		{
			return this;
		}

		option = depher(parameter, OBJECT, this.option);
		var self = option.self || this;

		self.option = self.option || option;
		self.option = glucose.bind(self)(self.option);

		option = glucose.bind(self)(option);

		self.option.mix(option);

		callback = optfor(parameter, FUNCTION);
		callback = called.bind(self)(callback);

		if (self.chained()) {
			if (truly(self[CHAIN_HANDLER])) {
				self[CHAIN_HANDLER].halt();
			}

			if (falzy(self[CALL_STACK])) {
				harden(CALL_STACK, [], self);
			}

			self[CALL_STACK].push({
				"option": option,
				"self": self,
				"method": method,
				"callback": callback });


			self[CHAIN_HANDLER] = snapd.bind(self)(
			function chain() {
				/*;
                     	@todo:
                     		We will drop usage to any async methods from third party modules.
                     	@end-todo
                     */
				series(this[CALL_STACK].
				map(function onEachCall(call, index) {
					/*;
                                          	@note:
                                          		The first call to the chained method will transfer
                                          			the properties to the main option.
                                          	@end-note
                                          */
					if (index === 0) {
						call.option.transfer(this.option);
					}

					return function delegate(tellback) {
						var done = called.bind(this)(
						function done(issue, result, option) {
							call.handler.halt();

							option = glucose.bind(this)(option);

							option.result = result;

							call.callback(issue, result, option);

							/*;
                                             	@note:
                                             		This should be called after the callback.
                                             	@end-note
                                             */
							this.option.mix(option);
							this.option.result = option.result;

							tellback(issue, result);
						});

						call.handler = snapd.bind(this)(
						function fallback() {
							done(new Error("failed to call callback"));
						}, 1000 * 5);

						/*;
                    	@note:
                    		Succeeding calls must communicate through cache and result.
                    	@end-note
                    */
						call.option.mix(this.option);
						call.option.result = this.option.result;

						var option = call.option.empty() ? this.option : call.option;

						call.method.bind(this)(option, done);
					}.bind(this);
				}.bind(this)),

				function lastly(issue, resultList) {
					/*;
                                        	@note:
                                        		This will get the last callback from the chain.
                                        	@end-note
                                        */
					var callback = this[CALL_STACK].reverse()[0].callback;

					var result = resultList.pop();

					callback(issue, result, this.option);

					if (protype(this.emit, FUNCTION)) {
						this.emit("done", issue, result, this.option);
					}

					while (this[CALL_STACK].length) {
						var call = this[CALL_STACK].pop();

						if (truu(call)) {
							call.handler.halt();
						}
					}

					this[CHAIN_HANDLER].halt();
					this.release();

					snapd.bind(this)(this.option.clear, 1000 * 1);
				}.bind(this));
			});

		} else {
			snapd.bind(this)(this.option.clear, 1000 * 1);

			return method.bind(self)(
			option.empty() ? self.option : option, called.bind(self)(
			function onResult(issue, result, option) {
				option.result = result;

				this.option.mix(option);
				this.option.transfer(option);

				callback(issue, result, option);
			}));
		}

		return self;
	};