UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

70 lines (64 loc) 2.2 kB
'use strict'; const MAP_CTRL_REPLACEMENTS = [ ['.k-map-controls.k-pos-top.k-pos-left', '.k-map-controls.k-top-start'], ['.k-map-controls.k-pos-top.k-pos-right', '.k-map-controls.k-top-end'], ['.k-map-controls.k-pos-bottom.k-pos-left', '.k-map-controls.k-bottom-start'], ['.k-map-controls.k-pos-bottom.k-pos-right', '.k-map-controls.k-bottom-end'], ['.k-map-controls.k-pos-left.k-pos-top', '.k-map-controls.k-top-start'], ['.k-map-controls.k-pos-right.k-pos-top', '.k-map-controls.k-top-end'], ['.k-map-controls.k-pos-left.k-pos-bottom', '.k-map-controls.k-bottom-start'], ['.k-map-controls.k-pos-right.k-pos-bottom', '.k-map-controls.k-bottom-end'], ]; function applyMapControlsReplacement(str) { let result = str; for (const [from, to] of MAP_CTRL_REPLACEMENTS) { result = result.replaceAll(from, to); } return result; } function transformStringLiterals(root, j, fn) { let changed = false; const visit = path => { if (typeof path.node.value !== 'string') { return; } const updated = fn(path.node.value); if (updated === path.node.value) { return; } path.node.value = updated; if (path.node.extra) { path.node.extra.rawValue = updated; if (path.node.extra.raw) { path.node.extra.raw = fn(path.node.extra.raw); } } changed = true; }; root.find(j.StringLiteral).forEach(visit); root.find(j.Literal, n => typeof n.value === 'string').forEach(visit); return changed; } function transformTemplateLiterals(root, j, fn) { let changed = false; root.find(j.TemplateLiteral).forEach(path => { path.node.quasis.forEach(quasi => { const updatedRaw = fn(quasi.value.raw); const updatedCooked = quasi.value.cooked != null ? fn(quasi.value.cooked) : null; if (updatedRaw !== quasi.value.raw || updatedCooked !== quasi.value.cooked) { quasi.value.raw = updatedRaw; if (quasi.value.cooked != null) { quasi.value.cooked = updatedCooked; } changed = true; } }); }); return changed; } module.exports = { MAP_CTRL_REPLACEMENTS, applyMapControlsReplacement, transformStringLiterals, transformTemplateLiterals, };