GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — t3code/oxlint-plugin-t3code/utils.ts at main · SivanTechDev/t3code

Expand file tree

/

utils.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
58 lines (49 loc) · 1.87 KB
/

utils.ts

Copy path

File metadata and controls

58 lines (49 loc) · 1.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { ESTree } from "@oxlint/plugins";
import * as Option from "effect/Option";
type ExpressionWrapper =
| ESTree.ChainExpression
| ESTree.ParenthesizedExpression
| ESTree.TSNonNullExpression
| ESTree.TSAsExpression
| ESTree.TSTypeAssertion;
type AstNode = ESTree.Node;
const asAstNode = (node: unknown): Option.Option<AstNode> =>
typeof node === "object" && node !== null && "type" in node && typeof node.type === "string"
? Option.some(node as AstNode)
: Option.none();
const isExpressionWrapper = (node: AstNode): node is ExpressionWrapper =>
node.type === "ChainExpression" ||
node.type === "ParenthesizedExpression" ||
node.type === "TSNonNullExpression" ||
node.type === "TSAsExpression" ||
node.type === "TSTypeAssertion";
export function unwrapExpression(node: unknown): Option.Option<AstNode> {
let current = asAstNode(node);
while (Option.isSome(current) && isExpressionWrapper(current.value)) {
current = asAstNode(current.value.expression);
}
return current;
}
export function getPropertyName(node: unknown): Option.Option<string> {
return Option.flatMap(asAstNode(node), (expression) => {
if (expression.type === "Identifier" && typeof expression.name === "string") {
return Option.some(expression.name);
}
if (expression.type === "PrivateIdentifier" && typeof expression.name === "string") {
return Option.some(expression.name);
}
if (expression.type === "Literal" && typeof expression.value === "string") {
return Option.some(expression.value);
}
return Option.none();
});
}
export function isIdentifier(node: Option.Option<AstNode>, name?: string): boolean {
if (Option.isNone(node)) return false;
const expression = node.value;
return (
expression.type === "Identifier" &&
typeof expression.name === "string" &&
(name === undefined || expression.name === name)
);
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.