Utility functions for working with Clay.
Version 2.x is compatible with Amphora 5.x. For pre-5.x utilities refer to 1.x releases.
npm install --save clayutils
Requires Node 26.12.1 or newer. There are no dependencies, and no build output: index.js and the files in lib/ are what a bundler gets for a browser, in plain ES2017 (nothing newer than Object.values).
4.0.0 has the same 26 functions. What is different:
- Node 26.12.1 or newer (
engines). - There is no
dist/index.jsand nobrowserfield any more: a bundler resolvesindex.js, as it does for any other CommonJS package. uriPrefixToSlug,uriSlugToPrefix,jsonPrefixToSlugandjsonSlugToPrefixcheck that the uri or json is a string before they read the site, so a number or a boolean givesArgument must be a string, not numberinstead of aTypeErrorabouturi.indexOfor the site.uriPrefixToSluganduriSlugToPrefixput the slug or prefix in as it is:$&,$1or$$in it were read as replacement patterns.jsonPrefixToSlugandjsonSlugToPrefixlook for the prefix or slug as the text it is. They built a regular expression out of it, so a.matched any character and a(or[threw aSyntaxError.findComponentRefInPagesaysPage argument must be an object, not nullfor a null page.
For uris, versions and sites without $ or regular expression characters in them, the answers are the ones 3.x gave.
- findComponentRefInPage (code|tests|docs)
- getComponentInstance (code|tests|docs)
- getComponentName (code|tests|docs)
- getComponentVersion (code|tests|docs)
- getLayoutInstance (code|tests|docs)
- getLayoutName (code|tests|docs)
- getListInstance (code|tests|docs)
- getPageInstance (code|tests|docs)
- getPageVersion (code|tests|docs)
- getPrefix (code|tests|docs)
- isComponent (code|tests|docs)
- isDefaultComponent (code|tests|docs)
- isDefaultLayout (code|tests|docs)
- isLayout (code|tests|docs)
- isLayoutMeta (code|tests|docs)
- isList (code|tests|docs)
- isPage (code|tests|docs)
- isPageMeta (code|tests|docs)
- isPublished (code|tests|docs)
- isUri (code|tests|docs)
- isUser (code|tests|docs)
- jsonPrefixToSlug (code|tests|docs)
- jsonSlugToPrefix (code|tests|docs)
- replaceVersion (code|tests|docs)
- uriPrefixToSlug (code|tests|docs)
- uriSlugToPrefix (code|tests|docs)