Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding in xo for typescript #70

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 76 additions & 65 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
"version": "3.0.0",
"homepage": "https://github.com/jaredwray/fumanchu",
"author": "Jared Wray ([email protected])",
"source": "dist/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "npm run build && xo --fix && c8 mocha",
"test:ci": "npm run build && xo && c8 --reporter=lcov mocha",
"build": "rimraf ./dist && tsup ./src/index.ts --format cjs --dts --clean",
"prepare": "npm run build",
"clean": "rimraf ./node_modules ./coverage yarn.lock package-lock.json ./dist ./dist-site",
"website:build": "rimraf ./site/readme.md && npx -y docula build -s ./site -o ./dist-site",
"website:serve": "rimraf ./site/readme.md && npx -y docula serve -s ./site -o ./dist-site"
},
"keywords": [
"array",
"assemble",
Expand Down Expand Up @@ -31,57 +43,6 @@
"util",
"utility"
],
"contributors": [
"Adrián Mugnolo (https://github.com/xymbol)",
"Aleš Kotnik (www.draagle.com)",
"Ali Sheehan-Dare (https://github.com/alisd23)",
"Anders D. Johnson (https://andrz.me)",
"Arthur Cinader (http://github.com/acinader)",
"Brian Woodward (https://twitter.com/doowb)",
"Dan Dascalescu (http://dandascalescu.com)",
"Dan Gorby (https://plus.google.com/+GreenRaccoon23)",
"Dane Petersen (https://thegreatsunra.com)",
"Daniel Wabyick (https://github.com/dwabyick)",
"Dennis Borisevich (https://github.com/DenSpirit)",
"Foundy (http://foundy.io)",
"GONZO (https://github.com/why2pac)",
"GracefulLight (https://brendaniel.github.io)",
"Hariadi Hinta (http://www.hariadi.org)",
"James Tsuyuki (https://github.com/jtsuyuki)",
"Jan Stola (https://github.com/iamstolis)",
"Jason Bellamy (http://jasonbellamy.com)",
"Jeffrey Froom (http://jfroom.com)",
"Jocelyn Badgley (http://www.chipersoft.com)",
"Joey Baker (https://www.byjoeybaker.com)",
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Kevin Davis (kevindav.us)",
"Laurent Goderre (https://github.com/LaurentGoderre)",
"Liam Moat (http://www.liammoat.com)",
"Makoto Tateno (https://github.com/makotot)",
"Marie Hogebrandt (http://mariehogebrandt.se)",
"Mark Perkins (http://allmarkedup.com)",
"Martyn Rushton (http://swapnull.co.uk)",
"Max Albrecht (178.is)",
"Michael Sheedy (michaelsheedy.com)",
"Mikko Tapionlinna (http://mikko.tapionlinna.fi)",
"Nathan Jessen (http://nathanjessen.github.io)",
"Nathaniel Furniss (https://github.com/nlfurniss)",
"Oleg Orlov (https://github.com/efender)",
"Omesh (https://github.com/omeshp)",
"Patrick Burtchaell (https://pburtchaell.com)",
"Paul Welsh (paulwelsh.info)",
"Raymond Camden (https://www.raymondcamden.com)",
"Rob (https://github.com/robsilva)",
"Sam Tiffin (https://samtiffin.com)",
"Shannon Moeller (http://shannonmoeller.com)",
"Spud Hsu (http://spud.in)",
"Stephen Way (http://stephenway.net)",
"Thomas Jaggi (http://responsive.ch)",
"Tim Douglas (https://github.com/timdouglas)",
"(https://github.com/homersimpsons)",
"Jonathas Ribeiro (https://github.com/jonathas)",
"Jared Wray (https://github.com/jaredwray)"
],
"repository": "jaredwray/fumanchu",
"bugs": {
"url": "https://github.com/jaredwray/fumanchu/issues"
Expand All @@ -91,18 +52,6 @@
"dist",
"license"
],
"source": "dist/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "npm run build && c8 mocha",
"test:ci": "npm run build && c8 --reporter=lcov mocha",
"build": "rimraf ./dist && tsup ./src/index.ts --format cjs --dts --clean",
"prepare": "npm run build",
"clean": "rimraf ./node_modules ./coverage yarn.lock package-lock.json ./dist ./dist-site",
"website:build": "rimraf ./site/readme.md && npx -y docula build -s ./site -o ./dist-site",
"website:serve": "rimraf ./site/readme.md && npx -y docula serve -s ./site -o ./dist-site"
},
"dependencies": {
"arr-flatten": "^1.1.0",
"array-sort": "^1.0.0",
Expand Down Expand Up @@ -149,6 +98,68 @@
"templates": "^1.2.9",
"tsup": "^8.3.5",
"typecript": "^0.0.1-security",
"typescript": "^5.6.3"
}
"typescript": "^5.6.3",
"xo": "^0.59.3"
},
"xo": {
"ignores": [
"dist/**",
"dist-site/**",
"site/**",
"helpers/**",
"src/index.ts"
]
},
"contributors": [
"Jared Wray (https://jaredwray.com)",
"Adrián Mugnolo (https://github.com/xymbol)",
"Aleš Kotnik (www.draagle.com)",
"Ali Sheehan-Dare (https://github.com/alisd23)",
"Anders D. Johnson (https://andrz.me)",
"Arthur Cinader (http://github.com/acinader)",
"Brian Woodward (https://twitter.com/doowb)",
"Dan Dascalescu (http://dandascalescu.com)",
"Dan Gorby (https://plus.google.com/+GreenRaccoon23)",
"Dane Petersen (https://thegreatsunra.com)",
"Daniel Wabyick (https://github.com/dwabyick)",
"Dennis Borisevich (https://github.com/DenSpirit)",
"Foundy (http://foundy.io)",
"GONZO (https://github.com/why2pac)",
"GracefulLight (https://brendaniel.github.io)",
"Hariadi Hinta (http://www.hariadi.org)",
"James Tsuyuki (https://github.com/jtsuyuki)",
"Jan Stola (https://github.com/iamstolis)",
"Jason Bellamy (http://jasonbellamy.com)",
"Jeffrey Froom (http://jfroom.com)",
"Jocelyn Badgley (http://www.chipersoft.com)",
"Joey Baker (https://www.byjoeybaker.com)",
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Kevin Davis (kevindav.us)",
"Laurent Goderre (https://github.com/LaurentGoderre)",
"Liam Moat (http://www.liammoat.com)",
"Makoto Tateno (https://github.com/makotot)",
"Marie Hogebrandt (http://mariehogebrandt.se)",
"Mark Perkins (http://allmarkedup.com)",
"Martyn Rushton (http://swapnull.co.uk)",
"Max Albrecht (178.is)",
"Michael Sheedy (michaelsheedy.com)",
"Mikko Tapionlinna (http://mikko.tapionlinna.fi)",
"Nathan Jessen (http://nathanjessen.github.io)",
"Nathaniel Furniss (https://github.com/nlfurniss)",
"Oleg Orlov (https://github.com/efender)",
"Omesh (https://github.com/omeshp)",
"Patrick Burtchaell (https://pburtchaell.com)",
"Paul Welsh (paulwelsh.info)",
"Raymond Camden (https://www.raymondcamden.com)",
"Rob (https://github.com/robsilva)",
"Sam Tiffin (https://samtiffin.com)",
"Shannon Moeller (http://shannonmoeller.com)",
"Spud Hsu (http://spud.in)",
"Stephen Way (http://stephenway.net)",
"Thomas Jaggi (http://responsive.ch)",
"Tim Douglas (https://github.com/timdouglas)",
"(https://github.com/homersimpsons)",
"Jonathas Ribeiro (https://github.com/jonathas)",
"Jared Wray (https://github.com/jaredwray)"
]
}
34 changes: 18 additions & 16 deletions src/helper-registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { helpers as dateHelpers } from './helpers/date.js';
import {helpers as dateHelpers} from './helpers/date.js';

