How to use from - 10 common examples

To help you get started, we’ve selected a few from examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fatcerberus / miniSphere / assets / system / game_modules / console.js View on Github external
function executeCommand(console, command)
{
	// tokenize the command string
	let tokens = command.match(/'.*?'|".*?"|\S+/g);
	if (tokens == null)
		return;
	for (let i = 0; i < tokens.length; ++i) {
		tokens[i] = tokens[i].replace(/'(.*)'/, "$1");
		tokens[i] = tokens[i].replace(/"(.*)"/, "$1");
	}
	let objectName = tokens[0];
	let instruction = tokens[1];

	// check that the instruction is valid
	if (!from.Array(console.commands)
		.any(it => it.entity == objectName))
	{
		console.log(`unrecognized object name '${objectName}'`);
		return;
	}
	if (tokens.length < 2) {
		console.log(`missing instruction for '${objectName}'`);
		return;
	}
	if (!from.Array(console.commands)
		.where(it => it.entity == objectName)
		.any(it => it.instruction == instruction))
	{
		console.log(`instruction '${instruction}' not valid for '${objectName}'`);
		return;
	}
github fatcerberus / miniSphere / assets / system / game_modules / joypad.js View on Github external
*  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
**/

'use strict';
const from = require('from');

// historically, Sphere requires a gamepad with at least 2 axes (X/Y) and
// 5 buttons (A, B, X, Y, Start) for full operation.
const Devices = from.Array(Joystick.getDevices())
	.where(it => it.numAxes >= 2)
	.where(it => it.numButtons >= 5)
	.toArray();

class Joypad
{
	constructor()
	{
		throw new TypeError(`'${new.target.name}' is a static class and cannot be instantiated`);
	}

	static get P1() { return Devices[0] || Joystick.Null; }
	static get P2() { return Devices[1] || Joystick.Null; }
	static get P3() { return Devices[2] || Joystick.Null; }
	static get P4() { return Devices[3] || Joystick.Null; }
}
github fatcerberus / miniSphere / assets / system / modules / console.js View on Github external
}
	var entity = tokens[0];
	var instruction = tokens[1];

	// check that the instruction is valid
	if (!from.Array(commands)
		.any(function(c) { return entity == c.entity; }))
	{
		log("unrecognized object name '" + entity + "'");
		return;
	}
	if (tokens.length < 2) {
		log("missing instruction for '" + entity + "'");
		return;
	}
	if (!from.Array(commands)
		.where(function(c) { return entity == c.entity; })
		.any(function(c) { return instruction == c.instruction; }))
	{
		log("instruction '" + instruction + "' not valid for '" + entity + "'");
		return;
	}

	// parse arguments
	for (var i = 2; i < tokens.length; ++i) {
		var maybeNumber = parseFloat(tokens[i]);
		tokens[i] = !isNaN(maybeNumber) ? maybeNumber : tokens[i];
	}

	// execute the command
	from.Array(commands)
		.where(function(c) { return entity == c.entity; })
github microsoft / Industry-Accelerator-FinancialServices / CDS.solutions / FinancialServicesCore / Extracts / Base / Controls / HIPOCanadaCC.HierarchyControl / HIPOCanadaCC.Hierarchy.js View on Github external
coveredEntities = [this.HierarchyControl.EntityId];
                            return [4 /*yield*/, here.getFamilyConnections(here.HierarchyControl.EntityId, 0, coveredEntities)];
                        case 1:
                            results = _b.sent();
                            for (_i = 0, _a = results.entities; _i < _a.length; _i++) {
                                entity = _a[_i];
                                he = this.parseJSONResponse(entity);
                                if (self_node.Line1 === undefined) {
                                    self_node.Line1 = entity["from.fullname"];
                                }
                                if (entity._record2roleid_value === ConnectionRole.Parent.toLowerCase() || entity._record1roleid_value === ConnectionRole.Child.toLowerCase()) {
                                    self_node.HierarchyParentEntityId = entity["to.contactid"];
                                    // TODO: Replace placeholder with parent label
                                    he.Line2 = "Parent";
                                }
                                if (entity["from.contactid"] === this.HierarchyControl.EntityId && self_node.ImgUrl === undefined) {
                                    self_node.ImgUrl = entity["from.entityimage"] !== undefined ? "data:image/png;base64," + entity["from.entityimage"] : "";
                                }
                                hierarchyElements.push(he);
                            }
                            hierarchyElements.push(self_node);
                            this.HierarchyElements = hierarchyElements;
                            return [2 /*return*/, 0];
                    }
                });
            });
