superscore.string

2019-07-14 admin

superscore.string是什么

什么是superscore.string,Useful mixins for Underscore.String

superscore.string使用教程帮助文档

superscore.string

Underscore.String mixins

Usage

Node environment

npm install superscore.string

Then in your scripts:

var s = require('superscore.string');

Browser environment

bower install superscore.string

Then include these files into your documents

<script src="bower_components/superscore.string/dist/lowerdash.js"></script>
<script src="bower_components/underscore.string/lib/underscore.string.js"></script>

API

Superscore.String provides the following methods :

  • String truncate(String str, Number max, [Object options]) Truncate a string before atChar

    • str string to truncate
    • max string max length
    • options
      • options.trail leading string, default to
      • options.atChar if provided, cut string before it
     s.truncate('The quick brown fox jumps over the lazy dog', 20, {
     	atChar: ' '
     });
     // "The quick brown fox…"
    
     s.truncate('The quick brown fox jumps over the lazy dog', 17);
     // "The quick brown f…"
    
  • Boolean anymatch(String str, Array matchers) Test provided string against anymatch expression(s) (Node only)

     console.info(s.anymatch('The quick brown fox jumps over the lazy dog', ['over', /^the/]))
     //false
    
     console.info(s.anymatch('The quick brown fox jumps over the lazy dog', ['over', /^The/]))
     // true
    
  • String random(Number length) Generates a random string of length length

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-69695.html

文章标题:superscore.string

回到顶部