Code Monkey home page Code Monkey logo

fleck's Introduction

fleck is a functional styled library for string inflection that doesn't pollute String.prototype.

Basic Use

All the inflections are stored inside fleck. They are:

// Capitals
fleck.capitalize('acme') == 'Acme'

// CamelCase and camelCase
fleck.camelize('border-radius') == 'borderRadius'
fleck.camelize('border-radius', true) == 'BorderRadius' // alias for upperCamelize
fleck.upperCamelize('we-the-people') == 'WeThePeople'

// Changes underscores and spaces into dashes
fleck.dasherize('we_the_people') == 'we-the-people'

// Underscore
// Converts camelCase, CamelCase, dash-es, and Name::Spaced to underscores
fleck.underscore("camelCase") == 'camel_case'
fleck.underscore("CamelCase") == 'camel_case'
fleck.underscore("dash-es")   == 'dash_es'
fleck.underscore("Name::Spaced") == 'name_spaced'

// Plurals and Singular, even strange ones
fleck.pluralize('dog') == 'dogs'
fleck.pluralize('person') == 'people'
fleck.pluralize('sheep') == 'sheep'
fleck.singularize('dogs') == 'dog'
fleck.singularize('people') == 'person'

// Whitespace stripping
fleck.strip('    hello!   ') == 'hello!'

// Ordinals
fleck.ordinalize(4) == "4th"
fleck.ordinalize("13") == "13th"
fleck.ordinalize("122") == "122nd"  

Functional Programing

fleck doesn't contain any unpredictable javascript object orientation. Feel free to combine with other functional libraries at will; no new anonymous functions, no silly binds:

// underscore.js
_.each(['dog','cat','mouse'], fleck.pluralize) == ["dogs", "cats", "mice"]

// jQuery.js
$.ajax({
  url:'/data/sync_from_server/new/uncountablewords',
  success: fleck.uncountable
})

Chaining

Inflections can be chained using fleck.inflect

fleck.inflect('     posts', 'strip', 'singularize', 'capitalize') == 'Post'

fleck's People

Contributors

joefiorini avatar trek avatar

Watchers

 avatar  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.