| Lines of Code | 45 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | import attr from "./attr"; |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Class FileAttr |
||
| 5 | * Manage string with attributes encoded inside |
||
| 6 | */ |
||
| 7 | export default class FileAttr { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Add attributes or modify them if they already exists |
||
| 11 | * @param {String} str the string to modify |
||
| 12 | * @param {Object} options object with attributes to add |
||
| 13 | * @return {String} the string with the new attributes |
||
| 14 | */ |
||
| 15 | static add(str, options) { |
||
| 16 | var att = new attr(str) |
||
|
|
|||
| 17 | return att.insert(options) |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Remove attributes from string |
||
| 22 | * @param {String} str the string to modify |
||
| 23 | * @return {String} the string modified |
||
| 24 | */ |
||
| 25 | static delete(str) { |
||
| 26 | return new attr(str).remove() |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param {String} str the string to get attributes from |
||
| 31 | * @return {object|String} object (all the attributes) if the key is null, if not the value of the atrtibuts |
||
| 32 | */ |
||
| 33 | static get(str) { |
||
| 34 | return new attr(str).val |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param {String} str the string to test attributes from |
||
| 39 | * @return {boolean} true if string has attr |
||
| 40 | */ |
||
| 41 | static test(str) { |
||
| 42 | var att = new attr(str).val |
||
| 43 | return (typeof att.s !== 'undefined' && att.s !== null) |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 |