Registry / storage / js-orm-lib

js-orm-lib

JSON →
library1.0.9jsnpmunverified

js-orm-lib v1.0.9 is a lightweight JavaScript ORM library focused on mapping backend API responses to front-end data models and vice versa. It uses a simple mapping configuration with string paths and custom transformation functions. Key differentiators: supports nested field mapping, entity name wrapping for reverse mapping, and requires explicit transformForApi when using functional mappings to ensure data integrity. Release cadence is low; this is the latest stable version. No notable alternatives with the same simplicity.

npm install js-orm-lib
INSTALL
IMPORT
SIG · JS-ORM-LIB
J
js-orm-lib
storagejavascriptv1.0.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mapFieldsFromApi
import { mapFieldsFromApi } from 'js-orm-lib'
const mapFieldsFromApi = require('js-orm-lib').mapFieldsFromApi
ESM import only. The package does not export a default; use named imports.
mapFieldsForApi
import { mapFieldsForApi } from 'js-orm-lib'
import mapFieldsForApi from 'js-orm-lib'
Named export, not default.
mapFieldsFromApi and mapFieldsForApi
import { mapFieldsFromApi, mapFieldsForApi } from 'js-orm-lib'
const jsOrm = require('js-orm-lib'); const mapFieldsFromApi = jsOrm.mapFieldsFromApi;
Both functions are named exports; no default export.

Demonstrates basic usage: mapping from API data to frontend model with string paths, function fields, transforms, and reverse mapping.

import { mapFieldsFromApi, mapFieldsForApi } from 'js-orm-lib'; const mockAPIData = { data: { fullName: 'Homer Simpson', ageNumber: 40, location: { town: 'SpringField' } }, favoriteFood: ['beer', 'pizza', 'burger'] }; const mapping = { name: 'data.fullName', age: 'data.ageNumber', homeTown: 'data.location.town', likedFood: 'favoriteFood', firstName: (mappedData, response) => response.data.fullName.split(' ')[0], birthYear: (mappedData, response) => { const date = new Date(); date.setFullYear(date.getFullYear() - mappedData.age); return date.getFullYear(); }, transformFromApi: (mappedData, response) => ({ ...mappedData, beersPerDay: 1, }), transformForApi: (mappedData) => ({ ...mappedData, needsMoreBeer: true, }), }; const mappedResult = mapFieldsFromApi(mockAPIData, mapping); console.log(mappedResult); // Reverse mapping const reversed = mapFieldsForApi(mappedResult, mapping); console.log(reversed);
Debug
Known issues
gotchaIf you use function values or transformFromApi, you must also provide transformForApi, otherwise the library throws an error.
fix
Always include transformForApi when using functional mappings or transformFromApi.
affects: >=0.0.0
gotchastring path mappings are reversed when calling mapFieldsForApi, but function fields and transformFromApi fields persist as-is.
fix
Be aware that only string paths are reversed; custom logic must be handled in transformForApi.
affects: >=0.0.0
gotchaThe library does not support async transformation functions. Functions must be synchronous.
fix
Do not use async/await in mapping functions; preprocess data before mapping if asynchronous operations are needed.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'split')
Mapping function accesses a property on response that doesn't exist or is undefined.
fix
Ensure the response object contains the expected nested property before accessing it. Use optional chaining or check existence.
Error: You need to specify a `transformForApi` function in the mapping because you used a function field or `transformFromApi` option.
Used function value or transformFromApi without providing transformForApi.
fix
Add transformForApi to the mapping configuration.
TypeError: mapping is not a valid object
Passed null, undefined, or non-object as mapping parameter.
fix
Ensure mapping is a plain object with string keys and string/function values.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
25
Resources
js-orm-lib — npm install js-orm-lib · libregistry