Overview
| Comment: | [core][js] text as object |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | core | webext2 |
| Files: | files | file ages | folders |
| SHA3-256: |
00c744764382dc316aedfe8610d42f8c |
| User & Date: | olr on 2017-07-31 15:35:29 |
| Other Links: | branch diff | manifest | tags |
Context
|
2017-07-31
| ||
| 15:42 | [core][js] str_transform as object check-in: 917994adcd user: olr tags: core, webext2 | |
| 15:35 | [core][js] text as object check-in: 00c7447643 user: olr tags: core, webext2 | |
| 15:31 | [core][js] helpers as object check-in: 1140b979f8 user: olr tags: core, webext2 | |
Changes
Modified gc_core/js/text.js from [beffb97d58] to [b502e53f4f].
1 2 3 4 5 6 |
// JavaScript
"use strict";
const helpers = require("resource://grammalecte/helpers.js");
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
// JavaScript
"use strict";
const helpers = require("resource://grammalecte/helpers.js");
var text = {
getParagraph: function* (sText) {
// generator: returns paragraphs of text
let iStart = 0;
let iEnd = 0;
sText = sText.replace("\r", "");
while ((iEnd = sText.indexOf("\n", iStart)) !== -1) {
yield sText.slice(iStart, iEnd);
iStart = iEnd + 1;
}
yield sText.slice(iStart);
},
wrap: function* (sText, nWidth=80) {
// generator: returns text line by line
while (sText) {
if (sText.length >= nWidth) {
let nEnd = sText.lastIndexOf(" ", nWidth) + 1;
if (nEnd > 0) {
yield sText.slice(0, nEnd);
sText = sText.slice(nEnd);
} else {
yield sText.slice(0, nWidth);
sText = sText.slice(nWidth);
}
} else {
break;
}
}
yield sText;
},
getReadableError: function (oErr) {
// Returns an error oErr as a readable error
try {
let sResult = "\n* " + oErr['nStart'] + ":" + oErr['nEnd']
+ " # " + oErr['sLineId'] + " # " + oErr['sRuleId'] + ":\n";
sResult += " " + oErr["sMessage"];
if (oErr["aSuggestions"].length > 0) {
sResult += "\n > Suggestions : " + oErr["aSuggestions"].join(" | ");
}
if (oErr["URL"] !== "") {
sResult += "\n > URL: " + oErr["URL"];
}
return sResult;
}
catch (e) {
helpers.logerror(e);
return "\n# Error. Data: " + oErr.toString();
}
}
}
if (typeof(exports) !== 'undefined') {
exports.getParagraph = text.getParagraph;
exports.wrap = text.wrap;
exports.getReadableError = text.getReadableError;
}
|