
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Transform data to fit your structures.
$ npm install --save dafit
Dafit enables you to create a dynamic schema you want your data to fit.
import { Resolver } from 'dafit';
// import dafit from 'dafit';
// then user dafit.Resolver
// or
// const { Resolver } = require('dafit');
const defaultValue = null;
const resolveUser = new Resolver({
id: defaultValue, // if field id is present will return it if not will set it to defaultValue
firstname: user => user.first_name, // will set firstname as the return value of the function
lastname: user => user.last_name,
fullName: user => `${user.first_name} ${user.last_name.toUpperCase()}`
friends: user => getFriends(user.id), // will wait for any thenable (e.g Promise) to resolve
permissions: (user, context) => { // receives a context to enable more dynamic resolving
if (contact.withPermissions) return getPermissions(user)
return []
},
})
const user = {
id: 1,
first_name: 'John',
last_name: 'Cena',
age: 39
}
const result = resolveUser(user, { withPermissions: true });
// Promise<{
// id: 1,
// firstname: 'John',
// lastname: 'Cena',
// fullName: 'John CENA',
// friends: [...],
// permissions: ['WRITE_DASHBOARD']
// }>
You can also use a synchronuous resolver for some use case to avoid using Promises
import { SyncResolver } from 'dafit';
// const { SyncResolver } = require('dafit');
const defaultValue = null;
const resolveUser = new SyncResolver({
id: defaultValue, // if field id is present will return it if not will set it to defaultValue
firstname: user => user.first_name, // will set firstname as the return value of the function
lastname: user => user.last_name,
fullName: user => `${user.first_name} ${user.last_name.toUpperCase()}`,
aPromise: () => new Promise((resolve) => resolve('Hello World!')), // the promise will not be resolved before return
})
const user = {
id: 1,
first_name: 'John',
last_name: 'Cena',
age: 39
}
const result = resolveUser(user, { withPermission: true });
// {
// id: 1,
// firstname: 'John',
// lastname: 'Cena',
// fullName: 'John CENA',
// aPromise: Promise<'Hello World!'>
// }
FAQs
Transform data to fit your structures
The npm package dafit receives a total of 88 weekly downloads. As such, dafit popularity was classified as not popular.
We found that dafit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.