How to use typechecker - 10 common examples

To help you get started, we’ve selected a few typechecker 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 bevry / boundation / source / package.js View on Github external
const result = arrangekeys(
				edition,
				'description directory entry tags engines'
			)
			if (result.tags) result.tags = Array.from(result.tags.values())
			return result
		})
	} else {
		delete packageData.editions
	}

	// trim empty keys
	for (const key in packageData) {
		if (packageData.hasOwnProperty(key)) {
			const value = packageData[key]
			if (typeChecker.isArray(value) && typeChecker.isEmptyArray(value)) {
				console.log(`trim: array: package.json:${key}`)
				delete packageData[key]
			} else if (
				typeChecker.isPlainObject(value) &&
				typeChecker.isEmptyPlainObject(value)
			) {
				console.log(`trim: empty: package.json:${key}`)
				delete packageData[key]
			} else if (value == null || value === '') {
				console.log(`trim: null|'': package.json:${key}`)
				delete packageData[key]
			}
		}
	}

	// ---------------------------------
github bevry-archive / feedr / source / index.js View on Github external
// Check deprecations
		if (feed.checkReponse) {
			next(new Error('Feed checkResponse option is deprecated for check'))
			return this
		}

		// Ensure optional
		feed = this.prepareFeed(feed)

		// Plugins
		const plugins = {}
		if (typeChecker.isString(feed.plugins)) {
			feed.plugins = feed.plugins.split(' ')
		}
		if (typeChecker.isArray(feed.plugins)) {
			for (let i = 0; i < feed.plugins.length; ++i) {
				const name = feed.plugins[i]
				try {
					plugins[name] = require('./plugins/' + name)
				} catch (err) {
					next(err)
					return this
				}
			}
		}

		// Generators
		function generateParser(name, method, opts, complete) {
			me.log('debug', `Feedr parse [${feed.url}] with ${name} attempt`)
			method(opts, function(err, data) {
				if (err) {
github bevry-archive / feedr / source / index.js View on Github external
next(new Error('Feed url was not supplied'))
			return this
		}

		// Check deprecations
		if (feed.checkReponse) {
			next(new Error('Feed checkResponse option is deprecated for check'))
			return this
		}

		// Ensure optional
		feed = this.prepareFeed(feed)

		// Plugins
		const plugins = {}
		if (typeChecker.isString(feed.plugins)) {
			feed.plugins = feed.plugins.split(' ')
		}
		if (typeChecker.isArray(feed.plugins)) {
			for (let i = 0; i < feed.plugins.length; ++i) {
				const name = feed.plugins[i]
				try {
					plugins[name] = require('./plugins/' + name)
				} catch (err) {
					next(err)
					return this
				}
			}
		}

		// Generators
		function generateParser(name, method, opts, complete) {
github bevry / boundation / source / package.js View on Github external
if (result.tags) result.tags = Array.from(result.tags.values())
			return result
		})
	} else {
		delete packageData.editions
	}

	// trim empty keys
	for (const key in packageData) {
		if (packageData.hasOwnProperty(key)) {
			const value = packageData[key]
			if (typeChecker.isArray(value) && typeChecker.isEmptyArray(value)) {
				console.log(`trim: array: package.json:${key}`)
				delete packageData[key]
			} else if (
				typeChecker.isPlainObject(value) &&
				typeChecker.isEmptyPlainObject(value)
			) {
				console.log(`trim: empty: package.json:${key}`)
				delete packageData[key]
			} else if (value == null || value === '') {
				console.log(`trim: null|'': package.json:${key}`)
				delete packageData[key]
			}
		}
	}

	// ---------------------------------
	// Badges

	// set travisTLD if it is com
	// we don't set it explicity to org
github bevry / boundation / source / package.js View on Github external
return result
		})
	} else {
		delete packageData.editions
	}

	// trim empty keys
	for (const key in packageData) {
		if (packageData.hasOwnProperty(key)) {
			const value = packageData[key]
			if (typeChecker.isArray(value) && typeChecker.isEmptyArray(value)) {
				console.log(`trim: array: package.json:${key}`)
				delete packageData[key]
			} else if (
				typeChecker.isPlainObject(value) &&
				typeChecker.isEmptyPlainObject(value)
			) {
				console.log(`trim: empty: package.json:${key}`)
				delete packageData[key]
			} else if (value == null || value === '') {
				console.log(`trim: null|'': package.json:${key}`)
				delete packageData[key]
			}
		}
	}

	// ---------------------------------
	// Badges

	// set travisTLD if it is com
	// we don't set it explicity to org
	// so that when the official migration happens, there will be no manual changes
