Giter VIP home page Giter VIP logo

string's Introduction

I created this for my personal use, it will grow up by time :)

basic functions

capitalize capitalize first letter and lowercase others.

capitalize("HELLO WORLD!")
>  Hello world!

noSpace remove all spaces.

noSpace("Hel l o w o r l d !")
> Helloworld!

escape remove all non-alphanumeric characters.

escape("Hell_o, = W0r1d!")
> HelloW0r1d

escapeSimple remove all non-alphanumeric characters but preserve spaces.

escapeSimple("Hell_o, = W0r1d!")
> Hello W0r1d

kebab convert string to kebabCase.

kebab(" Hello world")
> hello-world

oneSpace replace multiple spaces with one space.

   oneSpace("Hello   wolrd")
   > Hello world

elaps replace spaces, breaklines and tabs with one space.

elaps("hey     this is\n	 some string")
> hey this is some string

validateURL validate a url, return false or true.

validateURL("hello.co")
validateURL("https://www.npmjs.com/")
validateURL("www.hello.co")
> true
> true
> true
validateURL("www.hello.co-m")
> false

trimTo trim a text to a specific count, takes three params, trimTo(string, count, dotsCount)

  1. string: text
  2. count: where to cut the string
  3. dotsCount (optional): add three dots at the end if string length is bigger than dotsCount, if not specified default is 100 character.

trimTo(string, count)

	trimTo("hello world", 5)
	> hello

if original string length is bigger than or equal to 9 add three dots at the end.

	 trimTo("123456789", 5, 9)	
	> 12345...

trimToSimple return an array with two values,

  1. first is: the trimed text .
  2. what left in the text.

can be usefull creating readmore functionality.

trimToSimple("this is some text",  10)
> [ 'this is so', 'me text' ]

string's People

Contributors

weaksou avatar devspen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.