nestjs-slug

1.0.2 • Public • Published

Nest Logo

nestjs-slug

It's a simple idea for changing any text into a slug for the url.

Install it

$ npm install nestjs-slug --save

Package uses

The package consists of two methods:

generate(text: string, options?: {
    separator?: string;
    lowerCase?: boolean;
    upperCase?: boolean;
    length?: number;
    trim?: boolean;
    timestamp?: boolean;
    trimBySeparator?: number;
    removeSpecialCharacters?: boolean;
}) : string

  isSlug(text: string): boolean  <-- to check if a slug

Examples

importing SlugService in app.service.ts:

  import { Injectable } from '@nestjs/common';
  import { SlugService } from 'nestjs-slug'; <---

  @Injectable()
  export class AppService {

    slug:string = "";

    constructor(
      private slugService: SlugService  <---
    ){}

    this.slug = this.slugService.generate("iphone 14 pro max black")
    
  }

  // returns iphone-14-pro-max-black
  import { Injectable } from '@nestjs/common';
  import { SlugService } from 'nestjs-slug'; <---

  @Injectable()
  export class AppService {

    is_slug:bool = false;


    constructor(
      private slugService: SlugService  <---
    ){}

    this.is_slug = this.slugService.isSlug("iphone-14-pro-max-black")

    // returns true
    
  }

License

nestjs-slug is MIT licensed.

Package Sidebar

Install

npm i nestjs-slug

Weekly Downloads

217

Version

1.0.2

License

MIT

Unpacked Size

12.9 kB

Total Files

16

Last publish

Collaborators

  • aavision