index.js
function parseTagged(definition, taggedTypes) {
	let match = definition.match(/^(\w+)(?:\((.*)\))?$/),
		tag, args, typeInfo
	if (!match) {
		return
	}

	// Get type info
	tag = match[1]
	typeInfo = taggedTypes[tag]
	if (!typeInfo) {
		return
	}

	// Special no-'()' case: only match 'tag' if minArgs is zero
	if (typeInfo.minArgs > 0 && match[2] === undefined) {
		return
	}

	// Parse and check args
	args = (match[2] || '').trim().split(/\s*,\s*/)
	if (args.length === 1 && args[0] === '') {
		// Especial empty case
		args = []
	}
	args = args.map((arg, i) => {
		if (!arg) {
			if (!typeInfo.sparse) {
				throw new Error('Missing argument at position ' + i + ' for tagged type ' + tag)
			}
			return
		}

		if (typeInfo.numeric) {
			arg = Number(arg)
			if (isNaN(arg)) {
				throw new Error('Invalid numeric argument at position ' + i + ' for tagged type ' + tag)
			}
		}

		return arg
	})
	args.original = definition
	if (args.length < typeInfo.minArgs) {
		throw new Error('Too few arguments for tagged type ' + tag)
	} else if (typeInfo.maxArgs && args.length > typeInfo.maxArgs) {
		throw new Error('Too many arguments for tagged type ' + tag)
	}

	return new Field(typeInfo.type, typeInfo.parseArgs ? typeInfo.parseArgs(args) : args)
}
function parseTagged(definition, taggedTypes) {
	let match = definition.match(/^(\w+)(?:\((.*)\))?$/),
		tag, args, typeInfo
	if (!match) {
		return
	}

	// Get type info
	tag = match[1]
	typeInfo = taggedTypes[tag]
	if (!typeInfo) {
		return
	}

	// Special no-'()' case: only match 'tag' if minArgs is zero
	if (typeInfo.minArgs > 0 && match[2] === undefined) {
		return
	}

	// Parse and check args
	args = (match[2] || '').trim().split(/\s*,\s*/)
	if (args.length === 1 && args[0] === '') {
		// Especial empty case
		args = []
	}
	args = args.map((arg, i) => {
		if (!arg) {
			if (!typeInfo.sparse) {
				throw new Error('Missing argument at position ' + i + ' for tagged type ' + tag)
			}
			return
		}

		if (typeInfo.numeric) {
			arg = Number(arg)
			if (isNaN(arg)) {
				throw new Error('Invalid numeric argument at position ' + i + ' for tagged type ' + tag)
			}
		}

		return arg
	})
	args.original = definition
	if (args.length < typeInfo.minArgs) {
		throw new Error('Too few arguments for tagged type ' + tag)
	} else if (typeInfo.maxArgs && args.length > typeInfo.maxArgs) {
		throw new Error('Too many arguments for tagged type ' + tag)
	}

	return new Field(typeInfo.type, typeInfo.parseArgs ? typeInfo.parseArgs(args) : args)
}
function parseTagged ( definition , taggedTypes ) { let match = definition . match ( / ^(\w+)(?:\((.*)\))?$ / ) , tag , args , typeInfo if ( ! match ) { return } // Get type info tag = match [ 1 ] typeInfo = taggedTypes [ tag ] if ( ! typeInfo ) { return } // Special no-'()' case: only match 'tag' if minArgs is zero if ( typeInfo . minArgs > 0 && match [ 2 ] === undefined ) { return } // Parse and check args args = ( match [ 2 ] || '' ) . trim ( ) . split ( / \s*,\s* / ) if ( args . length === 1 && args [ 0 ] === '' ) { // Especial empty case args = [ ] } args = args . map ( ( arg , i ) => { if ( ! arg ) { if ( ! typeInfo . sparse ) { throw new Error ( 'Missing argument at position ' + i + ' for tagged type ' + tag ) } return } if ( typeInfo . numeric ) { arg = Number ( arg ) if ( isNaN ( arg ) ) { throw new Error ( 'Invalid numeric argument at position ' + i + ' for tagged type ' + tag ) } } return arg } ) args . original = definition if ( args . length < typeInfo . minArgs ) { throw new Error ( 'Too few arguments for tagged type ' + tag ) } else if ( typeInfo . maxArgs && args . length > typeInfo . maxArgs ) { throw new Error ( 'Too many arguments for tagged type ' + tag ) } return new Field ( typeInfo . type , typeInfo . parseArgs ? typeInfo . parseArgs ( args ) : args ) }
Try to parse a string definition as a tagged type
@private
@param {string} definition
@param {Object<String, Object>} taggedTypes
@returns {?Field}
Try to parse a string definition as a tagged type