github microsoft / Industry-Accelerator-FinancialServices / CDS.solutions / FinancialServicesCore / Extracts / Base / Controls / HIPOCanadaCC.HierarchyControl / HIPOCanadaCC.Hierarchy.js View on Github external
return [4 /*yield*/, here.getFamilyConnections(here.HierarchyControl.EntityId, 0, coveredEntities)];
                        case 1:
                            results = _b.sent();
                            for (_i = 0, _a = results.entities; _i < _a.length; _i++) {
                                entity = _a[_i];
                                he = this.parseJSONResponse(entity);
                                if (self_node.Line1 === undefined) {
                                    self_node.Line1 = entity["from.fullname"];
                                }
                                if (entity._record2roleid_value === ConnectionRole.Parent.toLowerCase() || entity._record1roleid_value === ConnectionRole.Child.toLowerCase()) {
                                    self_node.HierarchyParentEntityId = entity["to.contactid"];
                                    // TODO: Replace placeholder with parent label
                                    he.Line2 = "Parent";
                                }
                                if (entity["from.contactid"] === this.HierarchyControl.EntityId && self_node.ImgUrl === undefined) {
                                    self_node.ImgUrl = entity["from.entityimage"] !== undefined ? "data:image/png;base64," + entity["from.entityimage"] : "";
                                }
                                hierarchyElements.push(he);
                            }
                            hierarchyElements.push(self_node);
                            this.HierarchyElements = hierarchyElements;
                            return [2 /*return*/, 0];
                    }
                });
            });
github microsoft / Industry-Accelerator-FinancialServices / CDS.solutions / FinancialServicesCore / Extracts / Base / Controls / HIPOCanadaCC.HierarchyControl / HIPOCanadaCC.Hierarchy.js View on Github external
return __generator(this, function (_b) {
                    switch (_b.label) {
                        case 0:
                            here = this;
                            hierarchyElements = [];
                            self_node = new HierarchyNode();
                            self_node.HierarchyEntityId = this.HierarchyControl.EntityId;
                            coveredEntities = [this.HierarchyControl.EntityId];
                            return [4 /*yield*/, here.getFamilyConnections(here.HierarchyControl.EntityId, 0, coveredEntities)];
                        case 1:
                            results = _b.sent();
                            for (_i = 0, _a = results.entities; _i < _a.length; _i++) {
                                entity = _a[_i];
                                he = this.parseJSONResponse(entity);
                                if (self_node.Line1 === undefined) {
                                    self_node.Line1 = entity["from.fullname"];
                                }
                                if (entity._record2roleid_value === ConnectionRole.Parent.toLowerCase() || entity._record1roleid_value === ConnectionRole.Child.toLowerCase()) {
                                    self_node.HierarchyParentEntityId = entity["to.contactid"];
                                    // TODO: Replace placeholder with parent label
                                    he.Line2 = "Parent";
                                }
                                if (entity["from.contactid"] === this.HierarchyControl.EntityId && self_node.ImgUrl === undefined) {
                                    self_node.ImgUrl = entity["from.entityimage"] !== undefined ? "data:image/png;base64," + entity["from.entityimage"] : "";
                                }
                                hierarchyElements.push(he);
                            }
                            hierarchyElements.push(self_node);
                            this.HierarchyElements = hierarchyElements;
                            return [2 /*return*/, 0];
                    }
                });
github pivotal-cf / pivotal-ui / library / src / pivotal-ui-react / autocomplete / autocomplete.js View on Github external
return new Promise(resolve => {
    let trie;
    from(function (count, callback) {
      if (searchableItems && count >= searchableItems.length) this.emit('end');
      this.emit('data', searchableItems[count]);
      callback();
    }).pipe(through(value => {
      if (typeof value === 'object') {
        if (!trie) trie = new TrieSearch(null, trieOptions);
        trie.addFromObject(value);
        resolve(trie);
        return;
      }
      if (!trie) trie = new TrieSearch('value', trieOptions);
      trie.add({value});
      resolve(trie);
    }));
  });
};
github pivotal-cf / pivotal-ui / src / react / autocomplete / autocomplete.js View on Github external
return new Promise(resolve => {
    let trie;
    from(function (count, callback) {
      if (searchableItems && count >= searchableItems.length) this.emit('end');
      this.emit('data', searchableItems[count]);
      callback();
    }).pipe(through(value => {
      if (typeof value === 'object') {
        if (!trie) trie = new TrieSearch(null, trieOptions);
        trie.addFromObject(value);
        resolve(trie);
        return;
      }
      if (!trie) trie = new TrieSearch('value', trieOptions);
      trie.add({value});
      resolve(trie);
    }));
  });
};
github fatcerberus / miniSphere / assets / system / game_modules / scene.js View on Github external
function stop()
	{
		from.Array(tasks).each(function(tid) {
			Thread.kill(tid);
		});
	};
github fatcerberus / miniSphere / assets / system / runtime / dataWriter.js View on Github external
'uint8', 'uint16be', 'uint16le', 'uint32be', 'uint32le',
		'fstring', 'lstr8', 'lstr16be', 'lstr16le', 'lstr32be', 'lstr32le',
		'bool', 'raw',
	];
	const Attributes = {
		'fstring': [ 'length' ],
		'raw':     [ 'size' ],
	};

	for (const key of Object.keys(desc)) {
		let fieldDesc = desc[key];
		let fieldType = fieldDesc.type;
		if (!from.Array(FieldTypes).any(it => it === fieldType))
			throw new TypeError(`invalid field type '${fieldType}'`);
		if (fieldType in Attributes) {
			let haveAttributes = from.Array(Attributes[fieldType])
				.all(it => it in fieldDesc);
			if (!haveAttributes)
				throw new TypeError(`missing attributes for '${fieldType}'`);
		}
	}
}

from

Easy way to make a Readable Stream

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis