MCPcopy Index your code
hub / github.com/SchemaStore/schemastore / assertFileHasNoBom

Function assertFileHasNoBom

cli.js:1682–1704  ·  view source on GitHub ↗
(/** @type {DataFile} */ file)

Source from the content-addressed store, hash-verified

1680}
1681
1682function assertFileHasNoBom(/** @type {DataFile} */ file) {
1683 const bomTypes = [
1684 { name: 'UTF-8', signature: [0xef, 0xbb, 0xbf] },
1685 { name: 'UTF-16 (BE)', signature: [0xfe, 0xff] },
1686 { name: 'UTF-16 (LE)', signature: [0xff, 0xfe] },
1687 { name: 'UTF-32 (BE)', signature: [0x00, 0x00, 0xff, 0xfe] },
1688 { name: 'UTF-32 (LE)', signature: [0xff, 0xfe, 0x00, 0x00] },
1689 ]
1690
1691 for (const bom of bomTypes) {
1692 if (file.buffer.length >= bom.signature.length) {
1693 const bomFound = bom.signature.every(
1694 (value, index) => file.buffer[index] === value,
1695 )
1696
1697 if (bomFound) {
1698 printErrorAndExit(new Error(), [
1699 `Expected to have no BOM (${bom.name} BOM) in file "./${file.path}"`,
1700 ])
1701 }
1702 }
1703 }
1704}
1705
1706async function assertFilePassesJsonLint(
1707 /** @type {DataFile} */ file,

Callers 3

onSchemaFileFunction · 0.85
onPositiveTestFileFunction · 0.85
onNegativeTestFileFunction · 0.85

Calls 1

printErrorAndExitFunction · 0.85

Tested by

no test coverage detected