An interface for Directus that generates random hashes for string
fields with configurable options (length, allowed characters, auto-generate on create, allow manual regeneration, etc.). Built with the Directus Extensions SDK and Vue 3.
- Configurable length: Choose the number of characters.
- Character set toggles: Allow numbers, uppercase, and special characters.
- Auto-generate on create: Optionally set the value when a new item is created.
- Manual regenerate button: If enabled, users can regenerate the value via a button.
- Uniqueness-aware generation: If the field is marked unique in your schema, the component avoids duplicates among existing values in the collection.
- Directus host:
^10.10.0
- Node.js:
>= 18.17
(Directus 10 requirement)
From the repository root:
npm ci
npm run build
The compiled output is emitted to dist/
and referenced by Directus.
You have two options:
-
Link (recommended for development)
In this project:
npm run link
Follow the prompts to link to your local Directus project.
-
Manual install (for deployment)
Copy the built files into your Directus project under:
extensions/interfaces/hash-generator/
- Ensure
dist/index.js
is present as defined inpackage.json
.
Restart Directus after installing the extension.
- In the Directus app, go to
Settings
→Data Model
and open or create a collection. - Add a field of type
string
(Text) or open an existing string field. - Under Interface, select
Hash Generator
(icon:numbers
). - Configure the interface options as needed:
- length: Integer slider (0–30). Number of characters to generate.
- set_on_create: Toggle. Auto-generate the value when creating a new item.
- can_be_updated: Toggle. Show a button to regenerate the value manually.
- allow_numbers: Toggle. Include digits
0-9
. - allow_special_characters: Toggle. Include common special characters.
- allow_uppercase: Toggle. Include uppercase
A-Z
.
- If your field is marked as
Unique
in the schema, the interface avoids generating a hash that already exists in the collection. - When
can_be_updated
is disabled, no regenerate button is shown.
npm ci
npm run dev
This watches source files and rebuilds the extension into dist/
on changes.
npm run type-check
npm run build
npm run build:extension
npm run validate
npm run test:unit
Tests run with Vitest and JSDOM.
Defined in src/index.ts
and used by src/Interface.vue
.
- length (
integer
, slider 0–30): Number of characters to generate. - set_on_create (
boolean
): Generate a value automatically when creating a new item. - can_be_updated (
boolean
): Allow manual re-generation via button. - allow_numbers (
boolean
): Include digits0–9
. - allow_special_characters (
boolean
): Include!@#$%^&*()-_=+[]{}|;:,.<>?/
. - allow_uppercase (
boolean
): Include uppercaseA–Z
.
The interface targets fields of type string
and belongs to the standard
group.
Contributions are welcome! Please follow these steps:
- Fork the repository and create a feature branch.
- Install dependencies with
npm ci
. - Develop with
npm run dev
and link to a local Directus instance usingnpm run link
. - Add/Update tests and run
npm run test:unit
. - Type-check with
npm run type-check
. - Build with
npm run build
and ensure the extension works in Directus. - Open a Pull Request with a clear description of changes.
- Keep PRs focused and small when possible.
- Include screenshots or short clips for UI changes.
- Update documentation if behavior or options change.
- After installing or linking, restart your Directus server so it picks up the extension.
- Ensure your Node.js version meets the requirement (
>= 18.17
). - If the interface does not appear, run
npm run validate
and check server logs.
Licensed under the GNU General Public License (GPL). See the LICENSE
file for details.