UNPKG

@dev-build-deploy/reuse-it

Version:

(ReUSE) Copyright and License management library

58 lines (57 loc) 1.68 kB
"use strict"; /* SPDX-FileCopyrightText: 2023 Kevin de Jong <monkaii@hotmail.com> SPDX-License-Identifier: MIT */ Object.defineProperty(exports, "__esModule", { value: true }); exports.extractData = void 0; /** * Supported SPDX File tokens * @internal */ const SPDXTokens = { copyright: "SPDX-FileCopyrightText:", license: "SPDX-License-Identifier:", attributionText: "SPDX-FileAttributionText:", comment: "SPDX-FileComment:", contributor: "SPDX-FileContributor:", licenseComments: "SPDX-LicenseComments:", licenseConcluded: "SPDX-LicenseConcluded:", licenseInfoInFile: "SPDX-LicenseInfoInFile:", notice: "SPDX-FileNotice:", type: "SPDX-FileType:", ignore: "REUSE-Ignore", }; /** * Generates a token from the provided line * @param line The line to generate a token from * @returns The generated token */ function generateToken(line) { const tokenKeys = Object.keys(SPDXTokens); for (const key of tokenKeys) { const match = new RegExp(`${SPDXTokens[key]}`, "i").exec(line); if (match === null) { continue; } return { start: match.index, end: line.indexOf(SPDXTokens[key]) + SPDXTokens[key].length, type: key, }; } } /** * Extracts the data from the provided comment * @param comment The comment to extract the data from * @internal */ function* extractData(comment) { for (const line of comment.contents) { const match = generateToken(line.value); if (match) { yield { type: match.type, data: line.value.substring(match.end).trim() }; } } } exports.extractData = extractData;