more cleanup and optional defaults...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-26 05:21:25 +03:00
parent 3400c3ab34
commit 382de1db79
4 changed files with 60 additions and 31 deletions

View File

@ -78,7 +78,7 @@ var normalizeSplit = function(args){
/*********************************************************************/ /*********************************************************************/
// Helpers... // meta stuff...
var makeSplitter = function(separator, unique){ var makeSplitter = function(separator, unique){
return function(...tags){ return function(...tags){
var SP = this[separator] var SP = this[separator]
@ -94,12 +94,17 @@ var makeJoiner = function(separator){
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
var BaseTagsClassPrototype = { var BaseTagsClassPrototype = {
// Tag syntax...
//
// NOTE: this is not used for anything but .replace(..), thus 'g'
// flag is required here...
TAG_ILLEGAL_CHARS: /[\s-_]/g,
// NOTE: do not include 'g' flag here, it will make the RE objects // NOTE: do not include 'g' flag here, it will make the RE objects
// stateful which will yield very unpredictable results from // stateful which will yield very unpredictable results from
// general system. // general system as these objects are used for testing.
PATH_SEPARATOR: '/', PATH_SEPARATOR: '/',
PATH_SEPARATOR_PATTERN: /[\\\/]+/, PATH_SEPARATOR_PATTERN: /[\\\/]+/,
@ -108,6 +113,7 @@ var BaseTagsClassPrototype = {
COMBINED_SEPARATOR_PATTERN: /[:\\\/]+/, COMBINED_SEPARATOR_PATTERN: /[:\\\/]+/,
// Utils... // Utils...
// //
// //
@ -123,6 +129,9 @@ var BaseTagsClassPrototype = {
joinSet: makeJoiner('SET_SEPARATOR'), joinSet: makeJoiner('SET_SEPARATOR'),
joinPath: makeJoiner('PATH_SEPARATOR'), joinPath: makeJoiner('PATH_SEPARATOR'),
// Constructor API...
//
// Normalize tags... // Normalize tags...
// //
// .normalize(tag) // .normalize(tag)
@ -150,18 +159,14 @@ var BaseTagsClassPrototype = {
var PS = this.PATH_SEPARATOR var PS = this.PATH_SEPARATOR
var SP = this.SET_SEPARATOR_PATTERN var SP = this.SET_SEPARATOR_PATTERN
var PP = this.PATH_SEPARATOR_PATTERN var PP = this.PATH_SEPARATOR_PATTERN
var tagRemovedChars = (this.config || {})['tagRemovedChars'] var ILLEGAL_CHARS = this.TAG_ILLEGAL_CHARS
tagRemovedChars = tagRemovedChars instanceof RegExp ?
tagRemovedChars
: typeof(tagRemovedChars) == typeof('str') ?
new RegExp(tagRemovedChars, 'g')
: /[\s-_]/g
var res = normalizeSplit(tags) var res = normalizeSplit(tags)
.map(function(tag){ .map(function(tag){
return tag return tag
.trim() .trim()
.toLowerCase() .toLowerCase()
.replace(tagRemovedChars, '') .replace(ILLEGAL_CHARS, '')
// sort sets within paths... // sort sets within paths...
.split(PP) .split(PP)
.map(function(e){ .map(function(e){
@ -274,18 +279,11 @@ var BaseTagsClassPrototype = {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX should we split out the non-basic stuff???
// like:
// .makePathsPersistent()
// .optimizeTags()
// ...
var BaseTagsPrototype = { var BaseTagsPrototype = {
config: {
// XXX docs!
tagRemovedChars: '[\\s-_]',
},
// NOTE: for notes on structure see notes on the Utils section below... // NOTE: for notes on structure see notes on the Utils section below...
TAG_ILLEGAL_CHARS: BaseTagsClassPrototype.TAG_ILLEGAL_CHARS,
PATH_SEPARATOR: BaseTagsClassPrototype.PATH_SEPARATOR, PATH_SEPARATOR: BaseTagsClassPrototype.PATH_SEPARATOR,
PATH_SEPARATOR_PATTERN: BaseTagsClassPrototype.PATH_SEPARATOR_PATTERN, PATH_SEPARATOR_PATTERN: BaseTagsClassPrototype.PATH_SEPARATOR_PATTERN,
SET_SEPARATOR: BaseTagsClassPrototype.SET_SEPARATOR, SET_SEPARATOR: BaseTagsClassPrototype.SET_SEPARATOR,
@ -1858,7 +1856,7 @@ var TagsWithHandlersPrototype = {
// //
// // make all paths persistent... // // make all paths persistent...
// '*/*': function(tag, action){ // '*/*': function(tag, action){
// action == 'tag' // ;(action == 'tag' || action == 'replace')
// && this.togglePersistent(tag) }, // && this.togglePersistent(tag) },
// //
// ... // ...
@ -1981,6 +1979,35 @@ module.TagsWithHandlers =
//---------------------------------------------------------------------
// Store paths as persistent...
//
// This is TagsWithHandlers with a default path handler...
//
var TagsWithPersistentPathsPrototype = {
__proto__: TagsWithHandlersPrototype,
__special_tag_handlers__: Object.assign({},
TagsWithHandlersPrototype.__special_tag_handlers__ || {},
{
// make all paths persistent...
'*/*': function(tag, action){
;(action == 'tag' || action == 'replace')
&& this.togglePersistent(tag) },
}),
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var TagsWithPersistentPaths =
module.TagsWithPersistentPaths =
object.makeConstructor('TagsWithPersistentPaths',
BaseTagsClassPrototype,
TagsWithPersistentPathsPrototype)
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Tag dictionary... // Tag dictionary...
// //
@ -2232,6 +2259,8 @@ module.Tags =
BaseTagsClassPrototype, BaseTagsClassPrototype,
object.mixin(BaseTagsPrototype, object.mixin(BaseTagsPrototype,
TagsWithHandlersPrototype, TagsWithHandlersPrototype,
// XXX not sure if this should be on by default...
//TagsWithPersistentPathsPrototype,
// NOTE: this needs unmodified input tags this should be // NOTE: this needs unmodified input tags this should be
// mixed in last, i.e. first to be called in chain // mixed in last, i.e. first to be called in chain
// (TagsWithHandlers change the input tags)... // (TagsWithHandlers change the input tags)...