
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
@data-prism/utils
Advanced tools
Common utility functions used across the Data Prism ecosystem. This package provides lightweight helper functions for functional programming patterns, data transformation, and common operations that are shared between Data Prism packages.
Common utility functions used across the Data Prism ecosystem. This package provides lightweight helper functions for functional programming patterns, data transformation, and common operations that are shared between Data Prism packages.
Data Prism Utils is built around several key principles:
npm install @data-prism/utils
The package provides utility functions that handle common patterns in data processing:
applyOrMap(itemItemsOrNull, fn)Applies a function to an item or maps it over an array of items. Handles null and undefined gracefully by returning them unchanged.
Parameters:
itemItemsOrNull (T | T[] | null | undefined) - Single item, array of items, or null/undefinedfn (Function) - Function to apply to each itemReturns: Result of applying fn to the item(s), or null/undefined if input was null/undefined
import { applyOrMap } from "@data-prism/utils";
// Single item
applyOrMap(5, x => x * 2); // Returns: 10
// Array of items
applyOrMap([1, 2, 3], x => x * 2); // Returns: [2, 4, 6]
// Null/undefined handling
applyOrMap(null, x => x * 2); // Returns: null
applyOrMap(undefined, x => x * 2); // Returns: undefined
applyOrMapAsync(itemItemsOrNull, asyncFn)Applies an async function to an item or maps it over an array of items. Handles null and undefined gracefully.
Parameters:
itemItemsOrNull (T | T[] | null | undefined) - Single item, array of items, or null/undefinedasyncFn (Function) - Async function to apply to each itemReturns: Promise resolving to the result of applying asyncFn to the item(s), or null/undefined if input was null/undefined
import { applyOrMapAsync } from "@data-prism/utils";
// Single item
await applyOrMapAsync(5, async x => x * 2); // Returns: 10
// Array of items
await applyOrMapAsync([1, 2, 3], async x => x * 2); // Returns: [2, 4, 6]
// Null/undefined handling
applyOrMapAsync(null, async x => x * 2); // Returns: null
applyOrMapAsync(undefined, async x => x * 2); // Returns: undefined
pipeThru(init, fns)Pipes a value through a series of functions in sequence. Each function receives the result of the previous function.
Parameters:
init (T) - Initial value to pipe through the functionsfns (Function[]) - Array of functions to pipe the value throughReturns: The result after applying all functions in sequence
import { pipeThru } from "@data-prism/utils";
const add5 = x => x + 5;
const multiply2 = x => x * 2;
const toString = x => x.toString();
pipeThru(10, [add5, multiply2, toString]); // Returns: "30"
import { applyOrMap, pipeThru } from "@data-prism/utils";
// Transform data that might be a single item or array
const data = [{ name: "John" }, { name: "Jane" }];
const addGreeting = person => ({ ...person, greeting: `Hello, ${person.name}` });
const toUpperCase = person => ({ ...person, name: person.name.toUpperCase() });
const result = applyOrMap(data, person =>
pipeThru(person, [addGreeting, toUpperCase])
);
console.log(result);
// [
// { name: "JOHN", greeting: "Hello, John" },
// { name: "JANE", greeting: "Hello, Jane" }
// ]
import { applyOrMapAsync } from "@data-prism/utils";
async function fetchUserDetails(userId) {
const response = await fetch(`/api/users/${userId}`);
return response.json();
}
// Works with both single IDs and arrays of IDs
const userIds = ["user-1", "user-2", "user-3"];
const userDetails = await applyOrMapAsync(userIds, fetchUserDetails);
// Also works with a single ID
const singleUser = await applyOrMapAsync("user-1", fetchUserDetails);
import { pipeThru } from "@data-prism/utils";
// Define transformation steps
const parseJson = str => JSON.parse(str);
const extractUsers = data => data.users;
const filterActive = users => users.filter(u => u.active);
const sortByName = users => users.sort((a, b) => a.name.localeCompare(b.name));
// Process data through the pipeline
const rawData = '{"users": [{"name": "Bob", "active": true}, {"name": "Alice", "active": false}]}';
const result = pipeThru(rawData, [
parseJson,
extractUsers,
filterActive,
sortByName
]);
console.log(result); // [{ name: "Bob", active: true }]
import { applyOrMap } from "@data-prism/utils";
// Safely handle potentially null/undefined data
function processUserData(userData) {
return applyOrMap(userData, user => ({
...user,
displayName: user.firstName + " " + user.lastName
}));
}
processUserData(null); // Returns: null
processUserData(undefined); // Returns: undefined
processUserData(user); // Returns: processed user
processUserData([user1, user2]); // Returns: [processed user1, processed user2]
import { applyOrMap, pipeThru } from "@data-prism/utils";
// Common pattern in Data Prism packages
function normalizeResources(resources) {
const addType = resource => ({ ...resource, type: resource.type || "unknown" });
const addId = resource => ({ ...resource, id: resource.id || generateId() });
const validateRequired = resource => {
if (!resource.attributes) throw new Error("Missing attributes");
return resource;
};
return applyOrMap(resources, resource =>
pipeThru(resource, [addType, addId, validateRequired])
);
}
// Works with single resources or arrays
const singleResource = { attributes: { name: "Test" } };
const multipleResources = [
{ attributes: { name: "Test 1" } },
{ attributes: { name: "Test 2" } }
];
const normalizedSingle = normalizeResources(singleResource);
const normalizedMultiple = normalizeResources(multipleResources);
Data Prism Utils includes comprehensive TypeScript definitions:
import { applyOrMap, applyOrMapAsync, pipeThru } from "@data-prism/utils";
// Type-safe transformations
const numbers: number[] = [1, 2, 3];
const doubled: number[] = applyOrMap(numbers, x => x * 2);
// Async operations
const asyncResult: Promise<string[]> = applyOrMapAsync(
["a", "b", "c"],
async (str: string): Promise<string> => str.toUpperCase()
);
// Pipeline with type inference
const result: string = pipeThru(
42,
[
(x: number) => x * 2, // number -> number
(x: number) => x.toString(), // number -> string
(x: string) => x.padStart(4, '0') // string -> string
]
);
// Efficient: Process in pipelines
const result = pipeThru(data, [transform1, transform2, transform3]);
// Less efficient: Multiple intermediate variables
const step1 = transform1(data);
const step2 = transform2(step1);
const step3 = transform3(step2);
@data-prism/core - Uses utils for resource and query processing@data-prism/memory-store - Uses utils for data transformations@data-prism/postgres-store - Uses utils for SQL query buildingFAQs
Common utility functions used across the Data Prism ecosystem. This package provides lightweight helper functions for functional programming patterns, data transformation, and common operations that are shared between Data Prism packages.
The npm package @data-prism/utils receives a total of 3 weekly downloads. As such, @data-prism/utils popularity was classified as not popular.
We found that @data-prism/utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.