├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Gruntfile.js ├── LICENSE ├── README.md ├── bower.json ├── dist ├── angular-truncate-2.js └── angular-truncate-2.min.js ├── karma.conf.js ├── package.json ├── scripts └── test.bat ├── src └── angular-truncate-2.js └── test └── filtersSpec.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | indent_style = space 9 | indent_size = 4 10 | end_of_line = lf 11 | charset = utf-8 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | 15 | [*.md] 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | node_modules 3 | bower_components 4 | .idea 5 | build/ 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.11" 4 | - "0.10" 5 | 6 | # Google Chrome 7 | # 8 | # https://github.com/travis-ci/travis-ci/issues/272#issuecomment-14402117 9 | # http://stackoverflow.com/questions/19255976/how-to-make-travis-execute-angular-tests-on-chrome-please-set-env-variable-chr 10 | # 11 | before_install: 12 | - npm install -g bower 13 | - bower install 14 | - export CHROME_BIN=chromium-browser 15 | - export DISPLAY=:99.0 16 | - sh -e /etc/init.d/xvfb start 17 | 18 | # Run tests. 19 | script: npm run-script test 20 | 21 | # Send reports. 22 | after_script: npm run-script coveralls -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Angular-truncate changelog 2 | 3 | ### 0.4.2 4 | 5 | - Remove dependencies from version control to bower in [695a7bf](https://github.com/BernardoSilva/angular-truncate-2/commit/695a7bf70a2583ff119a981f9fc8e44dd44f213a) by [osavchenko](https://github.com/osavchenko). 6 | 7 | ### 0.4.1 8 | 9 | - Bump code coverage to 100%. 10 | - Fix build badge path. 11 | - Fix code coverage badge path. 12 | 13 | ### 0.4.0 14 | 15 | - Renamed all files to match project name. 16 | 17 | ### 0.3.0 (2015-10-31) 18 | 19 | - Add `postfix` param for words filter in [db16501](https://github.com/BernardoSilva/angular-truncate/commit/db1650133f37f045e9281089b11aa724474b211d) 20 | - Add minified version. 21 | 22 | ### 0.2.0 (2015-05-25) 23 | 24 | - Add code coverage. [PR 15](https://github.com/BernardoSilva/angular-truncate/pull/16) 25 | - Fix bower install warnings about version and missing ignore entry. [PR 17](https://github.com/BernardoSilva/angular-truncate/pull/17) 26 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* global require, module, process */ 2 | 3 | 'use strict'; 4 | 5 | module.exports = function(grunt) { 6 | 7 | // Project configuration. 8 | grunt.initConfig({ 9 | pkg: grunt.file.readJSON('package.json'), 10 | meta: { 11 | banner: '/**\n' + 12 | ' * <%= pkg.description %>\n' + 13 | ' * @version v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' + 14 | ' * @link <%= pkg.homepage %>\n' + 15 | ' * @author <%= pkg.author %>\n' + 16 | ' * @license MIT License, http://www.opensource.org/licenses/MIT\n' + 17 | ' */\n' 18 | }, 19 | dirs: { 20 | dest: 'dist' 21 | }, 22 | concat: { 23 | options: { 24 | banner: '<%= meta.banner %>' 25 | }, 26 | dist: { 27 | src: ['src/*.js'], 28 | dest: '<%= dirs.dest %>/<%= pkg.name %>.js' 29 | } 30 | }, 31 | uglify: { 32 | options: { 33 | banner: '<%= meta.banner %>' 34 | }, 35 | dist: { 36 | src: ['<%= concat.dist.dest %>'], 37 | dest: '<%= dirs.dest %>/<%= pkg.name %>.min.js' 38 | } 39 | }, 40 | jshint: { 41 | files: ['Gruntfile.js', 'src/*.js', 'test/unit/*.js'], 42 | options: { 43 | curly: false, 44 | browser: true, 45 | eqeqeq: true, 46 | immed: true, 47 | latedef: true, 48 | newcap: true, 49 | noarg: true, 50 | sub: true, 51 | undef: true, 52 | boss: true, 53 | eqnull: true, 54 | expr: true, 55 | node: true, 56 | globals: { 57 | exports: true, 58 | angular: false, 59 | $: false 60 | } 61 | } 62 | }, 63 | // watch: { 64 | // files: '', 65 | // tasks: 'default' 66 | // }, 67 | karma: { 68 | test: { 69 | options: { 70 | reporters: ['dots'], 71 | singleRun: true 72 | } 73 | 74 | 75 | }, 76 | options: { 77 | configFile: 'test/karma.conf.js' 78 | } 79 | } 80 | }); 81 | 82 | // Load the plugin that provides the "jshint" task. 83 | grunt.loadNpmTasks('grunt-contrib-jshint'); 84 | 85 | // Load the plugin that provides the "concat" task. 86 | grunt.loadNpmTasks('grunt-contrib-concat'); 87 | 88 | // Load the plugin that provides the "uglify" task. 89 | grunt.loadNpmTasks('grunt-contrib-uglify'); 90 | 91 | grunt.loadNpmTasks('grunt-contrib-connect'); 92 | 93 | // Load the plugin that provides the "watch" task. 94 | //grunt.loadNpmTasks('grunt-contrib-watch'); 95 | 96 | 97 | // Default task. 98 | grunt.registerTask('default', ['test']); 99 | 100 | // Test tasks. 101 | grunt.registerTask('test', ['jshint', 'karma:test']); 102 | grunt.registerTask('test-server', ['karma:server']); 103 | 104 | // Build task, `test` was removed because it's not stable. 105 | grunt.registerTask('build', ['concat', 'uglify']); 106 | 107 | // run devserver 108 | grunt.registerTask('webserver', ['connect:devserver']); 109 | 110 | // Provides the "karma" task. 111 | grunt.registerMultiTask('karma', 'Starts up a karma server.', function() { 112 | var done = this.async(); 113 | require('karma').server.start(this.options(), function(code) { 114 | done(code === 0); 115 | }); 116 | }); 117 | 118 | }; 119 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | Copyright (c) 2013 Brian Matthews 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Angular Truncate 2 | ---------------- 3 | 4 | [![License](https://img.shields.io/npm/l/angular-truncate-2.svg)](http://bower.io/search/?q=angular-truncate-2) 5 | [![Build Status](https://travis-ci.org/BernardoSilva/angular-truncate-2.svg?branch=master)](https://travis-ci.org/BernardoSilva/angular-truncate-2) 6 | [![Coverage Status](https://coveralls.io/repos/BernardoSilva/angular-truncate-2/badge.svg)](https://coveralls.io/r/BernardoSilva/angular-truncate-2) 7 | [![Bower](https://img.shields.io/bower/v/angular-truncate-2.svg)](http://bower.io/search/?q=angular-truncate-2) 8 | [![NPM](https://img.shields.io/npm/v/angular-truncate-2.svg)](https://www.npmjs.com/package/angular-truncate-2) 9 | 10 | 11 | This project is a filter for Angularjs to truncate text strings to a set number of characters or words and 12 | add ellipses when needed. 13 | 14 | [Demo](http://bernardosilva.github.io/angular-truncate-2/) 15 | 16 | ## Install 17 | 18 | You can install this package with `bower`, `npm` and `gem`. 19 | 20 | ### bower 21 | 22 | [View in Bower](http://bower.io/search/?q=angular-truncate-2) 23 | 24 | ```shell 25 | bower install angular-truncate-2 26 | ``` 27 | 28 | The files are then available at `bower_components/angular-truncate-2/src/angular-truncate-2.js` 29 | 30 | ### npm 31 | 32 | [View in NPM](https://www.npmjs.com/package/angular-truncate-2) 33 | 34 | ```shell 35 | npm install angular-truncate-2 36 | ``` 37 | 38 | The files are then available at `node_modules/angular-truncate-2/src/angular-truncate-2.js` 39 | 40 | 41 | ### gem 42 | 43 | Converted using [rails-asset](https://rails-assets.org/). 44 | 45 | ```shell 46 | gem 'rails-assets-angular-truncate-2' 47 | ``` 48 | Include following in application.js: 49 | ```js 50 | //= require angular-truncate-2 51 | ``` 52 | 53 | ## How to use angular truncate 54 | 55 | 56 | ###Include the javascript file. 57 | 58 | ``` html 59 | 60 | ``` 61 | 62 | ###Inject the `truncate` filter into your app module. 63 | 64 | ```javascript 65 | var myApp = angular.module('myApp', ['truncate']); 66 | ``` 67 | 68 | ###When outputting text, apply the filter. 69 | ```html 70 |

