Gathering detailed insights and metrics for @technote-space/velona
Gathering detailed insights and metrics for @technote-space/velona
Gathering detailed insights and metrics for @technote-space/velona
Gathering detailed insights and metrics for @technote-space/velona
npm install @technote-space/velona
Typescript
Module System
Node Version
NPM Version
66.7
Supply Chain
98.6
Quality
75.2
Maintenance
100
Vulnerability
100
License
TypeScript (97.65%)
JavaScript (2.35%)
Total Downloads
367
Last Day
1
Last Week
2
Last Month
6
Last Year
68
101 Stars
56 Commits
3 Forks
3 Watching
1 Branches
4 Contributors
Latest Version
0.8.0
Package Id
@technote-space/velona@0.8.0
Unpacked Size
17.50 kB
Size
6.15 kB
File Count
8
NPM Version
7.5.4
Node Version
15.7.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-33.3%
2
Compared to previous week
Last month
100%
6
Compared to previous month
Last year
-26.9%
68
Compared to previous year
18
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( 6 { add }, 7 ({ add }, a: number, b: number, c: number) => add(a, b) * c 8)
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'>) => print(`type: ${e.type}, x: ${e.x}, y: ${e.y}`) 6)
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(
10 `type: ${event.type}, x: ${event.x}, y: ${event.y}`
11) // 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( 5 { add }, 6 ({ add }, a: number, b: number, c: number) => add(a, b) * c 7)
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( 5 { add }, 6 ({ add }, a: number, b: number) => add(a, b) 7)
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-23
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