Skip to content

Commit

Permalink
chore: migrate to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
fabnguess committed Aug 13, 2024
1 parent 5c78bc4 commit c78e3d3
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

## Requirements

- [Node.js](https://nodejs.org/en/) v18 or higher
- [Node.js](https://nodejs.org/en/) v20 or higher

## Getting Started

Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./src/node";
export * from "./src/web";
export * from "./src/node.js";
export * from "./src/web.js";
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.4.0",
"description": "NodeSecure security flags",
"scripts": {
"test": "node --test test/",
"test": "glob -c \"tsx --test\" \"./test/**/*.spec.ts\"",
"coverage": "c8 -r html npm test",
"lint": "eslint index.js",
"generateFlags": "node scripts/generateFlags.js"
Expand Down Expand Up @@ -46,12 +46,17 @@
"homepage": "https://github.com/NodeSecure/flags#readme",
"devDependencies": {
"@nodesecure/eslint-config": "^1.8.0",
"@openally/config.typescript": "^1.0.3",
"@types/node": "^22.2.0",
"@types/turndown": "^5.0.5",
"c8": "^10.1.2",
"eslint": "^9.9.0",
"turndown": "^7.1.2"
"glob": "^11.0.0",
"tsx": "^4.17.0",
"turndown": "^7.1.2",
"typescript": "^5.5.4"
},
"type": "module",
"engines": {
"node": ">=18"
"node": ">=20"
}
}
File renamed without changes.
11 changes: 10 additions & 1 deletion src/manifest.js → src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/* eslint-disable max-len */

/** @type {flags.Manifest} **/
export const FLAGS = {

export interface Flag {
[key: string]: {
emoji: string;
title: string;
tooltipDescription: string
}
}

export const FLAGS : Flag = {
externalCapacity: {
emoji: "🌍",
title: "hasExternalCapacity",
Expand Down
4 changes: 2 additions & 2 deletions src/node.js → src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const kFlagsPath = path.join(__dirname, "flags");
* @description lazy read a flag file by getting a Node.js ReadableStream
* @param {!string} name flag (HTML File) name
*/
export function lazyFetchFlagFile(name) {
export function lazyFetchFlagFile(name: string): fs.ReadStream {
if (typeof name !== "string") {
throw new TypeError("You should provide a flag name");
}
Expand All @@ -29,7 +29,7 @@ export function lazyFetchFlagFile(name) {
return fs.createReadStream(path.join(kFlagsPath, fileName));
}

export async function eagerFetchFlagFile(name) {
export async function eagerFetchFlagFile(name: string): Promise<string> {
const rStream = lazyFetchFlagFile(name);
let htmlStr = "";

Expand Down
11 changes: 6 additions & 5 deletions src/web.js → src/web.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
// Import Internal Dependencies
import { FLAGS } from "./manifest.js";
import type { Flag } from "./manifest.js";

const kNotFoundFlags = "🔴";
const kManifestEmoji = Object.fromEntries(getManifestEmoji());
const kManifestEmoji : Record<string, string> = Object.fromEntries(getManifestEmoji());

/**
* @description Export src/manifest.json
*/
export function getManifest() {
export function getManifest(): Flag {
return FLAGS;
}

/**
* @example
* const kManifestEmoji = Object.fromEntries(getManifestEmoji());
*/
export function* getManifestEmoji() {
export function* getManifestEmoji() : Generator<[string, string]> {
for (const { emoji, title } of Object.values(FLAGS)) {
yield [title, emoji];
}
}

export function getEmojiFromTitle(title) {
export function getEmojiFromTitle(title: string ) : string {
return kManifestEmoji[title] ?? kNotFoundFlags;
}

/**
* @description Complete list of flags title (as an ES6 Set)
*/
export function getFlags() {
export function getFlags(): Set<string>{
return new Set(Object.values(FLAGS).map((flagDescriptor) => flagDescriptor.title));
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@openally/config.typescript",
"compilerOptions": {
"outDir": "dist",
"rootDir": "./src",
"types": ["node"],
}
}

0 comments on commit c78e3d3

Please sign in to comment.