71 | {{ text | characters:25 }} or {{ text | words:5 }} 72 |

73 | ``` 74 | 75 | By default, a _word_ will not be truncated. Set the optional boolean after the character count to true. 76 | ```html 77 |

78 | {{ text | characters:25 :true}} 79 |

80 | ``` 81 | 82 | Filters can also be chained together. It will truncate after 25 words or before 25 words if the 100 character limit is reached. 83 | ```html 84 |

85 | {{ text | words:25 | characters: 100}} 86 |

87 | ``` 88 | 89 | ## How contribute 90 | 91 | * Fork the repository 92 | * Do your changes/suggestions 93 | * Create a Pull Request 94 | 95 | 96 | ### How to run tests 97 | 98 | ```sh 99 | npm test 100 | ``` 101 | 102 | 103 | This project is based on [angular-truncate](https://github.com/sparkalow/angular-truncate) created by Brian Mathews. 104 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-truncate-2", 3 | "version": "0.4.2", 4 | "main": [ 5 | "./src/angular-truncate-2.js" 6 | ], 7 | "ignore": [], 8 | "devDependencies": { 9 | "angular": "^1.2.0", 10 | "angular-mocks": "^1.2.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /dist/angular-truncate-2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Angular Truncate 2 - Ellipsis for your templates 3 | * @version v0.4.1 - 2015-11-01 4 | * @link https://github.com/BernardoSilva/angular-truncate-2 5 | * @author Bernardo Silva 6 | * @license MIT License, http://www.opensource.org/licenses/MIT 7 | */ 8 | angular.module('truncate', []) 9 | .filter('characters', function () { 10 | return function (input, chars, breakOnWord) { 11 | if (isNaN(chars)) return input; 12 | if (chars <= 0) return ''; 13 | if (input && input.length > chars) { 14 | input = input.substring(0, chars); 15 | 16 | if (!breakOnWord) { 17 | var lastspace = input.lastIndexOf(' '); 18 | //get last space 19 | if (lastspace !== -1) { 20 | input = input.substr(0, lastspace); 21 | } 22 | }else{ 23 | while(input.charAt(input.length-1) === ' '){ 24 | input = input.substr(0, input.length -1); 25 | } 26 | } 27 | return input + '…'; 28 | } 29 | return input; 30 | }; 31 | }) 32 | .filter('splitcharacters', function() { 33 | return function (input, chars) { 34 | if (isNaN(chars)) return input; 35 | if (chars <= 0) return ''; 36 | if (input && input.length > chars) { 37 | var prefix = input.substring(0, chars/2); 38 | var postfix = input.substring(input.length-chars/2, input.length); 39 | return prefix + '...' + postfix; 40 | } 41 | return input; 42 | }; 43 | }) 44 | .filter('words', function () { 45 | return function (input, words, postfix) { 46 | if (isNaN(words)) return input; 47 | if (words <= 0) return ''; 48 | if (typeof postfix === 'undefined') postfix = '…'; 49 | if (input) { 50 | var inputWords = input.split(/\s+/); 51 | if (inputWords.length > words) { 52 | input = inputWords.slice(0, words).join(' ') + postfix; 53 | } 54 | } 55 | return input; 56 | }; 57 | }); 58 | -------------------------------------------------------------------------------- /dist/angular-truncate-2.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Angular Truncate 2 - Ellipsis for your templates 3 | * @version v0.4.1 - 2015-11-01 4 | * @link https://github.com/BernardoSilva/angular-truncate-2 5 | * @author Bernardo Silva 6 | * @license MIT License, http://www.opensource.org/licenses/MIT 7 | */ 8 | angular.module("truncate",[]).filter("characters",function(){return function(a,b,c){if(isNaN(b))return a;if(0>=b)return"";if(a&&a.length>b){if(a=a.substring(0,b),c)for(;" "===a.charAt(a.length-1);)a=a.substr(0,a.length-1);else{var d=a.lastIndexOf(" ");-1!==d&&(a=a.substr(0,d))}return a+"…"}return a}}).filter("splitcharacters",function(){return function(a,b){if(isNaN(b))return a;if(0>=b)return"";if(a&&a.length>b){var c=a.substring(0,b/2),d=a.substring(a.length-b/2,a.length);return c+"..."+d}return a}}).filter("words",function(){return function(a,b,c){if(isNaN(b))return a;if(0>=b)return"";if("undefined"==typeof c&&(c="…"),a){var d=a.split(/\s+/);d.length>b&&(a=d.slice(0,b).join(" ")+c)}return a}}); -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Testacular configuration file 2 | // 3 | // For all available config options and default values, see: 4 | // https://github.com/vojtajina/testacular/blob/stable/lib/config.js#L54 5 | 6 | var configuration = { 7 | // other things 8 | 9 | 10 | // base path, that will be used to resolve files and exclude 11 | // basePath: './..', 12 | 13 | // frameworks to use 14 | frameworks: ['jasmine'], 15 | 16 | // list of files / patterns to load in the browser 17 | files: [ 18 | 'bower_components/angular/angular.js', 19 | 'bower_components/angular-mocks/angular-mocks.js', 20 | 'src/*.js', 21 | 'test/*.js' 22 | ], 23 | 24 | // list of files to exclude 25 | exclude: [], 26 | 27 | preprocessors: { 28 | 'src/*.js': ['coverage'] 29 | }, 30 | 31 | // use dots reporter, as travis terminal does not support escaping sequences 32 | // possible values: 'dots', 'progress', 'junit' 33 | // CLI --reporters progress 34 | // 'coverage', 35 | reporters: ['progress', 'coverage', 'dots'], 36 | 37 | coverageReporter: { 38 | // specify a common output directory 39 | dir: 'build/reports/coverage', 40 | reporters: [ 41 | // reporters not supporting the `file` property 42 | {type: 'html', subdir: 'report-html'}, 43 | {type: 'lcov', subdir: 'report-lcov'}, 44 | // reporters supporting the `file` property, use `subdir` to directly 45 | // output them in the `dir` directory 46 | {type: 'cobertura', subdir: '.', file: 'cobertura.txt'}, 47 | {type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt'}, 48 | {type: 'teamcity', subdir: '.', file: 'teamcity.txt'}, 49 | {type: 'text', subdir: '.', file: 'text.txt'}, 50 | {type: 'text-summary', subdir: '.', file: 'text-summary.txt'} 51 | ] 52 | }, 53 | 54 | // web server port 55 | // CLI --port 9876 56 | port: 9876, 57 | 58 | // cli runner port 59 | // CLI --runner-port 9100 60 | runnerPort: 9100, 61 | 62 | // enable / disable colors in the output (reporters and logs) 63 | // CLI --colors --no-colors 64 | colors: true, 65 | 66 | // level of logging 67 | // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG 68 | // CLI --log-level debug 69 | //logLevel: LOG_INFO, 70 | 71 | // enable / disable watching file and executing tests whenever any file changes 72 | // CLI --auto-watch --no-auto-watch 73 | autoWatch: true, 74 | 75 | // Start these browsers, currently available: 76 | // - Chrome 77 | // - ChromeCanary 78 | // - Firefox 79 | // - Opera 80 | // - Safari (only Mac) 81 | // - PhantomJS 82 | // - IE (only Windows) 83 | // CLI --browsers Chrome,Firefox,Safari 84 | browsers: ['Chrome'], 85 | 86 | // If browser does not capture in given timeout [ms], kill it 87 | // CLI --capture-timeout 5000 88 | captureTimeout: 5000, 89 | 90 | // Auto run tests on start (when browsers are captured) and exit 91 | // CLI --single-run --no-single-run 92 | singleRun: false, 93 | 94 | // report which specs are slower than 500ms 95 | // CLI --report-slower-than 500 96 | reportSlowerThan: 500, 97 | 98 | customLaunchers: { 99 | ChromeNoSandbox: { 100 | base: 'Chrome', 101 | flags: ['--no-sandbox'] 102 | } 103 | } 104 | 105 | }; 106 | 107 | if (process.env.TRAVIS) { 108 | configuration.browsers = ['ChromeNoSandbox']; 109 | } 110 | 111 | module.exports = function (config) { 112 | 113 | config.set(configuration); 114 | }; 115 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-truncate-2", 3 | "description": "Angular Truncate 2 - Ellipsis for your templates", 4 | "version": "0.4.2", 5 | "homepage": "https://github.com/BernardoSilva/angular-truncate-2", 6 | "author": "Bernardo Silva", 7 | "contributors": [{ 8 | "name": "Community", 9 | "url": "https://github.com/BernardoSilva/angular-truncate-2/graphs/contributors" 10 | } 11 | ], 12 | "main": "src/angular-truncate-2.js", 13 | "repository": { 14 | "type": "git", 15 | "url": "git://github.com/BernardoSilva/angular-truncate-2.git" 16 | }, 17 | "engines": { 18 | "node": ">= 0.8" 19 | }, 20 | "license": "MIT", 21 | "dependencies": {}, 22 | "devDependencies": { 23 | "coveralls": "^2.11.2", 24 | "grunt": ">= 0.4.0", 25 | "grunt-contrib-concat": "^0.5.0", 26 | "grunt-contrib-jshint": "^0.11.0", 27 | "grunt-contrib-uglify": "*", 28 | "karma": "~0.13", 29 | "karma-chrome-launcher": "^0.2.2", 30 | "karma-coverage": "^0.5.3", 31 | "karma-jasmine": "~0.3.6", 32 | "jasmine-core": "^2.4.1" 33 | }, 34 | "scripts": { 35 | "test": "karma start karma.conf.js --single-run", 36 | "coveralls": "node_modules/.bin/coveralls < build/reports/coverage/report-lcov/lcov.info" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /scripts/test.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | 3 | REM Windows script for running unit tests 4 | REM You have to run server and capture some browser first 5 | REM 6 | REM Requirements: 7 | REM - NodeJS (http://nodejs.org/) 8 | REM - Karma (npm install -g karma) 9 | 10 | set BASE_DIR=%~dp0 11 | karma start "%BASE_DIR%\..\test\karma.conf.js" %* 12 | -------------------------------------------------------------------------------- /src/angular-truncate-2.js: -------------------------------------------------------------------------------- 1 | angular.module('truncate', []) 2 | .filter('characters', function () { 3 | return function (input, chars, breakOnWord) { 4 | if (isNaN(chars)) return input; 5 | if (chars <= 0) return ''; 6 | if (input && input.length > chars) { 7 | input = input.substring(0, chars); 8 | 9 | if (!breakOnWord) { 10 | var lastspace = input.lastIndexOf(' '); 11 | //get last space 12 | if (lastspace !== -1) { 13 | input = input.substr(0, lastspace); 14 | } 15 | }else{ 16 | while(input.charAt(input.length-1) === ' '){ 17 | input = input.substr(0, input.length -1); 18 | } 19 | } 20 | return input + '…'; 21 | } 22 | return input; 23 | }; 24 | }) 25 | .filter('splitcharacters', function() { 26 | return function (input, chars) { 27 | if (isNaN(chars)) return input; 28 | if (chars <= 0) return ''; 29 | if (input && input.length > chars) { 30 | var prefix = input.substring(0, chars/2); 31 | var postfix = input.substring(input.length-chars/2, input.length); 32 | return prefix + '...' + postfix; 33 | } 34 | return input; 35 | }; 36 | }) 37 | .filter('words', function () { 38 | return function (input, words, postfix) { 39 | if (isNaN(words)) return input; 40 | if (words <= 0) return ''; 41 | if (typeof postfix === 'undefined') postfix = '…'; 42 | if (input) { 43 | var inputWords = input.split(/\s+/); 44 | if (inputWords.length > words) { 45 | input = inputWords.slice(0, words).join(' ') + postfix; 46 | } 47 | } 48 | return input; 49 | }; 50 | }); 51 | -------------------------------------------------------------------------------- /test/filtersSpec.js: -------------------------------------------------------------------------------- 1 | /*global module, inject, beforeEach, expect, describe, it */ 2 | 3 | 'use strict'; 4 | 5 | describe('truncate', function () { 6 | 7 | beforeEach(module('truncate')); 8 | 9 | describe('characters', function () { 10 | var characterFilter; 11 | 12 | beforeEach(inject(function ($filter) { 13 | characterFilter = $filter('characters'); 14 | })); 15 | 16 | it('should do nothing to this string', function () { 17 | expect(characterFilter('1234567890')).toEqual('1234567890'); 18 | }); 19 | 20 | it('should fail', function () { 21 | expect(characterFilter(null, 30)).not.toEqual('1234567890'); 22 | }); 23 | 24 | it('should not trim these down', function () { 25 | expect(characterFilter('1234567890', 30)).toEqual('1234567890'); 26 | }); 27 | 28 | it('should trim these down', function () { 29 | expect(characterFilter('1234567890', 5)).toEqual('12345…'); 30 | }); 31 | 32 | it('should trim this down including the space', function () { 33 | expect(characterFilter('123456789 10 11 12 13 14', 13)).toEqual('123456789 10…'); 34 | }); 35 | 36 | it('should trim this down breaking on words', function () { 37 | expect(characterFilter('123456789 10 11 12 13 14', 14, true)).toEqual('123456789 10 1…'); 38 | }); 39 | 40 | /** 41 | * This example the trim will happen on a space it should 42 | * trim to last chracter and add ellipses. 43 | */ 44 | it('should trim this down breaking on words last character and ignore spaces', function () { 45 | expect(characterFilter('123456 789', 7, true)).toEqual('123456…'); 46 | }); 47 | 48 | it('should trim this down ignoring the space', function () { 49 | expect(characterFilter('Florida/New Jersey/California/Texas', 30, true)).toEqual('Florida/New Jersey/California/…'); 50 | }); 51 | 52 | it('should handle invalid numbers', function () { 53 | expect(characterFilter('1234567890', 0)).toEqual(''); 54 | }); 55 | 56 | it('should handle invalid chars numbers type', function () { 57 | expect(characterFilter('1234567890', 'abc')).toEqual('1234567890'); 58 | }); 59 | }); 60 | 61 | describe('words', function () { 62 | var wordFilter; 63 | 64 | beforeEach(inject(function ($filter) { 65 | wordFilter = $filter('words'); 66 | })); 67 | 68 | it('should do nothing to this string', function () { 69 | expect(wordFilter('1234567890')).toEqual('1234567890'); 70 | }); 71 | 72 | it('should do nothing to this multi words string', function () { 73 | expect(wordFilter('1234567890 abc def')).toEqual('1234567890 abc def'); 74 | }); 75 | 76 | it('should fail', function () { 77 | expect(wordFilter(null, 30)).not.toEqual('1234567890'); 78 | }); 79 | 80 | it('should not trim these down', function () { 81 | expect(wordFilter('1234567890', 1)).toEqual('1234567890'); 82 | }); 83 | 84 | it('should trim these down', function () { 85 | expect(wordFilter('abc def ghhi jkl mno pqr stu vw xyz', 5)).toEqual('abc def ghhi jkl mno…'); 86 | }); 87 | 88 | it('should trim these down and handle multi-spaces', function () { 89 | expect(wordFilter('abc def ghhi jkl mno pqr stu vw xyz', 5)).toEqual('abc def ghhi jkl mno…'); 90 | }); 91 | 92 | it('should not trim invalid words numbers', function () { 93 | expect(wordFilter('abc def ghhi jkl mno pqr stu vw xyz', 0)).toEqual(''); 94 | }); 95 | 96 | it('should not trim invalid words type', function () { 97 | expect(wordFilter('hello how u doin', 'abc')).toEqual('hello how u doin'); 98 | }); 99 | 100 | it('should not trim higher words numbers', function () { 101 | expect(wordFilter('abc def ghhi jkl mno pqr stu vw xyz', 25)).toEqual('abc def ghhi jkl mno pqr stu vw xyz'); 102 | }); 103 | 104 | it('should trim these down without ellipsis postfix', function () { 105 | expect(wordFilter('abc def ghhi jkl mno pqr stu vw xyz', 5, '')).toEqual('abc def ghhi jkl mno'); 106 | }); 107 | 108 | it('should trim these down with specific postfix', function () { 109 | expect(wordFilter('abc def ghhi jkl mno pqr stu vw xyz', 5, '...')).toEqual('abc def ghhi jkl mno...'); 110 | }); 111 | 112 | it('should trim these down with blank postfix', function () { 113 | expect(wordFilter('abc def ghhi jkl mno pqr stu vw xyz', 5, '')).toEqual('abc def ghhi jkl mno'); 114 | }); 115 | 116 | }); 117 | 118 | describe('splitcharacters', function () { 119 | var characterFilter; 120 | 121 | beforeEach(inject(function ($filter) { 122 | characterFilter = $filter('splitcharacters'); 123 | })); 124 | 125 | it('should do nothing to this string', function () { 126 | expect(characterFilter('1234567890')).toEqual('1234567890'); 127 | }); 128 | 129 | it('should fail', function () { 130 | expect(characterFilter(null, 30)).not.toEqual('1234567890'); 131 | }); 132 | 133 | it('should not trim these down', function () { 134 | expect(characterFilter('1234567890', 30)).toEqual('1234567890'); 135 | }); 136 | 137 | it('should trim these down', function () { 138 | expect(characterFilter('1234567890', 5)).toEqual('12...890'); 139 | }); 140 | 141 | it('should trim this down including the space', function () { 142 | expect(characterFilter('123456789 10 11 12 13 14', 13)).toEqual('123456...2 13 14'); 143 | }); 144 | 145 | it('should handle invalid numbers', function () { 146 | expect(characterFilter('1234567890', 0)).toEqual(''); 147 | }); 148 | 149 | it('should handle invalid chars numbers type', function () { 150 | expect(characterFilter('1234567890', 'abc')).toEqual('1234567890'); 151 | }); 152 | }); 153 | }); 154 | --------------------------------------------------------------------------------