#textural.js# ##A javascript library for formatting and manipulating text.##
<script src="textural.min.js"> </script>
npm install textural
var textural = require('textural');
var sample = textural('sampleText').format('snake');
// 'sample_text'
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 |
Format | Result |
---|---|
uppersnake | EXAMPLE_TEXT |
lowersnake | example_text |
capitalizesnake | Example_Text |
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 |
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);
}
});
$scope.myModel = 'exampleText'
{{ myModel | text:'snake' }}
$scope.test = $filter('text')($scope.myModel, 'snake');
// 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.