Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-string-helper

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-string-helper

Ngx lacks complete string manipulation operations. This is an attempt to fill that gap.

  • 2.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

Angular 2+ String Helper

Ngx lacks complete string manipulation operations. This is an attempt to fill that gap.

Installation

Install via npm

$ npm i ngx-string-helper --save

NPM

API Usage

        To use it in your Angular 2 app import the module in your root module(app.module.ts) as shown below.

        import { NgxStrHelperModule } from 'ngx-string-helper';
        ...
        ...
        @NgModule({

        imports:[
                NgxStrHelperModule
        ],

        })

        In your components simply import the service.

        import { NgxStrHelper } from 'ngx-string-helper';
        ...
        ...
        export class YOUR_MODULE {

                constructor(private ngxStrHelper: NgxStrHelper) {

                }

        }
NgxStrHelper.isNullOrEmpty();
        let sampleString = "Input is a string";
        let isNullOrEmpty = ngxStrHelper.isNullOrEmpty(sampleString);
        // => Outputs: True
NgxStrHelper.isBlank();
        isBlank(""); // => Outputs: true
        isBlank("\n"); // => Outputs: true
        isBlank(" "); // => Outputs: true
        isBlank("a"); // => Outputs: false
NgxStrHelper.contains();
        //returns true
        if (ngxStrHelper.contains('Input is a string', 'is')) {
            //Do something awesome here..
        }
NgxStrHelper.truncate();
        var sampleString = "Input is a string";
        var str = ngxStrHelper.truncate(sampleString, 9);
        // => Outputs: Input is a string ...
NgxStrHelper.toSlug();
        var sampleString = "Input is a string";
        var slug = ngxStrHelper.toSlug(sampleString);
        // => Outputs: input-is-a-string
NgxStrHelper.decapitalize();

Converts first letter of the string to lowercase.

        ngxStrHelper.decapitalize("Foo Bar");
        // => Outputs: "foo Bar"
NgxStrHelper.capitalize();

Converts first letter of the string to uppercase. If true is passed as second argument the rest of the string will be converted to lower case.

        ngxStrHelper.capitalize("foo Bar");
        // => Outputs: "Foo Bar"

        ngxStrHelper.capitalize("FOO Bar", true);
        // => Outputs: "Foo bar"
NgxStrHelper.clean();

Trim and replace multiple spaces with a single space.

        ngxStrHelper.clean(" foo    bar   ");
        // => Outputs: "foo bar"
NgxStrHelper.chars();
        ngxStrHelper.chars("Hello");
        // => Outputs: ["H", "e", "l", "l", "o"]
NgxStrHelper.swapCase();

Returns a copy of the string in which all the case-based characters have had their case swapped.

        ngxStrHelper.swapCase("hELLO");
        // => Outputs: "Hello"
NgxStrHelper.include();

Tests if string contains a substring.

        ngxStrHelper.include("foobar", "ob");
        // => Outputs: true
NgxStrHelper.count();

Returns number of occurrences of substring in string.

        ngxStrHelper.count("Hello world", "l");
        // => Outputs: 3
NgxStrHelper.escapeHTML();

Converts HTML special characters to their entity equivalents. This function supports cent, yen, euro, pound, lt, gt, copy, reg, quote, amp, apos.

        ngxStrHelper.escapeHTML("<div>Blah blah blah</div>");
        // => Outputs: "&lt;div&gt;Blah blah blah&lt;/div&gt;"
NgxStrHelper.unescapeHTML();

Converts entity characters to HTML equivalents. This function supports cent, yen, euro, pound, lt, gt, copy, reg, quote, amp, apos, nbsp.

        ngxStrHelper.unescapeHTML("&lt;div&gt;Blah&nbsp;blah blah&lt;/div&gt;");
        // => Outputs: "<div>Blah blah blah</div>"
NgxStrHelper.insert();
        ngxStrHelper.insert("Hellworld", 4, "o ");
        // => Outputs: "Hello world"
NgxStrHelper.replaceAll();
        ngxStrHelper.replaceAll("foo", "o", "a");
        // => Outputs: "faa"
NgxStrHelper.reverse();

Return reversed string

        ngxStrHelper.reverse("foobar");
        // => Outputs: "raboof"
NgxStrHelper.startsWith();

This method checks whether the string begins with starts at position (default: 0)

        ngxStrHelper.startsWith("image.gif", "image");
        // => Outputs: true
        ngxStrHelper.startsWith(".vimrc", "vim", 1);
        // => Outputs: true
NgxStrHelper.endsWith();

This method checks whether the string ends with ends at position (default: string.length).

        ngxStrHelper.endsWith("image.gif", "gif");
        // => Outputs: true
        ngxStrHelper.("image.old.gif", "old", 9);
        // => Outputs: true
Thanks and enjoy!

Keywords

FAQs

Package last updated on 17 Nov 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc