wishthis/node_modules/rtlcss/lib/config.js

87 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
'use strict'
2022-05-29 09:24:36 +00:00
var options
var config = {}
var corePlugin = require('./plugin.js')
2022-01-21 08:28:41 +00:00
function optionOrDefault (option, def) {
return option in options ? options[option] : def
}
function addKey (key, def) {
config[key] = optionOrDefault(key, def)
}
function main (opts, plugins, hooks) {
options = opts || {}
hooks = hooks || {}
addKey('autoRename', false)
addKey('autoRenameStrict', false)
addKey('blacklist', {})
addKey('clean', true)
addKey('greedy', false)
addKey('processUrls', false)
addKey('stringMap', [])
addKey('useCalc', false)
// default strings map
if (Array.isArray(config.stringMap)) {
2022-05-29 09:24:36 +00:00
var hasLeftRight, hasLtrRtl
for (var x = 0; x < config.stringMap.length; x++) {
var map = config.stringMap[x]
2022-01-21 08:28:41 +00:00
if (hasLeftRight && hasLtrRtl) {
break
} else if (map.name === 'left-right') {
hasLeftRight = true
} else if (map.name === 'ltr-rtl') {
hasLtrRtl = true
}
}
if (!hasLeftRight) {
config.stringMap.push({
2022-05-29 09:24:36 +00:00
'name': 'left-right',
'priority': 100,
'exclusive': false,
'search': ['left', 'Left', 'LEFT'],
'replace': ['right', 'Right', 'RIGHT'],
'options': { 'scope': '*', 'ignoreCase': false }
2022-01-21 08:28:41 +00:00
})
}
if (!hasLtrRtl) {
config.stringMap.push({
2022-05-29 09:24:36 +00:00
'name': 'ltr-rtl',
'priority': 100,
'exclusive': false,
'search': ['ltr', 'Ltr', 'LTR'],
'replace': ['rtl', 'Rtl', 'RTL'],
'options': { 'scope': '*', 'ignoreCase': false }
2022-01-21 08:28:41 +00:00
})
}
2022-05-29 09:24:36 +00:00
config.stringMap.sort(function (a, b) { return a.priority - b.priority })
2022-01-21 08:28:41 +00:00
}
// plugins
config.plugins = []
if (Array.isArray(plugins)) {
2022-05-29 09:24:36 +00:00
if (!plugins.some(function (plugin) { return plugin.name === 'rtlcss' })) {
2022-01-21 08:28:41 +00:00
config.plugins.push(corePlugin)
}
config.plugins = config.plugins.concat(plugins)
} else if (!plugins || plugins.name !== 'rtlcss') {
config.plugins.push(corePlugin)
}
2022-05-29 09:24:36 +00:00
config.plugins.sort(function (a, b) { return a.priority - b.priority })
2022-01-21 08:28:41 +00:00
// hooks
2022-05-29 09:24:36 +00:00
config.hooks = { pre: function () {}, post: function () {} }
2022-01-21 08:28:41 +00:00
if (typeof hooks.pre === 'function') {
config.hooks.pre = hooks.pre
}
if (typeof hooks.post === 'function') {
config.hooks.post = hooks.post
}
return config
}
module.exports.configure = main