A small utility library for Payload CMS projects, not a config plugin. It offers a validator composer that runs custom validators before a Payload default validator, helpers that pull IDs from values that may be IDs or populated documents, and helpers that resolve a value to a full document through a fetch callback. Requires Payload 3 or later.
Utility functions for Payload CMS — extract IDs, resolve documents, and compose field validators
Installation
npm i payload-utilities0
Stars
0
Forks
0
Open Issues
5 days ago
Last Updated
238
Weekly Downloads
v1.2.0
npm Version
10.4 KB
Unpacked Size
0
Dependencies
00 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 0 |
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
| Nov 21, 2026 | 0 |
| Nov 20, 2026 | 0 |
| Nov 19, 2026 | 0 |
| Nov 18, 2026 | 0 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
| Nov 13, 2026 | 0 |
| Nov 12, 2026 | 0 |
| Nov 11, 2026 | 0 |
| Nov 10, 2026 | 0 |
| Nov 9, 2026 | 0 |
| Nov 8, 2026 | 0 |
| Nov 7, 2026 | 0 |
| Nov 6, 2026 | 0 |
| Nov 5, 2026 | 0 |
| Nov 4, 2026 | 0 |
| Nov 3, 2026 | 0 |
| Nov 2, 2026 | 0 |
| Nov 1, 2026 | 0 |
| Oct 31, 2026 | 0 |
| Oct 30, 2026 | 0 |
| Oct 29, 2026 | 0 |
| Oct 28, 2026 | 0 |
| Oct 27, 2026 | 0 |
| Oct 26, 2026 | 0 |
| Oct 25, 2026 | 0 |
| Oct 24, 2026 | 0 |
| Oct 23, 2026 | 0 |
| Oct 22, 2026 | 0 |
| Oct 21, 2026 | 0 |
| Oct 20, 2026 | 0 |
| Oct 19, 2026 | 0 |
| Oct 18, 2026 | 0 |
| Oct 17, 2026 | 0 |
| Oct 16, 2026 | 0 |
| Oct 15, 2026 | 0 |
| Oct 14, 2026 | 0 |
| Oct 13, 2026 | 0 |
| Oct 12, 2026 | 0 |
| Oct 11, 2026 | 0 |
| Oct 10, 2026 | 0 |
| Oct 9, 2026 | 0 |
| Oct 8, 2026 | 0 |
| Oct 7, 2026 | 0 |
| Oct 6, 2026 | 0 |
| Oct 5, 2026 | 0 |
| Oct 4, 2026 | 0 |
| Oct 3, 2026 | 0 |
| Oct 2, 2026 | 0 |
| Oct 1, 2026 | 0 |
| Sep 30, 2026 | 0 |
| Sep 29, 2026 | 0 |
| Sep 28, 2026 | 0 |
| Sep 27, 2026 | 0 |
| Sep 26, 2026 | 0 |
| Sep 25, 2026 | 0 |
| Sep 24, 2026 | 0 |
| Sep 23, 2026 | 0 |
| Sep 22, 2026 | 0 |
| Sep 21, 2026 | 0 |
| Sep 20, 2026 | 0 |
| Sep 19, 2026 | 0 |
| Sep 18, 2026 | 0 |
| Sep 17, 2026 | 0 |
| Sep 16, 2026 | 0 |
| Sep 15, 2026 | 0 |
| Sep 14, 2026 | 0 |
| Sep 13, 2026 | 0 |
| Sep 12, 2026 | 0 |
| Sep 11, 2026 | 0 |
| Sep 10, 2026 | 0 |
| Sep 9, 2026 | 0 |
| Sep 8, 2026 | 0 |
| Sep 7, 2026 | 0 |
238+231 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 238 |
| Dec 5, 2026 | 199 |
| Dec 4, 2026 | 194 |
| Dec 3, 2026 | 180 |
| Dec 2, 2026 | 2 |
| Dec 1, 2026 | 7 |
| Nov 30, 2026 | 7 |
| Nov 29, 2026 | 6 |
| Nov 28, 2026 | 6 |
| Nov 27, 2026 | 6 |
| Nov 26, 2026 | 6 |
| Nov 25, 2026 | 6 |
| Nov 24, 2026 | 1 |
| Nov 23, 2026 | 1 |
| Nov 22, 2026 | 3 |
| Nov 21, 2026 | 3 |
| Nov 20, 2026 | 3 |
| Nov 19, 2026 | 4 |
| Nov 18, 2026 | 8 |
| Nov 17, 2026 | 8 |
| Nov 16, 2026 | 10 |
| Nov 15, 2026 | 11 |
| Nov 14, 2026 | 12 |
| Nov 13, 2026 | 12 |
| Nov 12, 2026 | 15 |
| Nov 11, 2026 | 11 |
| Nov 10, 2026 | 11 |
| Nov 9, 2026 | 9 |
| Nov 8, 2026 | 7 |
| Nov 7, 2026 | 6 |
| Nov 6, 2026 | 5 |
| Nov 5, 2026 | 1 |
| Nov 4, 2026 | 1 |
| Nov 3, 2026 | 2 |
| Nov 2, 2026 | 3 |
| Nov 1, 2026 | 3 |
| Oct 31, 2026 | 3 |
| Oct 30, 2026 | 3 |
| Oct 29, 2026 | 3 |
| Oct 28, 2026 | 3 |
| Oct 27, 2026 | 3 |
| Oct 26, 2026 | 6 |
| Oct 25, 2026 | 6 |
| Oct 24, 2026 | 7 |
| Oct 23, 2026 | 7 |
| Oct 22, 2026 | 10 |
| Oct 21, 2026 | 10 |
| Oct 20, 2026 | 9 |
| Oct 19, 2026 | 5 |
| Oct 18, 2026 | 4 |
| Oct 17, 2026 | 4 |
| Oct 16, 2026 | 4 |
| Oct 15, 2026 | 2 |
| Oct 14, 2026 | 2 |
| Oct 13, 2026 | 2 |
| Oct 12, 2026 | 2 |
| Oct 11, 2026 | 3 |
| Oct 10, 2026 | 2 |
| Oct 9, 2026 | 2 |
| Oct 8, 2026 | 1 |
| Oct 7, 2026 | 1 |
| Oct 6, 2026 | 1 |
| Oct 5, 2026 | 1 |
| Oct 4, 2026 | 0 |
| Oct 3, 2026 | 1 |
| Oct 2, 2026 | 3 |
| Oct 1, 2026 | 3 |
| Sep 30, 2026 | 5 |
| Sep 29, 2026 | 9 |
| Sep 28, 2026 | 9 |
| Sep 27, 2026 | 10 |
| Sep 26, 2026 | 12 |
| Sep 25, 2026 | 10 |
| Sep 24, 2026 | 10 |
| Sep 23, 2026 | 8 |
| Sep 22, 2026 | 8 |
| Sep 21, 2026 | 8 |
| Sep 20, 2026 | 8 |
| Sep 19, 2026 | 5 |
| Sep 18, 2026 | 5 |
| Sep 17, 2026 | 6 |
| Sep 16, 2026 | 7 |
| Sep 15, 2026 | 3 |
| Sep 14, 2026 | 5 |
| Sep 13, 2026 | 4 |
| Sep 12, 2026 | 8 |
| Sep 11, 2026 | 8 |
| Sep 10, 2026 | 7 |
| Sep 9, 2026 | 7 |
| Sep 8, 2026 | 7 |
| Sep 7, 2026 | 7 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1176252947-root)<a href="https://payloaddirectory.dev/plugins/1176252947-root"><img src="https://payloaddirectory.dev/badge/1176252947-root.svg" alt="Payload Directory"></a>README
Utility functions for Payload CMS — type-safe validators, ID extraction, and document resolution.
npm install payload-utilities
createValidatorCreates a composite field validator by combining custom validators with a Payload default validator. Custom validators run first — if any fails, it short-circuits. If all pass, the default validator runs.
import type {DateField} from 'payload';
import {date} from 'payload/shared';
import {createValidator, type CustomValidator} from 'payload-utilities';
type Data = Task;
type SiblingData = Data['schedule']['timeframe'];
type Value = SiblingData['end'];
type FieldConfig = DateField;
type Validator = CustomValidator<Data, SiblingData, Value, FieldConfig>;
const validateEndDate: Validator = (value, options) => {
const start = options.siblingData?.start;
if (!start) {
return 'Start- & Ende des Einplanungszeitraum sind Pflichtfelder';
}
const startDate = new Date(start);
const endDate = new Date(value);
if (endDate.getTime() < startDate.getTime()) {
return 'Das Ende des Einplanungszeitraum darf nicht vor dem Start liegen';
}
return true;
};
const validateStartDate: Validator = (value, options) => {
// ...
};
export const timeframeValidator = createValidator<Data, SiblingData, Value, FieldConfig>({
defaultValidator: date,
validators: [validateEndDate, validateStartDate],
});
Custom validators only run for present values. null, undefined, '' and empty arrays go straight to the default validator; 0 and false are validated.
formatErrorValidators may return any error type instead of a string. formatError turns it into the message, e.g. to translate keys in one place. It is required when the error type is not a string.
type Error = {key: MyTranslationKey; values?: Record<string, unknown>};
type Validator = CustomValidator<Data, SiblingData, Value, FieldConfig, DefaultDocumentIDType, Error>;
const isUnique: Validator = async (value, options) =>
(await isTaken(value)) ? {key: 'validation:notUnique'} : true;
export const validateTitle = createValidator<Data, SiblingData, Value, FieldConfig, DefaultDocumentIDType, Error>({
defaultValidator: text,
validators: [isUnique],
formatError: (error, {req}) => req.t(error.key, error.values),
});
extractId / extractIdsExtract IDs from values that are either an ID or an object with an id property.
import {extractId, extractIds} from 'payload-utilities';
// Single values
extractId(1); // 1
extractId('abc'); // 'abc'
extractId({id: 1}); // 1
// Arrays
extractIds([1, {id: 2}]); // [1, 2]
getDocument / getDocumentsResolves a value that is either a full document or an ID. If an object is passed, it is returned directly. If an ID is passed, the callback is called to fetch the document.
import {getDocument} from 'payload-utilities';
const post = await getDocument(idOrPost, (id) =>
payload.findByID({collection: 'posts', id}),
);
import {getDocuments} from 'payload-utilities';
const posts = await getDocuments(idsOrPosts, (ids) =>
payload.find({collection: 'posts', where: {id: {in: ids}}}).then(result => result.docs),
);
MIT
payload field factories
Typed factory functions that build Payload field configs with concise, composable overrides
77255/wk1v3
payload schema
Define Payload field validation once and compile it to Payload fields and Zod 4 schemas
7139/wk3v3
payload utilities
Developer utilities for traversing, flattening and transforming Payload documents and tidying generated types
6229/wk16v3
payload plugin tooling
Shared lint, format, TypeScript, build, test and CI config for developing Payload plugins
6039/wk0v4
payload cli
Command-line access to Payload collections and globals through the Local API, built for AI agents and humans
588/wk13v3
payload dev tools
Floating dev toolbar, /dev pages and an app snapshot for AI agents in Payload projects on Next.js
5548/wk18v3