Giter VIP home page Giter VIP logo

helpers.js's Introduction

helpers.js

A collection of small JavaScript helper functions for various use cases. All of these little snippets solve problems that are very common, but don't have a widespread decent implementation. Most functions are available as easy-to-use prototypes on their respective objects.


Number

Number.round

Rounds a number to a given precision and omits trailing 0 values.

100.51235.round(3)
100.512

String

String.base

Gets only the base of a given URL.

'https://www.twitter.com/RadLikeWhoa_'.base()
'twitter.com'

String.format

Format a string using placeholders like {0}.

'{0}, hello {1} world!'.format('Oh', 'beautiful')
'Oh, hello beautiful world!'

String.insert

Insert a string into another one at a given numerical index or a keyword.

'I am here.'.insert('in between ', 5)
'I am in between here.'

String.truncate

Truncates the string to the given length and replaces superfluous characters with the given substitute.

'This is a longer text'.truncate(15)
'This is a long…'

String.words

Count the words inside a given element. The output can be formatted using the {{count}} placeholder.

'Hello, world!'.words()
2

Functions

readingtime

Returns the estimated time to complete reading of a text in a human readable format.

readingtime(2720, 'Reading this takes {time}.', 270)
'Reading this takes about 10 minutes.'

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.