From 11d2ed31b47a08f35be5ff2cb077fc58fb7a218d Mon Sep 17 00:00:00 2001 From: Gerben Date: Sun, 20 Dec 2020 18:00:50 +0100 Subject: [PATCH] Consistently capitalise type names --- src/common.ts | 2 +- src/index.ts | 26 +++++++++++++------------- src/whatwg-dom.ts | 8 ++++---- src/whatwg-html.ts | 10 +++++----- src/whatwg-infra.ts | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/common.ts b/src/common.ts index 5733046..d92c9b5 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,4 +1,4 @@ -export type locale = string; +export type Locale = string; export function nextNode(node: Node): Node | null { const walker = (node.ownerDocument ?? node as Document).createTreeWalker(node.getRootNode()); diff --git a/src/index.ts b/src/index.ts index 934eb09..8b9b055 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import { - locale, + Locale, isElement, nextNode, } from './common.js'; @@ -29,12 +29,12 @@ import { } from './whatwg-html.js'; import { - asciiString, + AsciiString, htmlNamespace, } from './whatwg-infra.js'; -type nonEmptyString = string; -type integer = number; +type NonEmptyString = string; +type Integer = number; // § 3.3.1. Processing the fragment directive @@ -48,7 +48,7 @@ export const fragmentDirectiveDelimiter = ':~:'; // Instead of actually modifying the document’s URL fragment and fragment directive, this implementation returns the values these should have been set to. It therefore does not take the second argument. Also it expects to receive the URL as a string instead of as a URL object. export function processAndConsumeFragmentDirective(url: string): { url: string, documentFragmentDirective: string | null } { // “Each document has an associated fragment directive which is either null or an ASCII string holding data used by the UA to process the resource. It is initially null.” - let documentFragmentDirective: asciiString | null = null; + let documentFragmentDirective: AsciiString | null = null; // 1. “Let raw fragment be equal to url’s fragment.” // (as we only have access to the serialised URL, we extract the fragment again) @@ -86,10 +86,10 @@ export function processAndConsumeFragmentDirective(url: string): { url: string, // https://wicg.github.io/scroll-to-text-fragment/#parsedtextdirective // “A ParsedTextDirective is a struct that consists of four strings: textStart, textEnd, prefix, and suffix. textStart is required to be non-null. The other three items may be set to null, indicating they weren’t provided. The empty string is not a valid value for any of these items.” export interface ParsedTextDirective { - textStart: nonEmptyString; - textEnd: nonEmptyString | null; - prefix: nonEmptyString | null; - suffix: nonEmptyString | null; + textStart: NonEmptyString; + textEnd: NonEmptyString | null; + prefix: NonEmptyString | null; + suffix: NonEmptyString | null; }; // https://wicg.github.io/scroll-to-text-fragment/#parse-a-text-directive @@ -170,7 +170,7 @@ export function isValidFragmentDirective(input: string | null): input is ValidFr // https://wicg.github.io/scroll-to-text-fragment/#text-fragment-directive // “The text fragment directive is one such fragment directive that enables specifying a piece of text on the page, that matches the production:” -export type TextDirective = asciiString; // should conform to the text directive grammar +export type TextDirective = AsciiString; // should conform to the text directive grammar export function isTextFragmentDirective(input: string): input is TextDirective { // TODO (use PEG.js?) return input.startsWith('text='); // TEMP @@ -373,7 +373,7 @@ export function scrollRangeIntoView(range: Range, behavior: ScrollBehavior, bloc // https://wicg.github.io/scroll-to-text-fragment/#process-a-fragment-directive // “To process a fragment directive, given as input an ASCII string fragment directive input and a Document document, run these steps:” -export function processFragmentDirective(fragmentDirectiveInput: asciiString | null, document: Document): Range[] { +export function processFragmentDirective(fragmentDirectiveInput: AsciiString | null, document: Document): Range[] { // 1. “If fragment directive input is not a valid fragment directive, then return an empty list.” if (!isValidFragmentDirective(fragmentDirectiveInput)) { return []; @@ -858,7 +858,7 @@ export function findARangeFromANodeList(queryString: string, searchRange: Range, // https://wicg.github.io/scroll-to-text-fragment/#get-boundary-point-at-index // “To get boundary point at index, given an integer index, list of Text nodes nodes, and a boolean isEnd, follow these steps:” -export function getBoundaryPointAtIndex(index: integer, nodes: Text[], isEnd: boolean): BoundaryPoint | null { +export function getBoundaryPointAtIndex(index: Integer, nodes: Text[], isEnd: boolean): BoundaryPoint | null { // 1. “Let counted be 0.” let counted = 0; @@ -898,7 +898,7 @@ export function getBoundaryPointAtIndex(index: integer, nodes: Text[], isEnd: bo // https://wicg.github.io/scroll-to-text-fragment/#is-at-a-word-boundary // “A number position is at a word boundary in a string text, given a locale locale, if, using locale, …” -export function isAtWordBoundary(position: number, text: string, locale: locale) { +export function isAtWordBoundary(position: number, text: string, locale: Locale) { // “…either a word boundary immediately precedes the positionth code unit, …” // TODO Implement the “default word boundary specification” of the referenced unicode spec. // TEMP Just use a regular expression to test against a pair of alphanumeric characters. diff --git a/src/whatwg-dom.ts b/src/whatwg-dom.ts index 38133c0..da3a415 100644 --- a/src/whatwg-dom.ts +++ b/src/whatwg-dom.ts @@ -10,8 +10,8 @@ import { nextNode, } from './common.js'; -type nonNegativeInteger = number; -type count = number; +type NonNegativeInteger = number; +type Count = number; // https://dom.spec.whatwg.org/#concept-tree-descendant @@ -109,7 +109,7 @@ export function isShadowIncludingInclusiveAncestor(nodeA: Node, nodeB: Node): bo export function substringData( node: CharacterData, // XXX The spec says “node node”, but reads “node’s data” which is only defined for CharacterData nodes. offset: number, - count: count + count: Count ): string { // 1. “Let length be node’s length.” const length = nodeLength(node); @@ -126,4 +126,4 @@ export function substringData( // https://dom.spec.whatwg.org/#concept-range-bp // “A boundary point is a tuple consisting of a node (a node) and an offset (a non-negative integer).” -export type BoundaryPoint = [Node, nonNegativeInteger]; +export type BoundaryPoint = [Node, NonNegativeInteger]; diff --git a/src/whatwg-html.ts b/src/whatwg-html.ts index fde1b12..45d9909 100644 --- a/src/whatwg-html.ts +++ b/src/whatwg-html.ts @@ -6,20 +6,20 @@ import { - locale, + Locale, isElement, } from './common.js'; import { + asciiWhitespace, htmlNamespace, - AsciiWhitespace, xmlNamespace, } from './whatwg-infra.js'; // § 3.2.6.2 The lang and xml:lang attributes // https://html.spec.whatwg.org/multipage/dom.html#language -export function languageOf(node: Node): locale { +export function languageOf(node: Node): Locale { // “To determine the language of a node, user agents must look at the nearest ancestor element (including the element itself if the node is an element) that has a lang attribute in the XML namespace set or is an HTML element and has a lang in no namespace attribute set. That attribute specifies the language of the node (regardless of its value).” let curNode: Node | null = node; while (curNode !== null) { @@ -73,13 +73,13 @@ export function getPragmaSetDefaultLanguage(): string | undefined { let position = 0; // 5. “Skip ASCII whitespace within input given position.” - while (position < input.length && AsciiWhitespace.includes(input[position])) + while (position < input.length && asciiWhitespace.includes(input[position])) position++; // 6. “Collect a sequence of code points that are not ASCII whitespace from input given position.” // 7. “Let candidate be the string that resulted from the previous step.” let candidate = ''; - while (!AsciiWhitespace.includes(input[position])) { + while (!asciiWhitespace.includes(input[position])) { candidate += input[position]; position++; } diff --git a/src/whatwg-infra.ts b/src/whatwg-infra.ts index 8cb833e..4ac1486 100644 --- a/src/whatwg-infra.ts +++ b/src/whatwg-infra.ts @@ -6,11 +6,11 @@ // https://infra.spec.whatwg.org/#ascii-whitespace // “ASCII whitespace is U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020 SPACE.” -export const AsciiWhitespace = '\u0009\u000a\u000c\u000d\u0020'; +export const asciiWhitespace = '\u0009\u000a\u000c\u000d\u0020'; // https://infra.spec.whatwg.org/#ascii-string // “An ASCII string is a string whose code points are all ASCII code points.” -export type asciiString = string; +export type AsciiString = string; // https://infra.spec.whatwg.org/#html-namespace // “The HTML namespace is "http://www.w3.org/1999/xhtml".”