This content has moved here: https://2ality.com/2022/10/javascript-decorators.html#history-of-decorators
// The actual API is documented at the end of this file | |
/** | |
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters | |
*/ | |
const ansiConstants = { | |
//----- Attributes ----- | |
Normal: 0, |
// This code has moved here: https://2ality.com/2022/10/javascript-decorators.html#example-friend-visibility |
-
Collecting material: For a number of topics that I may write about in the future, I have text files where I collect information as I come across it during coding, on the web, on Twitter, etc.
-
Outline: The collected material is my starting point. I rearrange it into an outline which I refine until I’m happy with it. Refining includes adding/removing/rearranging items and doing more research when I notice gaps in my knowledge.
-
Skeletal draft: I add bullet points and code examples until almost all of the content exists at least in skeletal form. This process often uncovers knowledge gaps and flaws in the structure of the content which I then can fix.
These are a few thoughts on how Node.js apps can make data portable between platforms. The focus in this case is on paths. Handling line terminators is covered elsewhere.
Feedback welcome!
Sometimes we’d like to use the same paths on different platforms. Then there are two issues that we are facing:
- The path separator may be different.
- The file structure may be different: home directories and directories for temporary files may be in different locations, etc.
Approach:
- The file starts with shell code.
- That code uses Node.js to execute the file in ESM mode, after it removes the initial non-JavaScript lines.
- Node.js does not currently have CLI flags for achieving what we do in this step. Therefore, we have to pipe to the
node
executable.
- Node.js does not currently have CLI flags for achieving what we do in this step. Therefore, we have to pipe to the
When editing this file, we want to use the JavaScript mode of our IDE or editor. Therefore, we try to “hide” the shell code from JavaScript as much as possible.
//========== .split() with lookbehind ========== | |
// Downside: Safari doesn’t support lookbehind | |
import * as assert from 'node:assert/strict'; | |
const RE_SPLIT_AFTER_EOL = /(?<=\r?\n)/; | |
function splitLinesWithEols1(str) { | |
return str.split(RE_SPLIT_AFTER_EOL); | |
} |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Transformer Test</title> | |
</head> | |
<body> | |
<script type="module"> | |
/** |
import {ReadableStream} from 'node:stream/web'; | |
/** | |
* @param iterable an iterable (asynchronous or synchronous) | |
* | |
* @see https://streams.spec.whatwg.org/#example-rs-pull | |
*/ | |
function iterableToReadableStream(iterable) { | |
return new ReadableStream({ | |
async start() { |