export enum HelperRegistryCompatibility {
NODEJS = 'nodejs',
Expand All @@ -9,17 +9,17 @@ export type HelperFilter = {
name?: string;
category?: string;
compatibility?: HelperRegistryCompatibility;
}
};

export type Helper = {
name: string;
category: string;
compatibility?: HelperRegistryCompatibility;
fn: Function;
}
fn: ((...arguments_: any[]) => string);
};

export class HelperRegistry {
private _helpers: Array<Helper> = [];
private readonly _helpers: Helper[] = [];

constructor() {
this.init();
Expand All @@ -34,28 +34,30 @@ export class HelperRegistry {
if (this.has(helper.name)) {
throw new Error(`Helper ${helper.name} already exists.`);
}

this._helpers.push(helper);
}

public registerHelpers(helpers: Array<Helper>) {
helpers.forEach(helper => this.register(helper));
public registerHelpers(helpers: Helper[]) {
for (const helper of helpers) {
this.register(helper);
}
}

public has(name: string): boolean {
return this._helpers.some(helper => helper.name === name);
}

public filter(filter: HelperFilter): Array<Helper> {
return this._helpers.filter(helper => {
return (!filter.name || helper.name === filter.name) &&
(!filter.category || helper.category === filter.category) &&
(!filter.compatibility || helper.compatibility === filter.compatibility);
});
public filter(filter: HelperFilter): Helper[] {
return this._helpers.filter(helper => (!filter.name || helper.name === filter.name)
&& (!filter.category || helper.category === filter.category)
&& (!filter.compatibility || helper.compatibility === filter.compatibility));
}

public loadHandlebars(handlebars: any) {
this._helpers.forEach(helper => {
for (const helper of this._helpers) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
handlebars.registerHelper(helper.name, helper.fn);
});
}
}
}
}
6 changes: 3 additions & 3 deletions src/helpers/date.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Helper} from '../helper-registry.js';
import {type Helper} from '../helper-registry.js';

const year = () => new Date().getFullYear();

export const helpers: Array<Helper> = [
export const helpers: Helper[] = [
{
name: 'year',
category: 'date',
fn: year,
},
];
];
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const Handlebars = HandlebarsLib;
* @type {Handlebars}
*/
export const handlebars = HandlebarsLib.create();

/**
* Fumanchu Handlebars helpers
*/
Expand All @@ -29,6 +30,10 @@ export async function createHandlebars() {
return handlebars;
}

/**
* Will return a Handlebars instance with Fumanchu helpers (experimental)
* @returns {Handlebars} Handlebars instance with helpers
*/
export function fumanchu() {
const registry = new HelperRegistry();
const handlebars = HandlebarsLib.create();
Expand Down
Loading