1// @ts-check 2 3import { Collection } from "./collection.js"; 4import { Type } from "../models/type.js"; 5 6/** The types within one doc, e.g. "Methods" or "Guides". * 7 * @extends {Collection<Type>} 8 */ 9export class Types extends Collection { 10 /** @inheritdoc */ 11 model() { 12 return Type; 13 } 14 static GUIDES_RGX = 15 /(^|\()(guides?|tutorials?|reference|book|getting\ started|manual|examples)($|[\):])/i; 16 static APPENDIX_RGX = /appendix/i; 17 18 /** 19 * Splits the types into guides, regular types and appendices, in that 20 * order, dropping any group that ends up empty. 21 * 22 * @returns {unknown[][]} 23 */ 24 groups() { 25 const result = []; 26 for (var type of this.models) { 27 const name = this._groupFor(type); 28 result[name] ||= []; 29 result[name].push(type); 30 } 31 return result.filter((e) => e.length > 0); 32 } 33 34 /** 35 * @param {Type} type 36 * @returns {number} The index of the group the type belongs in. 37 */ 38 _groupFor(type) { 39 if (Types.GUIDES_RGX.test(type.name)) { 40 return 0; 41 } else if (Types.APPENDIX_RGX.test(type.name)) { 42 return 2; 43 } else { 44 return 1; 45 } 46 } 47};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.