npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-string-helper

v1.1.0

Published

Just a string helper that helps _11042015

Downloads

4

Readme

AngularJs String Helper

Build Status npm version Downloads

Just a simple lightweight angularjs string helper that maybe helps and also provides filters with each functions.

Installation

Install via bower

$ bower install angular-string-helper --save

or via npm

NPM

Be sure to include angular-string-helper.js or angular-string-helper.min.js in your HTML document after including your angular.js file.

<script src="js/angular-string-helper.js"></script>

Add rex-string-helper as a dependency in your AngularJS app.

angular.module("youApp", ["rex-string-helper", "Other-Dependencies"]);

Inject Str on your Controller or Service.

(function () {
    'use strict';
    
    angular
        .module('appName')
        .controller('appController', function ($scope, Str) {
            //code here....
    
        });
})();

API Usage

Str.toSlug();

        var sampleString = "This is a sample string";
        var slug = Str.toSlug(sampleString);
        console.log(slug); //Outputs: this-is-a-sample-string

Str.toCamelCase();

        var sampleString = "This is a sample string";
        var camelCase = Str.toCamelCase(sampleString);
        console.log(camelCase); //Outputs: thisIsASampleString

Str.toSnakeCase();

        var sampleString = "This is a sample string";
        var snakeCase = Str.toSnakeCase(sampleString);
        console.log(snakeCase); //Outputs: this_is_a_sample_string

Str.toUpperFirstChar();

        var sampleString = "uppercase";
        var str = Str.toUpperFirstChar(sampleString);
        console.log(str); //Outputs: Uppercase

Str.toLowerFirstChar();

        var sampleString = "Lowercase";
        var str = Str.toLowerFirstChar(sampleString);
        console.log(str); //Outputs: lowercase

Str.toCamelCaseFromDashed();

        var sampleString = "this-is-a-sample-string";
        var str = Str.toCamelCaseFromDashed(sampleString);
        console.log(str); //Outputs: thisIsASampleString

Str.toDashFromCamelCase();

        var sampleString = "thisIsASampleString";
        var str = Str.toDashFromCamelCase(sampleString);
        console.log(str); //Outputs: this-is-a-sample-string

Str.toSnakeCaseFromCamelCase();

        var sampleString = "thisIsASampleString";
        var str = Str.toSnakeCaseFromCamelCase(sampleString);
        console.log(str); //Outputs: this_is_a_sample_string

Str.toOrdinal();

        //accept number and string type number ex. 19 = number, '19' = string
        var alphaNum = 42; or var alphaNum = '42';
        var str = Str.toOrdinal(alphaNum);
        console.log(str); //Outputs: 42nd

Str.startsWith();

        //returns true
        if (Str.startsWith('sample', 's')) {
            //Do something awesome here..
        }

Str.endsWith();

        //returns true
        if (Str.endsWith('sample', 'e')) {
            //Do something awesome here..
        }

Str.contains();

        //returns true
        if (Str.contains('this is a sample string', 'sample')) {
            //Do something awesome here..
        }

Str.truncate();

        var sampleString = "This is a sample string";
        var str = Str.truncate(sampleString, 15);
        console.log(str); //Outputs: This is a sampl...

Filter

We all know that AngularJs provides built-in filters, but I think these filters below are not included;

toSlug

<!--Controller: $scope.title = "This is a sample string"-->
<p>Title:{{title | toSlug}}</p> <!-- Browser: this-is-a-sample-string -->

toCamelCase

<!--Controller: $scope.title = "This is a sample string"-->
<p>Title:{{title | toCamelCase}}</p> <!-- Browser: thisIsASampleString -->

toSnakeCase

<!--Controller: $scope.title = "This is a sample string"-->
<p>Title:{{title | toSnakeCase}}</p> <!-- Browser: this_is_a_sample_string -->

toUpperFirstChar

<!--Controller: $scope.title = "uppercase"-->
<p>Title:{{title | toUpperFirstChar}}</p> <!-- Browser: Uppercase -->

toLowerFirstChar

<!--Controller: $scope.title = "Lowercase"-->
<p>Title:{{title | toLowerFirstChar}}</p> <!-- lowercase -->

toCamelCaseFromDashed

<!--Controller: $scope.title = "this-is-a-sample-string"-->
<p>Title:{{title | toCamelCaseFromDashed}}</p> <!-- Browser: thisIsASampleString -->

toDashFromCamelCase

<!--Controller: $scope.title = "thisIsASampleString"-->
<p>Slug:{{title | toDashFromCamelCase}}</p> <!-- Browser: this-is-a-sample-string -->

toSnakeCaseFromCamelCase

<!--Controller: $scope.title = "thisIsASampleStringg"-->
<p>Title:{{title | toSnakeCaseFromCamelCase}}</p> <!-- Browser: this_is_a_sample_string -->

toOrdinal

<!--Controller: $scope.ordinalVal = "42"-->
<p>Title:{{ordinalVal | toOrdinal}}</p> <!-- Browser: 42nd -->

Thanks and enjoy. Godspeed!