List of habits/opinions I have when writing JavaScript/TypeScript. Some of these are nits, some are just generally good practice. Regardless, they are all things I feel strongly about.
- Double or single quotes.
- Tabs vs spaces.
| /** | |
| * @returns `typeof value === 'object' && value != null && !Array.isArray(value)` | |
| * @see {@link UntrustedObject} for type refinement details. | |
| */ | |
| function isUntrustedObject(value: unknown): value is UntrustedObject { | |
| return typeof value === 'object' && value != null && !Array.isArray(value); | |
| } | |
| // Split a string into a union of all it's characters. | |
| type SplitString<S extends string> = S extends `${infer First}${infer Rest}` |
| import { IndexedDataView } from "/binary"; | |
| import { setTag } from "../tags.ts"; | |
| import { AudioFileFormat, AudioFileRawTags, AudioFileMedia, ID3v2PictureType, AudioFileFormatType, AudioFileParseOptions } from "../types.ts"; | |
| import { createAudioFileParser } from "../utils.ts"; | |
| import { Duration } from "/numbers"; | |
| enum MetadataBlockHeaderType { | |
| STREAMINFO = 0, | |
| PADDING = 1, | |
| APPLICATION = 2, |
| import { IndexedDataView } from "../IndexedDataView.ts"; | |
| import { FileInfo, FileTags, File, FileMedia, ID3v2PictureType } from "../types.ts"; | |
| enum MetadataBlockHeaderType { | |
| STREAMINFO = 0, | |
| PADDING = 1, | |
| APPLICATION = 2, | |
| SEEKTABLE = 3, | |
| VORBIS_COMMENT = 4, | |
| CUESHEET = 5, |
| import { encodeText } from "/binary"; | |
| import { Reporter } from "/tool/console_reporter"; | |
| import { Event } from "/events"; | |
| import { Duration, DurationMeasurer, Percent } from "/numbers"; | |
| import { createResourceFromCallback, Resource } from "/resources"; | |
| import { processResource } from "/tool/resources"; | |
| class EventLoopLagTracker { | |
| constructor(delay: Duration) { | |
| this.#delay = delay; |
I hereby claim:
To claim this, I am signing this object:
| const parsed = { type: "File", program: parse(unsorted) }; | |
| // Find all imports | |
| let imports = [] | |
| traverse(parsed, { | |
| ImportDeclaration(node, parent) { | |
| imports.push({node, text: unsorted.substring(node.start, node.end)}); | |
| } | |
| }); |
| import React from 'react'; | |
| import { Flex } from 'jsxstyle'; | |
| class Column extends React.Component { | |
| render () { | |
| return <Flex {...this.props} direction="column"/>; | |
| } | |
| } | |
| export default Column; |
| function getValues () { | |
| return { | |
| a: 1, | |
| b: 2 | |
| }; | |
| } | |
| let {a, b} = getValues(); | |
| console.log(a, b); |