← Fundamentals
Fundamentals

The standard library and third-party packages

Read the operation’s contract before building on it

Use library operations by their documented input, matching and result rules.

Outcome

Select and compose library operations by their actual contract, and identify the native dependency setup behind an import.

Terminology (4)Terms used in this lesson

Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.

Standard library
Library facilities supplied as part of a language’s implementation or specified library environment.
API contract
The operation’s documented accepted inputs, matching rules, returned or changed values and failure behavior.
Dependency manifest
Project configuration naming required packages and the native resolver’s requirements.
Resolved dependency
The particular dependency implementation selected by the project’s resolver and configuration.

Using a library means choosing a contract

A library supplies reusable operations. Standard-library facilities come with the language implementation or runtime; a third-party dependency needs its own project setup. Importing a name selects code to use, while dependency resolution makes the required version available to the project.

The operation’s contract specifies its inputs, result and effects. For text processing, check whether it works on characters, substrings or whole items, how many matches it changes, and whether it returns new text or changes existing storage. Compose those choices around the application’s intended unit of change.

JavaScript supplies string methods, and Node supplies runtime modules such as node:fs. TypeScript declarations describe APIs for checking; declarations alone do not install their runtime implementation. Third-party package resolution and the emitted module format must agree with the execution environment.

01Label input

Read the labels people actually entered

A community noticeboard imports a line of labels, removes an optional tag: marker and applies an editor’s rename table. A tab should separate labels; a repeated marker should leave the second copy as data. A rename must keep its original target even when another rule uses the destination name.

The first line arrives from the noticeboard’s text entry. Before choosing a word-reading operation, compare what a literal space delimiter and a whitespace-word operation report for leading spaces, an interior tab and trailing spaces. This reduced input uses ASCII whitespace.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const text = '  north\tsouth  ';
const literal = text.split(' ');
const words = text.trim().split(/\s+/).filter(Boolean);

console.log(literal.length, words.length);
Which report follows from this complete project?
TypeScript · terminal.sh
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
npx tsc main.ts --strict --target ES2022 --module Node16 --moduleResolution Node16 --types node --outDir out && node out/main.js

Save each complete example in a fresh folder under its selected filename and use the guarded command. The TypeScript workflow uses local TypeScript and Node types with ES2022/Node16 CommonJS emission; set package.json’s type field to commonjs, preserving its other fields. Rust uses edition 2024. These programs use native standard libraries only. The dependency commands describe separate local project setup; the browser runner does not install packages.

02Optional markers

Decide what counts as a leading marker

The board uses one exact leading marker to flag entered labels. These probes try related native operations on a repeated marker and an unmarked or interior occurrence. Predict the results before comparing their matching rules with the board’s policy.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
for (const label of ['pre:pre:wing', 'midpre:wing']) {
	console.log(label.replace('pre:', ''));
}
Which report follows from this complete project?

03Rename requests

Keep renames attached to their original labels

Editors also rename labels. This reduced message contains oak alone, inside oakwood and again at the end. Observe the library’s substring operations before deciding how to apply a table of complete-label changes.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const message = 'oak oakwood oak';

console.log(message.replace('oak', 'elm'));
console.log(message.replaceAll('oak', 'elm'));
Which report follows from this complete project?

04Practice

Repair the noticeboard label desk

The label desk must read the entered words, interpret one optional leading marker and apply an editor’s simultaneous rename table. Each supplied complete file keeps earlier correct helpers and the input reader in place while you repair the indicated operation.

Three uses of one label pipeline

Read the entered labels, preserve marker data and reconcile complete-label changes against the original board.

  1. easy · F-PACKAGES-V4-1 Read whitespace labels
  2. medium · F-PACKAGES-V4-2 Honor one leading marker
  3. hard · F-PACKAGES-V4-3 Rename original labels
Sources

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.