Gathering detailed insights and metrics for velona
Gathering detailed insights and metrics for velona
Gathering detailed insights and metrics for velona
Gathering detailed insights and metrics for velona
npm install velona
Typescript
Module System
Node Version
NPM Version
69.7
Supply Chain
97.4
Quality
78.2
Maintenance
100
Vulnerability
100
License
TypeScript (97.65%)
JavaScript (2.35%)
Total Downloads
281,428
Last Day
54
Last Week
2,075
Last Month
18,538
Last Year
95,237
MIT License
108 Stars
56 Commits
4 Forks
2 Watchers
1 Branches
4 Contributors
Updated on Jul 07, 2025
Latest Version
0.8.0
Package Id
velona@0.8.0
Unpacked Size
13.56 kB
Size
4.30 kB
File Count
11
NPM Version
9.6.7
Node Version
18.17.0
Published on
Aug 05, 2023
Cumulative downloads
Total Downloads
Last Day
-93.8%
54
Compared to previous day
Last Week
-38.6%
2,075
Compared to previous week
Last Month
33.3%
18,538
Compared to previous month
Last Year
43.7%
95,237
Compared to previous year
19
Velona is TypeScript DI helper for functional programming.
index.ts
1import { depend } from "velona"; 2 3const add = (a: number, b: number) => a + b; 4 5export const basicFn = depend({ add }, ({ add }, a: number, b: number, c: number) => add(a, b) * c);
sample.ts
1import { basicFn } from "./"; 2 3console.log(basicFn(2, 3, 4)); // 20
index.spec.ts
1import { basicFn } from "./"; 2 3const injectedFn = basicFn.inject({ add: (a, b) => a * b }); 4 5expect(injectedFn(2, 3, 4)).toBe(2 * 3 * 4); // pass 6expect(basicFn(2, 3, 4)).toBe((2 + 3) * 4); // pass
handler.ts
1import { depend } from "velona"; 2 3export const handler = depend( 4 { print: (text: string) => alert(text) }, 5 ({ print }, e: Pick<MouseEvent, "type" | "x" | "y">) => 6 print(`type: ${e.type}, x: ${e.x}, y: ${e.y}`) 7);
index.ts
1import { handler } from "./handler"; 2 3document.body.addEventListener("click", handler, false); 4document.body.click(); // alert('type: click, x: 0, y: 0')
index.spec.ts
1import { handler } from "./handler";
2
3const event = { type: "click", x: 1, y: 2 };
4
5expect(() => handler(event)).toThrow(); // ReferenceError: alert is not defined (on Node.js)
6
7const injectedHandler = handler.inject({ print: text => text });
8
9expect(injectedHandler(event)).toBe(`type: ${event.type}, x: ${event.x}, y: ${event.y}`); // pass
add.ts
1export const add = (a: number, b: number) => a + b;
noDI.ts
1import { add } from "./add"; 2 3export const noDIFn = (a: number, b: number, c: number) => add(a, b) * c;
index.ts
1import { depend } from "velona"; 2import { add } from "./add"; 3 4export const basicFn = depend({ add }, ({ add }, a: number, b: number, c: number) => add(a, b) * c);
sample.ts
1import { basicFn } from "./"; 2import { noDIFn } from "./noDI"; 3 4console.log(basicFn(2, 3, 4)); // 20 5console.log(noDIFn(2, 3, 4)); // 20
index.spec.ts
1import { basicFn } from "./"; 2import { noDIFn } from "./noDI"; 3 4const injectedFn = basicFn.inject({ add: (a, b) => a * b }); 5 6expect(injectedFn(2, 3, 4)).toBe(2 * 3 * 4); // pass 7expect(basicFn(2, 3, 4)).toBe((2 + 3) * 4); // pass 8expect(noDIFn(2, 3, 4)).toBe((2 + 3) * 4); // pass
index.ts
1import fs from "fs";
2import { depend } from "velona";
3
4type FS = {
5 readFile(path: string, option: "utf8"): Promise<string>;
6 writeFile(path: string, text: string, option: "utf8"): Promise<void>;
7};
8
9export const basicFn = depend(
10 fs.promises as FS, // downcast for injection
11 async (dependencies, path: string, text: string) => {
12 await dependencies.writeFile(path, text, "utf8");
13 return dependencies.readFile(path, "utf8");
14 }
15);
sample.ts
1import { basicFn } from "./"; 2 3const text = await basicFn("sample.txt", "Hello world!"); // create sample.txt 4console.log(text); // 'Hello world!'
index.spec.ts
1import { basicFn } from "./";
2
3const data: Record<string, string> = {};
4const injectedFn = basicFn.inject({
5 readFile: path => Promise.resolve(data[path]),
6 writeFile: (path, text) => {
7 data[path] = text;
8 return Promise.resolve();
9 },
10});
11
12const text = "Hello world!";
13await expect(injectedFn("test.txt", text)).resolves.toBe(text);
tasks.ts
1import { depend } from "velona"; 2import { PrismaClient } from "@prisma/client"; 3 4type Task = { 5 id: number; 6 label: string; 7 done: boolean; 8}; 9 10const prisma = new PrismaClient(); 11 12export const getTasks = depend( 13 { prisma: prisma as { task: { findMany(): Promise<Task[]> } } }, // inject prisma 14 ({ prisma }) => prisma.task.findMany() // prisma is injected object 15);
tasks.spec.ts
1import { getTasks } from "$/service/tasks"; 2 3const injectedGetTasks = getTasks.inject({ 4 prisma: { 5 task: { 6 findMany: () => 7 Promise.resolve([ 8 { id: 0, label: "task1", done: false }, 9 { id: 1, label: "task2", done: false }, 10 { id: 2, label: "task3", done: true }, 11 { id: 3, label: "task4", done: true }, 12 { id: 4, label: "task5", done: false }, 13 ]), 14 }, 15 }, 16}); 17 18await expect(injectedGetTasks()).resolves.toHaveLength(5);
add.ts
1export const add = (a: number, b: number) => a + b;
grandchild.ts
1import { depend } from "velona"; 2import { add } from "./add"; 3 4export const grandchild = depend({ add }, ({ add }, a: number, b: number) => add(a, b));
child.ts
1import { depend } from "velona"; 2import { grandchild } from "./grandchild"; 3 4export const child = depend( 5 { grandchild }, 6 ({ grandchild }, a: number, b: number, c: number) => grandchild(a, b) * c 7);
parentFn.ts
1import { depend } from "velona"; 2import { child } from "./child"; 3 4export const parentFn = depend( 5 { child, print: (data: number) => alert(data) }, 6 ({ child, print }, a: number, b: number, c: number) => print(child(a, b, c)) 7);
index.ts
1import { parentFn } from "./parentFn"; 2 3parentFn(2, 3, 4); // alert(20)
parentFn.spec.ts
1import { parentFn } from "./parentFn"; 2 3const injectedFn = parentFn.inject(parentDeps => ({ 4 child: parentDeps.child.inject(childDeps => ({ 5 grandchild: clildDeps.grandchild.inject({ 6 add: (a, b) => a * b, 7 }), 8 })), 9 print: data => data, 10})); 11 12expect(injectedFn(2, 3, 4)).toBe(2 * 3 * 4); // pass
Velona is licensed under a MIT License.
No vulnerabilities found.