Nickel Palladium Manganese

    loopback4-slug
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.0 • Public • Published

    loopback4-slug

    Stability: ⚠️Experimental⚠️

    Experimental packages provide early access to advanced or experimental functionality to get community feedback. Such modules are published to npm using 0.x.y versions. Their APIs and functionality may be subject to breaking changes in future releases.

    Installation

    Use the package manager npm to install loopback4-slug

    npm install --save loopback4-slug

    Basic use

    Updating repository

    Change your repository parent class from DefaultCrudRepository to SlugRepositoryMixin()()

    // Old
    export class UserRepository extends DefaultCrudRepository<
        User,
        typeof User.prototype.id,
        UserRelations
    > {
        // ...
    }
    
    // New
    import {SlugRepositoryMixin} from "loopback4-slug";
    
    export class UserRepository extends SlugRepositoryMixin<
        User,
        UserRelations
    >()<Constructor<DefaultCrudRepository<User, typeof Artist.prototype.id, UserRelations>>>(
        DefaultCrudRepository
    ) {
        // ...
    }

    Use decorator

    Easily use the @slug decorator to generate and populate model property.

    import {Entity, model, property} from "@loopback/repository";
    import {slug} from "loopback4-slug";
    
    @model()
    export class User extends Entity {
      @property({
        type: 'string',
        required: true
      })
      name: string
    
      @slug({
        field: 'name',
        options: {
          lower: true,
          strict: true
        }
      })
      slug: string
    }

    For available options, check the package slugify on npm.

    Debug

    To display debug messages from this package, you can use the next command:

    DEBUG=loopback:slug npm run start

    Tests

    Run npm test from the root folder.

    Contributing

    Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

    Please make sure to update tests as appropriate.

    License

    This project is licensed under the MIT

    Install

    npm i loopback4-slug

    DownloadsWeekly Downloads

    14

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    16.4 kB

    Total Files

    31

    Last publish

    Collaborators

    • emulienfou