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
TypeScript DI helper for functional programming
npm install velona
Typescript
Module System
Node Version
NPM Version
67.1
Supply Chain
96.5
Quality
78.2
Maintenance
100
Vulnerability
100
License
Updated on 14 Oct 2024
Minified
Minified + Gzipped
TypeScript (97.65%)
JavaScript (2.35%)
Cumulative downloads
Total Downloads
Last day
15.7%
Compared to previous day
Last week
48.5%
Compared to previous week
Last month
-10.1%
Compared to previous month
Last year
14.1%
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.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
Found 2/18 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-02
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More