Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. // sformat prototype as argument replacement.
  2. //
  3. // "{0} is dead, but {1} is alive! {0} {2}".sformat("ASP", "ASP.NET")
  4. // Output: "ASP is dead, but ASP.NET is alive! ASP {2}"
  5. //
  6. if (!String.prototype.sformat) {
  7. String.prototype.sformat = function() {
  8. const args = arguments;
  9. return this.replace(/{(\d+)}/g, (match, number) => {
  10. return typeof args[number] !== 'undefined' ? args[number] : match;
  11. });
  12. };
  13. }
  14.  
  15. if (!String.prototype.present) {
  16. String.prototype.present = function() {
  17. return this && typeof this != 'undefined' && this.length > 0;
  18. };
  19. }
  20.  
  21. if (!String.prototype.starts) {
  22. String.prototype.starts = function(text) {
  23. return this.toLowerCase().search(text.toLowerCase()) > -1;
  24. };
  25. }
Add Comment
Please, Sign In to add comment