github sx1989827 / DOClever / Desktop / node_modules / eachr / source / index.js View on Github external
module.exports = function eachr (subject, callback) {
	// Handle
	if ( typeChecker.isArray(subject) ) {
		for ( let key = 0; key < subject.length; ++key ) {
			const value = subject[key]
			if ( callback.call(subject, value, key, subject) === false ) {
				break
			}
		}
	}
	else if ( typeChecker.isPlainObject(subject) ) {
		for ( const key in subject ) {
			if ( subject.hasOwnProperty(key) ) {
				const value = subject[key]
				if ( callback.call(subject, value, key, subject) === false ) {
					break
				}
			}
		}
github sx1989827 / DOClever / Desktop / node_modules / eachr / es2015 / index.js View on Github external
module.exports = function eachr(subject, callback) {
	// Handle
	if (typeChecker.isArray(subject)) {
		for (var key = 0; key < subject.length; ++key) {
			var value = subject[key];
			if (callback.call(subject, value, key, subject) === false) {
				break;
			}
		}
	} else if (typeChecker.isPlainObject(subject)) {
		for (var _key in subject) {
			if (subject.hasOwnProperty(_key)) {
				var _value = subject[_key];
				if (callback.call(subject, _value, _key, subject) === false) {
					break;
				}
			}
		}
	} else if (typeChecker.isMap(subject)) {
github sx1989827 / DOClever / Desktop / node_modules / extract-opts / source / index.js View on Github external
module.exports = function (opts, next, config = {}) {
	// Empty, set default
	if ( config.completionCallbackNames == null ) {
		config.completionCallbackNames = ['next']
	}

	// Not array, make array
	else if ( typeChecker.isArray(config.completionCallbackNames) === false ) {
		config.completionCallbackNames = [config.completionCallbackNames]
	}

	// Arguments
	if ( typeChecker.isFunction(opts) && next == null ) {
		next = opts
		opts = {}
	}
	else if ( !opts ) {
		opts = {}
	}

	// Completion callback
	if ( !next ) {
		// Cycle the completionCallbackNames to check if the completion callback name exists in opts
		// if it does, then use it as the next and delete it's value
github sx1989827 / DOClever / Desktop / node_modules / extract-opts / es2015 / index.js View on Github external
module.exports = function (opts, next) {
	var config = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

	// Empty, set default
	if (config.completionCallbackNames == null) {
		config.completionCallbackNames = ['next'];
	}

	// Not array, make array
	else if (typeChecker.isArray(config.completionCallbackNames) === false) {
			config.completionCallbackNames = [config.completionCallbackNames];
		}

	// Arguments
	if (typeChecker.isFunction(opts) && next == null) {
		next = opts;
		opts = {};
	} else if (!opts) {
		opts = {};
	}

	// Completion callback
	if (!next) {
		// Cycle the completionCallbackNames to check if the completion callback name exists in opts
		// if it does, then use it as the next and delete it's value
		eachr(config.completionCallbackNames, function (completionCallbackName) {
github bevry / projectz / source / lib / projectz.js View on Github external
}

		// Validate keywords field
		if (isString(this.mergedPackageData.keywords)) {
			next(new Error('projectz: keywords field must be array instead of CSV'))
			return this
		}

		// Validate sponsors array
		if (this.mergedPackageData.sponsor) {
			next(
				new Error('projectz: sponsor field is deprecated, use sponsors field')
			)
			return this
		}
		if (isString(this.mergedPackageData.sponsors)) {
			next(new Error('projectz: sponsors field must be array instead of CSV'))
			return this
		}

		// Validate maintainers array
		if (this.mergedPackageData.maintainer) {
			next(
				new Error(
					'projectz: maintainer field is deprecated, use maintainers field'
				)
			)
			return this
		}
		if (isString(this.mergedPackageData.maintainers)) {
			next(
				new Error('projectz: maintainers field must be array instead of CSV')

typechecker

Utilities to get and check variable types (isString, isPlainObject, isRegExp, etc)

Artistic-2.0
Latest version published 7 months ago

Package Health Score

70 / 100
Full package analysis