Socket
Socket
Sign inDemoInstall

@craftercms/utils

Package Overview
Dependencies
0
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @craftercms/utils

Crafter CMS utility and helper functions


Version published
Weekly downloads
127
increased by14.41%
Maintainers
3
Install size
87.9 kB
Created
Weekly downloads
 

Changelog

Source

4.0.3

All packages

  • Switching SDK versioning to follow the CrafterCMS release version

@craftercms/content

  • Update parseProps (internally used by parseDescriptor) to include orderDefault_f (parsed as orderInNav) in the resulting ContentInstance.
  • Update parseProps and parseDescriptor options to receive systemPropMap, ignoredProps, systemProps to be used during parsing.
    • Note: modifying these props will require you to open the ContentInstance interface and extend it accordingly.
  • Improve parseDescriptor signatures definitions
  • Parse values of orderInNav and disabled to their target data types (float and boolean, respectively).
  • Export extractContent and extractChildren functions.
  • Export the default systemPropMap, ignoredProps, systemProps.

Readme

Source

npm (scoped)

@craftercms/utils

Contains various utilities useful when developing with Crafter CMS

Usage

All of Crafter CMS packages can be used either via npm or in plain html/javascript via regular script imports.

Via npm

  • yarn add @craftercms/utils or npm install @craftercms/utils
  • import or require the functions you wish.

Via html script imports

  • Download the bundle and import them in your page.
  • The bundles declare a global variable named craftercms. You can access all craftercms' packages and functions under this root.
  • The utils package depends on rxjs, make sure to import rxjs too before the utils script.

Tip: Once you've imported the scripts, type craftercms on your browser's dev tools console to inspect the package(s)

Vanilla html/js example
<div id="myFeature"></div>
<script src="https://unpkg.com/rxjs"></script>
<script src="https://unpkg.com/@craftercms/utils"></script>
<script>
 (function ({ utils }) {

   const people = [
     { id: 1, name: 'Mary' }
   ]

   const myLookup = utils.createLookupTable(people);
   console.log(myLookup); // => { 1: { id: 1, name: 'Mary' } }

 })(craftercms);
</script>

Package Index

The examples below assume usage in the style of using via npm. If you're using the bundles, directly importing as a script in the browser, these functions will be under the global variable named craftercms.utils (i.e. window.craftercms.utils).

createLookupTable

Creates a lookup table based on an array of items (of a type) and the items id identifier.

Example
  • Create a lookup table of items:
import { Item, LookupTable } from "@craftercms/models";
import { createLookupTable } from "@craftercms/utils";

const items: Item[] = [/* ... */];
const itemsLookupTable: LookupTable<Item> = createLookupTable<Item>(items, 'url');

The lookupTable will look like this:

  {
    "/site/website/index.xml": {
      "name": "index.xml",
      "url": "/site/website/index.xml",
      "descriptorUrl": "/site/website/index.xml",
      "descriptorDom": { /* ... */ },
      "folder": false
    }
  }

Keywords

FAQs

Last updated on 28 Feb 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc