add() — fastify Function Reference
Architecture documentation for the add() function in content-type-parser.js from the fastify codebase.
Entity Profile
Dependency Diagram
graph TD 0263d1e1_98f0_1273_d326_dcda379097b2["add()"] b47c11f3_fe3b_64dc_0f58_921e5921ec45["content-type-parser.js"] 0263d1e1_98f0_1273_d326_dcda379097b2 -->|defined in| b47c11f3_fe3b_64dc_0f58_921e5921ec45 edbc058c_128e_1ef0_93ce_0bf3b13c664a["addContentTypeParser()"] edbc058c_128e_1ef0_93ce_0bf3b13c664a -->|calls| 0263d1e1_98f0_1273_d326_dcda379097b2 fd6a4182_e07c_13d6_27a1_5f504e3df02e["existingParser()"] 0263d1e1_98f0_1273_d326_dcda379097b2 -->|calls| fd6a4182_e07c_13d6_27a1_5f504e3df02e 0b4bab63_088f_d4fe_2577_c45d409a3deb["Parser()"] 0263d1e1_98f0_1273_d326_dcda379097b2 -->|calls| 0b4bab63_088f_d4fe_2577_c45d409a3deb 5735efa4_5eb9_ac60_1a38_e8b97b6a9ae2["validateRegExp()"] 0263d1e1_98f0_1273_d326_dcda379097b2 -->|calls| 5735efa4_5eb9_ac60_1a38_e8b97b6a9ae2 style 0263d1e1_98f0_1273_d326_dcda379097b2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
lib/content-type-parser.js lines 44–92
ContentTypeParser.prototype.add = function (contentType, opts, parserFn) {
const contentTypeIsString = typeof contentType === 'string'
if (contentTypeIsString) {
contentType = contentType.trim().toLowerCase()
if (contentType.length === 0) throw new FST_ERR_CTP_EMPTY_TYPE()
} else if (!(contentType instanceof RegExp)) {
throw new FST_ERR_CTP_INVALID_TYPE()
}
if (typeof parserFn !== 'function') {
throw new FST_ERR_CTP_INVALID_HANDLER()
}
if (this.existingParser(contentType)) {
throw new FST_ERR_CTP_ALREADY_PRESENT(contentType)
}
if (opts.parseAs !== undefined) {
if (opts.parseAs !== 'string' && opts.parseAs !== 'buffer') {
throw new FST_ERR_CTP_INVALID_PARSE_TYPE(opts.parseAs)
}
}
const parser = new Parser(
opts.parseAs === 'string',
opts.parseAs === 'buffer',
opts.bodyLimit,
parserFn
)
if (contentType === '*') {
this.customParsers.set('', parser)
} else {
if (contentTypeIsString) {
const ct = new ContentType(contentType)
if (ct.isValid === false) {
throw new FST_ERR_CTP_INVALID_TYPE()
}
const normalizedContentType = ct.toString()
this.parserList.unshift(normalizedContentType)
this.customParsers.set(normalizedContentType, parser)
} else {
validateRegExp(contentType)
this.parserRegExpList.unshift(contentType)
this.customParsers.set(contentType.toString(), parser)
}
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does add() do?
add() is a function in the fastify codebase, defined in lib/content-type-parser.js.
Where is add() defined?
add() is defined in lib/content-type-parser.js at line 44.
What does add() call?
add() calls 3 function(s): Parser, existingParser, validateRegExp.
What calls add()?
add() is called by 1 function(s): addContentTypeParser.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free