for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import {dateUnslug} from '../../'
var fullAttr = '-abe-(.+?)(?=\.'
var captureAttr = '-abe-(.+?)(?=\.'
/**
* Class Attr
* Work string to manage string attributes key/value
*/
export default class Attr {
* @param {String} str string to work with
* @return {void}
constructor(str) {
this.str = str
this.val = {}
this.extract()
}
* @return {Object} attributes extracted from string as an object
extract() {
var rex = new RegExp(captureAttr + this.getExtension() + ')')
if(rex.test(this.str)) {
var arrAttr = this.str.match(rex)[0].replace('-abe-', '')
this.val = {'s': arrAttr[0], 'd': dateUnslug(arrAttr.slice(1), this.str)}
return this.val
* @return {String} str without attributes
remove() {
return this.str.replace(new RegExp(fullAttr + this.getExtension() + ')'), '')
getExtension(){
var ext = this.str.split('.')
return ext[ext.length - 1]
* Insert attributes to the string
* @param {String} string composed of a status (ex: v for validate, d for draft ...) and a date
string
* @return {String} the new string with added attributes
insert(newValues) {
var strWithoutAttr = this.remove()
strWithoutAttr = strWithoutAttr.replace(new RegExp('\\.' + this.getExtension()), '')
return strWithoutAttr + '-abe-' + newValues + '.' + this.getExtension()