Skip to content

Commit

Permalink
feat(valid-langs): deprecate validLangs, add isValidLangs, reduce fil…
Browse files Browse the repository at this point in the history
…e size (#2527)

* feat(valid-langs): deprecate validLangs, add isValidLangs, reduce file size

* no prettier

* comment typo

* fix external api integration test

* comment at top

* fix ie11

* Update lib/core/utils/valid-langs.js

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>

* update list

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
  • Loading branch information
straker and WilcoFiers authored Sep 25, 2020
1 parent 0f7f5c6 commit 8a699ec
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 8,154 deletions.
9 changes: 5 additions & 4 deletions lib/checks/language/valid-lang-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { validLangs, getBaseLang } from '../../core/utils';
import { isValidLang, getBaseLang } from '../../core/utils';
import { sanitize } from '../../commons/text';

function validLangEvaluate(node, options, virtualNode) {
const langs = (options.value ? options.value : validLangs()).map(getBaseLang);

const invalid = [];
options.attributes.forEach(langAttr => {
const langVal = virtualNode.attr(langAttr);
Expand All @@ -12,11 +10,14 @@ function validLangEvaluate(node, options, virtualNode) {
}

const baselangVal = getBaseLang(langVal);
const invalidLang = options.value
? !options.value.map(getBaseLang).includes(baselangVal)
: !isValidLang(baselangVal);

// Edge sets lang to an empty string when xml:lang is set
// so we need to ignore empty strings here
if (
(baselangVal !== '' && langs.indexOf(baselangVal) === -1) ||
(baselangVal !== '' && invalidLang) ||
// whitespace only lang value is invalid
(langVal !== '' && !sanitize(langVal))
) {
Expand Down
2 changes: 1 addition & 1 deletion lib/core/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ export { default as toArray } from './to-array';
export { default as tokenList } from './token-list';
export { default as uniqueArray } from './unique-array';
export { default as validInputTypes } from './valid-input-type';
export { default as validLangs } from './valid-langs';
export { default as isValidLang, validLangs } from './valid-langs';
Loading

0 comments on commit 8a699ec

Please sign in to comment.