UNPKG

compromise

Version:
37 lines (34 loc) 958 B
'use strict'; //set a term as a particular Part-of-speech const path = require('./paths'); const log = path.log; const tagset = path.tags; //remove a tag from a term const unTagOne = (term, tag, reason) => { if (term.tag[tag]) { log.tell(' --' + tag + ' ' + (reason || '')); delete term.tag[tag]; } }; const unTagAll = (term, tag, reason) => { if (!term || !tag) { return; } unTagOne(term, tag, reason); if (tagset[tag]) { //pull-out their children (dependants) too //this should probably be recursive, instead of just 2-deep let killAlso = tagset[tag].children || []; for (let o = 0; o < killAlso.length; o++) { //kill its child unTagOne(term, killAlso[o], reason); //kill grandchildren too let kill2 = tagset[killAlso[o]].children || [] for (let i2 = 0; i2 < kill2.length; i2++) { unTagOne(term, kill2[i2], reason); } } } return; }; module.exports = unTagAll;