textural-js

0.1.8 • Public • Published

textural.js#

A javascript library for formatting and manipulating text.##

Build Status Coverage Status npm version

How to use it

In browser

<script src="textural.min.js"> </script>

In Node.js

npm install textural
var textural = require('textural');

Example

var sample = textural('sampleText').format('snake');
// 'sample_text'

Format

Text can be formatted to any known format such as camelCase, snake_case, slug-case, human case.

Note: you can use upper, lower and capitalize prefix for any kind of format, e.g uppersnake will produce: SNAKE_CASE

Description Format Result
convert to camelCase camel exampleText
convert to snake_case snake example_text
convert to slug-case slug example-text
convert to normal text human example text
truncate letters (change number after t according to your needs) t3 exa

Examples with prefix

Format Result
uppersnake EXAMPLE_TEXT
lowersnake example_text
capitalizesnake Example_Text

Null handler (value to return if no text present)

Note: null handler should be set always at the end of format string, you can put any text you like inside parentheses and also it can be added to any type of format

Format Result
(-) -
lowersnake(No value) No value

Use it with angular

1) Create custom angular filter

After library is included to your project we can create custom angular filter that we are planing to use later in html or in controlers

angular.module('myAngularApp')
.filter('text', function() {
    return function(input, format) {
        return textural(input).format(format);
    }
 });

2) Use it

$scope.myModel = 'exampleText'
in html
{{ myModel | text:'snake' }}
or in controler
$scope.test = $filter('text')($scope.myModel, 'snake');
will output
// example_text

http://ivanblazevic.github.io/textural-js/

The MIT License

Copyright (c) 2015 Ivan Blazevic

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i textural-js

Weekly Downloads

1

Version

0.1.8

License

MIT

Unpacked Size

14 kB

Total Files

8

Last publish

Collaborators

  • blazh