mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
more cleanup and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e0bdcfd33a
commit
38c155de0c
@ -31,6 +31,17 @@ var util = require('lib/util')
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
// Helpers...
|
||||||
|
|
||||||
|
// normalize a split to either contain multiple values or a list...
|
||||||
|
var splitOrList = function(args){
|
||||||
|
return (args.length == 1 && args[0] instanceof Array) ?
|
||||||
|
args.pop()
|
||||||
|
: args }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
var TagsClassPrototype = {
|
var TagsClassPrototype = {
|
||||||
@ -62,10 +73,7 @@ var TagsClassPrototype = {
|
|||||||
: typeof(tagRemovedChars) == typeof('str') ?
|
: typeof(tagRemovedChars) == typeof('str') ?
|
||||||
new RegExp(tagRemovedChars, 'g')
|
new RegExp(tagRemovedChars, 'g')
|
||||||
: /[\s-_]/g
|
: /[\s-_]/g
|
||||||
var res = (tags.length == 1 && tags[0] instanceof Array) ?
|
var res = splitOrList(tags)
|
||||||
tags.pop()
|
|
||||||
: tags
|
|
||||||
res = res
|
|
||||||
.map(function(tag){
|
.map(function(tag){
|
||||||
return tag
|
return tag
|
||||||
.trim()
|
.trim()
|
||||||
@ -93,10 +101,7 @@ var TagsClassPrototype = {
|
|||||||
: res
|
: res
|
||||||
},
|
},
|
||||||
subTags: function(...tags){
|
subTags: function(...tags){
|
||||||
tags = (tags.length == 1 && tags[0] instanceof Array) ?
|
return this.normalize(splitOrList(tags))
|
||||||
tags.pop()
|
|
||||||
: tags
|
|
||||||
return this.normalize(tags)
|
|
||||||
.map(function(tag){
|
.map(function(tag){
|
||||||
return tag.split(/[:\\\/]/g) })
|
return tag.split(/[:\\\/]/g) })
|
||||||
.flat()
|
.flat()
|
||||||
@ -595,9 +600,7 @@ var TagsPrototype = {
|
|||||||
|
|
||||||
// check if value is tagged by tags..,
|
// check if value is tagged by tags..,
|
||||||
if(value && tags.length > 0){
|
if(value && tags.length > 0){
|
||||||
tags = tags.length == 1 && tags[0] instanceof Array ?
|
tags = splitOrList(tags)
|
||||||
tags.shift()
|
|
||||||
: tags
|
|
||||||
var u = this.tags(value)
|
var u = this.tags(value)
|
||||||
while(tags.length > 0){
|
while(tags.length > 0){
|
||||||
if(this.match(tags.shift(), u).length == 0){
|
if(this.match(tags.shift(), u).length == 0){
|
||||||
@ -634,7 +637,7 @@ var TagsPrototype = {
|
|||||||
return this.tags(value)
|
return this.tags(value)
|
||||||
.filter(function(tag){ return /[\\\/]/.test(tag) }) },
|
.filter(function(tag){ return /[\\\/]/.test(tag) }) },
|
||||||
// XXX should this support ...tags???
|
// XXX should this support ...tags???
|
||||||
sets: function(){
|
sets: function(value){
|
||||||
return this.tags(value)
|
return this.tags(value)
|
||||||
.filter(function(tag){ return tag.includes(':') }) },
|
.filter(function(tag){ return tag.includes(':') }) },
|
||||||
//
|
//
|
||||||
@ -870,9 +873,7 @@ var TagsPrototype = {
|
|||||||
action = ['on', 'off', 'toggle', '?'].includes(tags[tags.length-1]) ?
|
action = ['on', 'off', 'toggle', '?'].includes(tags[tags.length-1]) ?
|
||||||
tags.pop()
|
tags.pop()
|
||||||
: 'toggle'
|
: 'toggle'
|
||||||
tags = (tags[0] instanceof Array && tags.length == 1) ?
|
tags = splitOrList(tags)
|
||||||
tags.pop()
|
|
||||||
: tags
|
|
||||||
|
|
||||||
var persistent =
|
var persistent =
|
||||||
this.__persistent_tags =
|
this.__persistent_tags =
|
||||||
@ -930,9 +931,7 @@ var TagsPrototype = {
|
|||||||
throw new Error(
|
throw new Error(
|
||||||
`.rename(..): only support tags and tag sets as renaming target, got: "${to}"`) }
|
`.rename(..): only support tags and tag sets as renaming target, got: "${to}"`) }
|
||||||
|
|
||||||
tags = new Set((tags[0] instanceof Array && tags.length == 1) ?
|
tags = new Set(splitOrList(tags))
|
||||||
tags[0]
|
|
||||||
: tags)
|
|
||||||
|
|
||||||
// prepare for the replacement...
|
// prepare for the replacement...
|
||||||
var pattern = new RegExp(`(^|[:\\\\\\/])${tag}(?=$|[:\\\\\\/])`, 'g')
|
var pattern = new RegExp(`(^|[:\\\\\\/])${tag}(?=$|[:\\\\\\/])`, 'g')
|
||||||
@ -997,9 +996,7 @@ var TagsPrototype = {
|
|||||||
// -> this
|
// -> this
|
||||||
//
|
//
|
||||||
remove: function(...values){
|
remove: function(...values){
|
||||||
values = (values.length == 1 && values[0] instanceof Array) ?
|
values = splitOrList(values)
|
||||||
values.pop()
|
|
||||||
: values
|
|
||||||
var res = this.clone()
|
var res = this.clone()
|
||||||
|
|
||||||
Object.entries(res.__index || {})
|
Object.entries(res.__index || {})
|
||||||
@ -1016,9 +1013,7 @@ var TagsPrototype = {
|
|||||||
// -> this
|
// -> this
|
||||||
//
|
//
|
||||||
keep: function(...values){
|
keep: function(...values){
|
||||||
values = (values.length == 1 && values[0] instanceof Array) ?
|
values = splitOrList(values)
|
||||||
values.pop()
|
|
||||||
: values
|
|
||||||
var res = this.clone()
|
var res = this.clone()
|
||||||
|
|
||||||
Object.entries(res.__index || {})
|
Object.entries(res.__index || {})
|
||||||
@ -1030,11 +1025,14 @@ var TagsPrototype = {
|
|||||||
|
|
||||||
// Join 1 or more Tags objects...
|
// Join 1 or more Tags objects...
|
||||||
//
|
//
|
||||||
// XXX should this be join or add???
|
// .join(other, ..)
|
||||||
|
// .join([other, ..])
|
||||||
|
// -> this
|
||||||
|
//
|
||||||
join: function(...others){
|
join: function(...others){
|
||||||
var that = this
|
var that = this
|
||||||
var index = this.__index || {}
|
var index = this.__index || {}
|
||||||
others
|
splitOrList(others)
|
||||||
.forEach(function(other){
|
.forEach(function(other){
|
||||||
Object.entries(other.__index || {})
|
Object.entries(other.__index || {})
|
||||||
.forEach(function(e){
|
.forEach(function(e){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user