UNPKG

@progress/kendo-ui

Version:

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

73 lines (64 loc) 2.03 kB
'use strict'; const arrowClassMappings = { 'k-arrow-up': 'k-i-arrow-n', 'k-arrow-next': 'k-i-arrow-e', 'k-arrow-down': 'k-i-arrow-s', 'k-arrow-prev': 'k-i-arrow-w', 'k-arrow-first': 'k-i-seek-w', 'k-arrow-last': 'k-i-seek-e', }; const sortedOldClasses = Object.keys(arrowClassMappings).sort((a, b) => b.length - a.length); function buildArrowRegex() { const escaped = sortedOldClasses.map(c => c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')); return new RegExp('(?<![\\w-])(' + escaped.join('|') + ')(?![\\w-])', 'g'); } const ARROW_RE = buildArrowRegex(); function applyArrowClassRenames(str) { return str.replace(ARROW_RE, (match) => arrowClassMappings[match] || match); } 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 = { arrowClassMappings, applyArrowClassRenames, transformStringLiterals, transformTemplateLiterals, };