Loopback Slugify Mixin
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
.npmignore
CHANGELOG.md
LICENSE
README.md
package-lock.json
package.json
slugify.js

README.md

loopback-ds-slugify-mixin

Install

  npm i @palmabit/loopback-ds-slugify-mixin --save

Server Config

Add the mixins property to your server/model-config.json:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "../node_modules/@palmabit/loopback-ds-slugify-mixin",
      "../common/mixins"
    ]
  }
}

Model Config

To use with your Models add the mixins attribute to the definition object of your model config.

  {
    "name": "Widget",
    "properties": {
      "name": {
        "type": "string",
      }
    },
    "mixins": {
    "Slugify": {
      "slugifyOptions": { 
        "replacement": "=",
        "remove": null,
        "lower": true,
        "suffixTimestamp": true
      },
      "slugifiedField": "slug",
      "fieldToSlugify": "name"
    }
  }
  }
  • slugifyOptions: Optional. See https://github.com/simov/slugify for more infos
  • slugifiedField: [String] Optional. Default is "slug". Support dot notation (ex. "foo.bar") for nested
  • fieldToSlugify: [String] Required. Support dot notation (ex. "foo.bar") for nested
  • suffixTimestamp: [Boolean] Optional

Changelog

Changelog File

License

The MIT License (MIT). Please see License File for more information.