code
stringlengths 10
343k
| docstring
stringlengths 36
21.9k
| func_name
stringlengths 1
3.35k
| language
stringclasses 1
value | repo
stringlengths 7
58
| path
stringlengths 4
131
| url
stringlengths 44
195
| license
stringclasses 5
values |
---|---|---|---|---|---|---|---|
var tokenizeHTML = (function() {
var REG_EXP = /\s+|\>|</;
return function(html) {
return html.split(REG_EXP).sort().join(" ");
};
})(); | Browsers don't preserve original attribute order
In order to be able to compare html we simply split both, the expected and actual html at spaces and element-ends,
sort them alphabetically and put them back together
TODO: This solution is a bit crappy. Maybe there's a smarter way. However it works for now. | (anonymous) ( ) | javascript | jhollingworth/bootstrap-wysihtml5 | test/support/html_equal.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/test/support/html_equal.js | MIT |
wysihtml5.assert.htmlEqual = (function() {
var htmlHost = document.createElement("div");
/**
* IE uppercases tags and attribute names
* and also removes quotes around attribute values whenever possible
*/
var NEEDS_TO_BE_PREPARSED = (function() {
var html = '<img alt="foo" width=1 height="1" data-foo="1">';
htmlHost.innerHTML = html;
return htmlHost.innerHTML != html;
})();
var DOESNT_PRESERVE_WHITE_SPACE = (function() {
var div = document.createElement("div"),
a = document.createElement("a"),
p = document.createElement("p");
a.appendChild(p);
div.appendChild(a);
return div.innerHTML.toLowerCase() != "<a><p></p></a>";
})();
/**
* When setting attributes via DOM API (setAttribute, etc.)
* Firefox reorders them randomly when read via innerHTML, which makes comparing such strings
* with expected strings a pain in the arse
* Issue: https://bugzilla.mozilla.org/show_bug.cgi?id=238686
*/
var REORDERS_ATTRIBUTES = (function() {
var img = document.createElement("img"),
parsedActualHtml,
parsedExpectedHtml;
img.setAttribute("alt", "foo");
img.setAttribute("border", "1");
img.setAttribute("src", "foo.gif");
htmlHost.innerHTML = "";
htmlHost.appendChild(img);
parsedActualHtml = htmlHost.innerHTML;
htmlHost.innerHTML = '<img alt="foo" border="1" src="foo.gif">';
parsedExpectedHtml = htmlHost.innerHTML;
return parsedExpectedHtml != parsedActualHtml;
})();
/**
* Browsers don't preserve original attribute order
* In order to be able to compare html we simply split both, the expected and actual html at spaces and element-ends,
* sort them alphabetically and put them back together
* TODO: This solution is a bit crappy. Maybe there's a smarter way. However it works for now.
*/
var tokenizeHTML = (function() {
var REG_EXP = /\s+|\>|</;
return function(html) {
return html.split(REG_EXP).sort().join(" ");
};
})();
var normalizeWhiteSpace = (function() {
var PRE_REG_EXP = /(<pre[\^>]*>)([\S\s]*?)(<\/pre>)/mgi,
WHITE_SPACE_REG_EXP = /\s+/gm,
PLACEHOLDER = "___PRE_CONTENT___",
PLACEHOLDER_REG_EXP = new RegExp(PLACEHOLDER, "g");
return function(html) {
var preContents = [];
// Extract content of elements that preserve white space first
html = html.replace(PRE_REG_EXP, function(match, $1, $2, $3) {
preContents.push($2);
return $1 + PLACEHOLDER + $3;
});
// Normalize space
html = html.replace(WHITE_SPACE_REG_EXP, " ");
// Reinsert original pre content
html = html.replace(PLACEHOLDER_REG_EXP, function() {
return preContents.shift();
});
return html;
};
})();
var removeWhiteSpace = (function() {
var REG_EXP = /(>)(\s*?)(<)/gm;
return function(html) {
return wysihtml5.lang.string(html.replace(REG_EXP, "$1$3")).trim();
};
})();
return function(actual, expected, message, config) {
config = config || {};
if (NEEDS_TO_BE_PREPARSED) {
actual = wysihtml5.dom.getAsDom(actual).innerHTML;
expected = wysihtml5.dom.getAsDom(expected).innerHTML;
}
if (config.normalizeWhiteSpace || DOESNT_PRESERVE_WHITE_SPACE) {
actual = normalizeWhiteSpace(actual);
expected = normalizeWhiteSpace(expected);
}
if (config.removeWhiteSpace) {
actual = removeWhiteSpace(actual);
expected = removeWhiteSpace(expected);
}
actual = tokenizeHTML(actual);
expected = tokenizeHTML(expected);
ok(actual == expected, message);
};
})(); | Compare html strings without stumbling upon browser misbehaviors
Uses and takes the same parameters as QUnit's equal method
@example
wysihtml5.assert.htmlEqual(
removeAttributes('<p align="center">foo</p>'),
'<p>foo</p>',
'Removed align attribute on <p>'
); | (anonymous) ( ) | javascript | jhollingworth/bootstrap-wysihtml5 | test/support/html_equal.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/test/support/html_equal.js | MIT |
(function($){
$.fn.wysihtml5.locale["ko-KR"] = {
font_styles: {
normal: "일반",
h1: "헤드라인 1",
h2: "헤드라인 2",
h3: "헤드라인 3"
},
emphasis: {
bold: "굵게",
italic: "기울게",
underline: "밑줄"
},
lists: {
unordered: "기호목록",
ordered: "숫자목록",
outdent: "내어쓰기",
indent: "들여쓰기"
},
link: {
insert: "링크 삽입",
cancel: "취소"
},
image: {
insert: "이미지 삽입",
cancel: "취소"
},
html: {
edit: "HTML 편집"
},
colours: {
black: "검은색",
silver: "은색",
gray: "회색",
maroon: "고동색",
red: "빨간색",
purple: "보라색",
green: "초록색",
olive: "올리브",
navy: "네이비",
blue: "파란색",
orange: "주황색"
}
};
}(jQuery)); | Korean translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.ko-KR.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.ko-KR.js | MIT |
(function($){
$.fn.wysihtml5.locale["fr-FR"] = {
font_styles: {
normal: "Texte normal",
h1: "Titre 1",
h2: "Titre 2",
h3: "Titre 3"
},
emphasis: {
bold: "Gras",
italic: "Italique",
underline: "Souligné"
},
lists: {
unordered: "Liste à puces",
ordered: "Liste numérotée",
outdent: "Diminuer le retrait",
indent: "Augmenter le retrait",
indered: "Augmenter le retrait"
},
link: {
insert: "Insérer un lien",
cancel: "Annuler"
},
image: {
insert: "Insérer une image",
cancel: "Annuler"
},
html: {
edit: "Editer en HTML"
},
colours: {
black: "Noir",
silver: "Gris clair",
gray: "Gris",
maroon: "Marron",
red: "Rouge",
purple: "Pourpre",
green: "Vert",
olive: "Olive",
navy: "Bleu marine",
blue: "Bleu",
orange: "Orange"
}
};
}(jQuery)); | French translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.fr-FR.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.fr-FR.js | MIT |
(function($){
$.fn.wysihtml5.locale["lt-LT"] = {
font_styles: {
normal: "Normalus",
h1: "Antraštė 1",
h2: "Antraštė 2",
h3: "Antraštė 3"
},
emphasis: {
bold: "Pastorintas",
italic: "Kursyvas",
underline: "Pabrauktas"
},
lists: {
unordered: "Suženklintas sąrašas",
ordered: "Numeruotas sąrašas",
outdent: "Padidinti įtrauką",
indent: "Sumažinti įtrauką"
},
link: {
insert: "Įterpti nuorodą",
cancel: "Atšaukti"
},
image: {
insert: "Įterpti atvaizdą",
cancel: "Atšaukti"
},
html: {
edit: "Redaguoti HTML"
},
colours: {
black: "Juoda",
silver: "Sidabrinė",
gray: "Pilka",
maroon: "Kaštoninė",
red: "Raudona",
purple: "Violetinė",
green: "Žalia",
olive: "Gelsvai žalia",
navy: "Tamsiai mėlyna",
blue: "Mėlyna",
orange: "Oranžinė"
}
};
}(jQuery)); | Lithuanian translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.lt-LT.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.lt-LT.js | MIT |
(function($){
$.fn.wysihtml5.locale["es-AR"] = {
font_styles: {
normal: "Texto normal",
h1: "Título 1",
h2: "Título 2",
h3: "Título 3"
},
emphasis: {
bold: "Negrita",
italic: "Itálica",
underline: "Subrayado"
},
lists: {
ordered: "Lista ordenada",
unordered: "Lista desordenada",
indent: "Agregar sangría",
outdent: "Eliminar sangría"
},
link: {
insert: "Insertar enlace",
cancel: "Cancelar"
},
image: {
insert: "Insertar imágen",
cancel: "Cancelar"
},
html: {
edit: "Editar HTML"
},
colours: {
black: "Negro",
silver: "Plata",
gray: "Gris",
maroon: "Marrón",
red: "Rojo",
purple: "Púrpura",
green: "Verde",
olive: "Oliva",
navy: "Azul Marino",
blue: "Azul",
orange: "Naranja"
}
};
}(jQuery)); | Spanish Argenina translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.es-AR.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.es-AR.js | MIT |
(function($){
$.fn.wysihtml5.locale["pt-BR"] = {
font_styles: {
normal: "Texto normal",
h1: "Título 1",
h2: "Título 2",
h3: "Título 3",
h4: "Título 4",
h5: "Título 5",
h6: "Título 6"
},
emphasis: {
bold: "Negrito",
italic: "Itálico",
underline: "Sublinhado"
},
lists: {
unordered: "Lista",
ordered: "Lista numerada",
outdent: "Remover indentação",
indent: "Indentar"
},
link: {
insert: "Inserir link",
cancel: "Cancelar",
target: "Abrir em uma nova aba"
},
image: {
insert: "Inserir imagem",
cancel: "Cancelar"
},
html: {
edit: "Editar HTML"
},
colours: {
black: "Preto",
silver: "Prata",
gray: "Cinza",
maroon: "Marrom",
red: "Vermelho",
purple: "Roxo",
green: "Verde",
olive: "Oliva",
navy: "Marinho",
blue: "Azul",
orange: "Laranja"
}
};
}(jQuery)); | Brazilian portuguese translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.pt-BR.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.pt-BR.js | MIT |
(function($){
$.fn.wysihtml5.locale["nb-NB"] = {
font_styles: {
normal: "Normal tekst",
h1: "Tittel 1",
h2: "Tittel 2",
h3: "Tittel 3"
},
emphasis: {
bold: "Fet",
italic: "Kursiv",
underline: "Understrekning"
},
lists: {
unordered: "Usortert",
ordered: "Sortert",
outdent: "Detabuler",
indent: "Tabuler",
indered: "Tabuler"
},
link: {
insert: "Sett inn lenke",
cancel: "Avbryt"
},
image: {
insert: "Sett inn bilde",
cancel: "Avbryt"
},
html: {
edit: "Rediger HTML"
},
colours: {
black: "Svart",
silver: "Sølv",
gray: "Grå",
maroon: "Brun",
red: "Rød",
purple: "Lilla",
green: "Grønn",
olive: "Oliven",
navy: "Marineblå",
blue: "Blå",
orange: "Oransj"
}
};
}(jQuery)); | Norwegian translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.nb-NB.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.nb-NB.js | MIT |
(function($){
$.fn.wysihtml5.locale["ca-CT"] = {
font_styles: {
normal: "Text normal",
h1: "Títol 1",
h2: "Títol 2"
},
emphasis: {
bold: "Negreta",
italic: "Cursiva",
underline: "Subratllat"
},
lists: {
unordered: "Llista desordenada",
ordered: "Llista ordenada",
outdent: "Esborrar tabulació",
indent: "Afegir tabulació"
},
link: {
insert: "Afegir enllaç",
cancel: "Cancelar"
},
image: {
insert: "Afegir imatge",
cancel: "Cancelar"
},
html: {
edit: "Editar HTML"
},
colours: {
black: "Negre",
silver: "Plata",
gray: "Gris",
maroon: "Marró",
red: "Vermell",
purple: "Porpre",
green: "Verd",
olive: "Oliva",
navy: "Blau marí",
blue: "Blau",
orange: "Taronja"
}
};
}(jQuery)); | Catalan translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.ca-CT.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.ca-CT.js | MIT |
(function($){
$.fn.wysihtml5.locale["tr-TR"] = {
font_styles: {
normal: "Normal",
h1: "Başlık 1",
h2: "Başlık 2",
h3: "Başlık 3"
},
emphasis: {
bold: "Kalın",
italic: "İtalik",
underline: "Altı Çizili"
},
lists: {
unordered: "Sırasız Liste",
ordered: "Sıralı Liste",
outdent: "Girintiyi Azalt",
indent: "Girintiyi Arttır"
},
link: {
insert: "Ekle",
cancel: "Vazgeç"
},
image: {
insert: "Ekle",
cancel: "Vazgeç"
},
html: {
edit: "HTML Göster"
},
colours: {
black: "Siyah",
silver: "Gümüş",
gray: "Gri",
maroon: "Vişne Çürüğü",
red: "Kırmızı",
purple: "Pembe",
green: "Yeşil",
olive: "Zeytin Yeşili",
navy: "Lacivert",
blue: "Mavi",
orange: "Turuncu"
}
};
}(jQuery)); | Turkish translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.tr-TR.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.tr-TR.js | MIT |
(function($){
$.fn.wysihtml5.locale["sk-SK"] = {
font_styles: {
normal: "Normálny text",
h1: "Nadpis úrovne 1",
h2: "Nadpis úrovne 2",
h3: "Nadpis úrovne 3"
},
emphasis: {
bold: "Tučné",
italic: "Kurzíva",
underline: "Podčiarknuté"
},
lists: {
unordered: "Neusporiadaný zoznam",
ordered: "Číslovaný zoznam",
outdent: "Zväčšiť odsadenie",
indent: "Zmenšiť odsadenie"
},
link: {
insert: "Vložiť odkaz",
cancel: "Zrušiť"
},
image: {
insert: "Vložiť obrázok",
cancel: "Zrušiť"
},
html: {
edit: "Editovať HTML"
},
colours: {
black: "Čierna",
silver: "Strieborná",
gray: "Šedá",
maroon: "Bordová",
red: "Červená",
purple: "Fialová",
green: "Zelená",
olive: "Olivová",
navy: "Tmavomodrá",
blue: "Modrá",
orange: "Oranžová"
}
};
}(jQuery)); | Slovak translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.sk-SK.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.sk-SK.js | MIT |
(function($){
$.fn.wysihtml5.locale["sv-SE"] = {
font_styles: {
normal: "Normal Text",
h1: "Rubrik 1",
h2: "Rubrik 2",
h3: "Rubrik 3"
},
emphasis: {
bold: "Fet",
italic: "Kursiv",
underline: "Understruken"
},
lists: {
unordered: "Osorterad lista",
ordered: "Sorterad lista",
outdent: "Minska indrag",
indent: "Öka indrag"
},
link: {
insert: "Lägg till länk",
cancel: "Avbryt"
},
image: {
insert: "Lägg till Bild",
cancel: "Avbryt"
},
html: {
edit: "Redigera HTML"
},
colours: {
black: "Svart",
silver: "Silver",
gray: "Grå",
maroon: "Kastaniebrun",
red: "Röd",
purple: "Lila",
green: "Grön",
olive: "Olivgrön",
navy: "Marinblå",
blue: "Blå",
orange: "Orange"
}
};
}(jQuery)); | Swedish translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.sv-SE.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.sv-SE.js | MIT |
(function($){
$.fn.wysihtml5.locale["pl-PL"] = {
font_styles: {
normal: "Tekst podstawowy",
h1: "Nagłówek 1",
h2: "Nagłówek 2",
h3: "Nagłówek 3"
},
emphasis: {
bold: "Pogrubienie",
italic: "Kursywa",
underline: "Podkreślenie"
},
lists: {
unordered: "Lista wypunktowana",
ordered: "Lista numerowana",
outdent: "Zwiększ wcięcie",
indent: "Zmniejsz wcięcie"
},
link: {
insert: "Wstaw odnośnik",
cancel: "Anuluj"
},
image: {
insert: "Wstaw obrazek",
cancel: "Anuluj"
},
html: {
edit: "Edycja HTML"
},
colours: {
black: "Czarny",
silver: "Srebrny",
gray: "Szary",
maroon: "Kasztanowy",
red: "Czerwony",
purple: "Fioletowy",
green: "Zielony",
olive: "Oliwkowy",
navy: "Granatowy",
blue: "Niebieski",
orange: "Pomarańczowy"
}
};
}(jQuery)); | Polish translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.pl-PL.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.pl-PL.js | MIT |
(function($){
$.fn.wysihtml5.locale["it-IT"] = {
font_styles: {
normal: "Testo normale",
h1: "Titolo 1",
h2: "Titolo 2"
},
emphasis: {
bold: "Grassetto",
italic: "Corsivo",
underline: "Sottolineato"
},
lists: {
unordered: "Lista non ordinata",
ordered: "Lista ordinata",
outdent: "Elimina rientro",
indent: "Aggiungi rientro"
},
link: {
insert: "Inserisci link",
cancel: "Annulla"
},
image: {
insert: "Inserisci immagine",
cancel: "Annulla"
},
html: {
edit: "Modifica HTML"
},
colours: {
black: "Nero",
silver: "Argento",
gray: "Grigio",
maroon: "Marrone",
red: "Rosso",
purple: "Viola",
green: "Verde",
olive: "Oliva",
navy: "Blu Marino",
blue: "Blu",
orange: "Arancio"
}
};
}(jQuery)); | Italian translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.it-IT.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.it-IT.js | MIT |
(function($){
$.fn.wysihtml5.locale["de-DE"] = {
font_styles: {
normal: "Normaler Text",
h1: "Überschrift 1",
h2: "Überschrift 2",
h3: "Überschrift 3"
},
emphasis: {
bold: "Fett",
italic: "Kursiv",
underline: "Unterstrichen"
},
lists: {
unordered: "Ungeordnete Liste",
ordered: "Geordnete Liste",
outdent: "Einzug verkleinern",
indent: "Einzug vergrößern"
},
link: {
insert: "Link einfügen",
cancel: "Abbrechen",
target: "Link in neuen Fenster öffnen"
},
image: {
insert: "Bild einfügen",
cancel: "Abbrechen"
},
html: {
edit: "HTML bearbeiten"
},
colours: {
black: "Schwarz",
silver: "Silber",
gray: "Grau",
maroon: "Kastanienbraun",
red: "Rot",
purple: "Violett",
green: "Grün",
olive: "Olivgrün",
navy: "Marineblau",
blue: "Blau",
orange: "Orange"
}
};
}(jQuery)); | German translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.de-DE.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.de-DE.js | MIT |
(function($){
$.fn.wysihtml5.locale["cs-CZ"] = {
font_styles: {
normal: "Normální text",
h1: "Nadpis úrovně 1",
h2: "Nadpis úrovně 2",
h3: "Nadpis úrovně 3"
},
emphasis: {
bold: "Tučné",
italic: "Kurzíva",
underline: "Podtržení"
},
lists: {
unordered: "Seznam s odrážkami",
ordered: "Číslovaný seznam",
outdent: "Zvětšit odsazení",
indent: "Zmenšit odsazení"
},
link: {
insert: "Vložit odkaz",
cancel: "Zrušit"
},
image: {
insert: "Vložit obrázek",
cancel: "Zrušit"
},
html: {
edit: "Upravit HTML"
},
colours: {
black: "Černá",
silver: "Stříbrná",
gray: "Šedá",
maroon: "Vínová",
red: "Červená",
purple: "Fialová",
green: "Zelená",
olive: "Olivová",
navy: "Tmavomodrá",
blue: "Modrá",
orange: "Oranžová"
}
};
}(jQuery)); | Czech translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.cs-CZ.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.cs-CZ.js | MIT |
(function($){
$.fn.wysihtml5.locale["ru-RU"] = {
font_styles: {
normal: "Обычный текст",
h1: "Заголовок 1",
h2: "Заголовок 2",
h3: "Заголовок 3"
},
emphasis: {
bold: "Полужирный",
italic: "Курсив",
underline: "Подчёркнутый"
},
lists: {
unordered: "Маркированный список",
ordered: "Нумерованный список",
outdent: "Уменьшить отступ",
indent: "Увеличить отступ"
},
link: {
insert: "Вставить ссылку",
cancel: "Отмена"
},
image: {
insert: "Вставить изображение",
cancel: "Отмена"
},
html: {
edit: "HTML код"
},
colours: {
black: "Чёрный",
silver: "Серебряный",
gray: "Серый",
maroon: "Коричневый",
red: "Красный",
purple: "Фиолетовый",
green: "Зелёный",
olive: "Оливковый",
navy: "Тёмно-синий",
blue: "Синий",
orange: "Оранжевый"
}
};
}(jQuery)); | Russian translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.ru-RU.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.ru-RU.js | MIT |
(function($){
$.fn.wysihtml5.locale["el-GR"] = {
font_styles: {
normal: "Απλό κείμενο",
h1: "Κεφαλίδα 1",
h2: "Κεφαλίδα 2",
h3: "Κεφαλίδα 3"
},
emphasis: {
bold: "B",
italic: "I",
underline: "U"
},
lists: {
unordered: "Λίστα με κουκκίδες",
ordered: "Αριθμημένη λίστα",
outdent: "Μείωση εσοχής",
indent: "Αύξηση εσοχής"
},
link: {
insert: "Εισαγωγή Συνδέσμου",
cancel: "Άκυρο"
},
image: {
insert: "Εισαγωγή Εικόνας",
cancel: "Άκυρο"
},
html: {
edit: "Επεξεργασία HTML"
},
colours: {
black: "Μαύρο",
silver: "Ασημί",
gray: "Γκρι",
maroon: "Καφέ",
red: "Κόκκινο",
purple: "Μωβ",
green: "Πράσινο",
olive: "Λαδί",
navy: "Βαθύ Μπλε",
blue: "Μπλε",
orange: "Πορτοκαλί"
}
};
}(jQuery)); | Greek translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.el-GR.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.el-GR.js | MIT |
(function($){
$.fn.wysihtml5.locale["zh-TW"] = {
font_styles: {
normal: "內文",
h1: "標題 1",
h2: "標題 2",
h3: "標題 3"
},
emphasis: {
bold: "粗體",
italic: "斜體",
underline: "底線"
},
lists: {
unordered: "項目符號",
ordered: "編號列表",
outdent: "減少縮排",
indent: "增加縮排"
},
link: {
insert: "插入超連結",
cancel: "取消"
},
image: {
insert: "插入圖片連結",
cancel: "取消"
},
html: {
edit: "HTML原始碼"
},
colours: {
black: "黑色",
silver: "銀色",
gray: "灰色",
maroon: "栗色",
red: "红色",
purple: "紫色",
green: "綠色",
olive: "橄欖色",
navy: "深藍色",
blue: "藍色",
orange: "橙色"
}
};
}(jQuery)); | Chinese Traditional translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.zh-TW.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.zh-TW.js | MIT |
(function($){
$.fn.wysihtml5.locale["hr-HR"] = {
font_styles: {
normal: "Normalan tekst",
h1: "Naslov 1",
h2: "Naslov 2",
h3: "Naslov 3"
},
emphasis: {
bold: "Podebljano",
italic: "Nakrivljeno",
underline: "Podcrtano"
},
lists: {
unordered: "Nesortirana lista",
ordered: "Sortirana lista",
outdent: "Izdubi",
indent: "Udubi"
},
link: {
insert: "Umetni poveznicu",
cancel: "Otkaži"
},
image: {
insert: "Umetni sliku",
cancel: "Otkaži"
},
html: {
edit: "Izmjeni HTML"
},
colours: {
black: "Crna",
silver: "Srebrna",
gray: "Siva",
maroon: "Kestenjasta",
red: "Crvena",
purple: "Ljubičasta",
green: "Zelena",
olive: "Maslinasta",
navy: "Mornarska",
blue: "Plava",
orange: "Narandžasta"
}
};
}(jQuery)); | Croatian localisation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.hr-HR.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.hr-HR.js | MIT |
(function($){
$.fn.wysihtml5.locale["bg-BG"] = {
font_styles: {
normal: "Нормален текст",
h1: "Заглавие 1",
h2: "Заглавие 2",
h3: "Заглавие 3"
},
emphasis: {
bold: "Удебелен",
italic: "Курсив",
underline: "Подчертан"
},
lists: {
unordered: "Неподреден списък",
ordered: "Подреден списък",
outdent: "Намали отстояние",
indent: "Увеличи отстояние"
},
link: {
insert: "Вмъкни връзка",
cancel: "Отмени"
},
image: {
insert: "Вмъкни картинка",
cancel: "Отмени"
},
html: {
edit: "Редакртирай HTML"
},
colours: {
black: "Черен",
silver: "Сребърен",
gray: "Сив",
maroon: "Коричневый",
red: "Червен",
purple: "Виолетов",
green: "Зелен",
olive: "Маслинен",
navy: "Морско син",
blue: "Син",
orange: "Оранжев"
}
};
}(jQuery)); | Bulgarian translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.bg-BG.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.bg-BG.js | MIT |
(function($){
$.fn.wysihtml5.locale["mo-MD"] = {
font_styles: {
normal: "Normal",
h1: "Titlu 1",
h2: "Titlu 2"
},
emphasis: {
bold: "Bold",
italic: "Cursiv",
underline: "Accentuat"
},
lists: {
unordered: "Neordonata",
ordered: "Ordonata",
outdent: "Margine",
indent: "zimțuire"
},
link: {
insert: "Indroduce link-ul",
cancel: "Anula"
},
image: {
insert: "Insera imagina",
cancel: "Anula"
},
html: {
edit: "Editare HTML"
},
colours: {
black: "Negru",
silver: "Argint",
gray: "Gri",
maroon: "Castaniu",
red: "Roșu",
purple: "Violet",
green: "Verde",
olive: "Oliv",
navy: "Marin",
blue: "Albastru",
orange: "Portocaliu"
}
};
}(jQuery)); | Moldavian translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.mo-MD.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.mo-MD.js | MIT |
(function($){
$.fn.wysihtml5.locale["zh-CN"] = {
font_styles: {
normal: "正文",
h1: "标题 1",
h2: "标题 2",
h3: "标题 3"
},
emphasis: {
bold: "粗体",
italic: "斜体",
underline: "下划线"
},
lists: {
unordered: "项目符号",
ordered: "编号",
outdent: "减少缩进",
indent: "增加缩进"
},
link: {
insert: "插入链接",
cancel: "取消"
},
image: {
insert: "插入图片",
cancel: "取消"
},
html: {
edit: "HTML代码"
},
colours: {
black: "黑色",
silver: "银色",
gray: "灰色",
maroon: "赤红色",
red: "红色",
purple: "紫色",
green: "绿色",
olive: "橄榄色",
navy: "深蓝色",
blue: "蓝色",
orange: "橙色"
}
};
}(jQuery)); | Chinese translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.zh-CN.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.zh-CN.js | MIT |
(function($){
$.fn.wysihtml5.locale["es-ES"] = {
font_styles: {
normal: "Texto normal",
h1: "Título 1",
h2: "Título 2",
h3: "Título 3"
},
emphasis: {
bold: "Negrita",
italic: "Itálica",
underline: "Subrayado"
},
lists: {
unordered: "Lista desordenada",
ordered: "Lista ordenada",
outdent: "Eliminar sangría",
indent: "Agregar sangría"
},
link: {
insert: "Insertar enlace",
cancel: "Cancelar"
},
image: {
insert: "Insertar imágen",
cancel: "Cancelar"
},
html: {
edit: "Editar HTML"
},
colours: {
black: "Negro",
silver: "Plata",
gray: "Gris",
maroon: "Marrón",
red: "Rojo",
purple: "Púrpura",
green: "Verde",
olive: "Oliva",
navy: "Azul Marino",
blue: "Azul",
orange: "Naranja"
}
};
}(jQuery)); | Uruguayan spanish translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.es-ES.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.es-ES.js | MIT |
(function($){
$.fn.wysihtml5.locale["ja-JP"] = {
font_styles: {
normal: "通常の文字",
h1: "見出し1",
h2: "見出し2",
h3: "見出し3"
},
emphasis: {
bold: "太字",
italic: "斜体",
underline: "下線"
},
lists: {
unordered: "点字リスト",
ordered: "数字リスト",
outdent: "左寄せ",
indent: "右寄せ"
},
link: {
insert: "リンクの挿入",
cancel: "キャンセル"
},
image: {
insert: "画像の挿入",
cancel: "キャンセル"
},
html: {
edit: "HTMLを編集"
},
colours: {
black: "黒色",
silver: "シルバー",
gray: "グレー",
maroon: "栗色",
red: "赤色",
purple: "紫色",
green: "緑色",
olive: "オリーブ",
navy: "ネイビー",
blue: "青色",
orange: "オレンジ"
}
};
}(jQuery)); | Japanese translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.ja-JP.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.ja-JP.js | MIT |
(function($){
$.fn.wysihtml5.locale["nl-NL"] = {
font_styles: {
normal: "Normale Tekst",
h1: "Kop 1",
h2: "Kop 2",
h3: "Kop 3"
},
emphasis: {
bold: "Vet",
italic: "Cursief",
underline: "Onderstrepen"
},
lists: {
unordered: "Ongeordende lijst",
ordered: "Geordende lijst",
outdent: "Inspringen verkleinen",
indent: "Inspringen vergroten"
},
link: {
insert: "Link invoegen",
cancel: "Annuleren"
},
image: {
insert: "Afbeelding invoegen",
cancel: "Annuleren"
},
html: {
edit: "HTML bewerken"
},
colours: {
black: "Zwart",
silver: "Zilver",
gray: "Grijs",
maroon: "Kastanjebruin",
red: "Rood",
purple: "Paars",
green: "Groen",
olive: "Olijfgroen",
navy: "Donkerblauw",
blue: "Blauw",
orange: "Oranje"
}
};
}(jQuery)); | Dutch translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.nl-NL.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.nl-NL.js | MIT |
(function($){
$.fn.wysihtml5.locale["mo-MD"] = {
font_styles: {
normal: "نص عادي",
h1: "عنوان رئيسي 1",
h2: "عنوان رئيسي 2",
h3: "عنوان رئيسي 3",
},
emphasis: {
bold: "عريض",
italic: "مائل",
underline: "تحته خط"
},
lists: {
unordered: "قائمة منقطة",
ordered: "قائمة مرقمة",
outdent: "محاذاه للخارج",
indent: "محاذاه للداخل"
},
link: {
insert: "إضافة رابط",
cancel: "إلغاء"
},
image: {
insert: "إضافة صورة",
cancel: "إلغاء"
},
html: {
edit: "تعديل HTML"
},
colours: {
black: "أسود",
silver: "فضي",
gray: "رمادي",
maroon: "بني",
red: "أحمر",
purple: "بنفسجي",
green: "أخضر",
olive: "زيتوني",
navy: "أزرق قاتم",
blue: "أزرق نيلي",
orange: "برتقالي"
}
};
}(jQuery)); | Arabic translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.ar-AR.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.ar-AR.js | MIT |
(function($){
$.fn.wysihtml5.locale["ua-UA"] = {
font_styles: {
normal: "Звичайний текст",
h1: "Заголовок 1",
h2: "Заголовок 2",
h3: "Заголовок 3"
},
emphasis: {
bold: "Напівжирний",
italic: "Курсив",
underline: "Підкреслений"
},
lists: {
unordered: "Маркований список",
ordered: "Нумерований список",
outdent: "Зменшити відступ",
indent: "Збільшити відступ"
},
link: {
insert: "Вставити посилання",
cancel: "Відміна"
},
image: {
insert: "Вставити зображення",
cancel: "Відміна"
},
html: {
edit: "HTML код"
},
colours: {
black: "Чорний",
silver: "Срібний",
gray: "Сірий",
maroon: "Коричневий",
red: "Червоний",
purple: "Фіолетовий",
green: "Зелений",
olive: "Оливковий",
navy: "Темно-синій",
blue: "Синій",
orange: "Помаранчевий"
}
};
}(jQuery)); | Ukrainian translation for bootstrap-wysihtml5 | (anonymous) ( $ ) | javascript | jhollingworth/bootstrap-wysihtml5 | src/locales/bootstrap-wysihtml5.ua-UA.js | https://github.com/jhollingworth/bootstrap-wysihtml5/blob/master/src/locales/bootstrap-wysihtml5.ua-UA.js | MIT |
function issueCommand(command, properties, message) {
const cmd = new Command(command, properties, message);
process.stdout.write(cmd.toString() + os.EOL);
} | Commands
Command Format:
::name key=value,key=value::message
Examples:
::warning::This is the message
::set-env name=MY_VAR::some value | issueCommand ( command , properties , message ) | javascript | aws-actions/amazon-ecr-login | dist/index.js | https://github.com/aws-actions/amazon-ecr-login/blob/master/dist/index.js | MIT |
var bd09togcj02 = function bd09togcj02(bd_lng, bd_lat) {
var bd_lng = +bd_lng;
var bd_lat = +bd_lat;
var x = bd_lng - 0.0065;
var y = bd_lat - 0.006;
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
var gg_lng = z * Math.cos(theta);
var gg_lat = z * Math.sin(theta);
return [gg_lng, gg_lat]
}; | 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02) 的转换
即 百度 转 谷歌、高德
@param bd_lng
@param bd_lat
@returns {*[]} | bd09togcj02 ( bd_lng , bd_lat ) | javascript | wandergis/coordtransform | index.js | https://github.com/wandergis/coordtransform/blob/master/index.js | MIT |
var gcj02tobd09 = function gcj02tobd09(lng, lat) {
var lat = +lat;
var lng = +lng;
var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
var bd_lng = z * Math.cos(theta) + 0.0065;
var bd_lat = z * Math.sin(theta) + 0.006;
return [bd_lng, bd_lat]
}; | 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
即 谷歌、高德 转 百度
@param lng
@param lat
@returns {*[]} | gcj02tobd09 ( lng , lat ) | javascript | wandergis/coordtransform | index.js | https://github.com/wandergis/coordtransform/blob/master/index.js | MIT |
var wgs84togcj02 = function wgs84togcj02(lng, lat) {
var lat = +lat;
var lng = +lng;
if (out_of_china(lng, lat)) {
return [lng, lat]
} else {
var dlat = transformlat(lng - 105.0, lat - 35.0);
var dlng = transformlng(lng - 105.0, lat - 35.0);
var radlat = lat / 180.0 * PI;
var magic = Math.sin(radlat);
magic = 1 - ee * magic * magic;
var sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
var mglat = lat + dlat;
var mglng = lng + dlng;
return [mglng, mglat]
}
}; | WGS-84 转 GCJ-02
@param lng
@param lat
@returns {*[]} | wgs84togcj02 ( lng , lat ) | javascript | wandergis/coordtransform | index.js | https://github.com/wandergis/coordtransform/blob/master/index.js | MIT |
var gcj02towgs84 = function gcj02towgs84(lng, lat) {
var lat = +lat;
var lng = +lng;
if (out_of_china(lng, lat)) {
return [lng, lat]
} else {
var dlat = transformlat(lng - 105.0, lat - 35.0);
var dlng = transformlng(lng - 105.0, lat - 35.0);
var radlat = lat / 180.0 * PI;
var magic = Math.sin(radlat);
magic = 1 - ee * magic * magic;
var sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
var mglat = lat + dlat;
var mglng = lng + dlng;
return [lng * 2 - mglng, lat * 2 - mglat]
}
}; | GCJ-02 转换为 WGS-84
@param lng
@param lat
@returns {*[]} | gcj02towgs84 ( lng , lat ) | javascript | wandergis/coordtransform | index.js | https://github.com/wandergis/coordtransform/blob/master/index.js | MIT |
var out_of_china = function out_of_china(lng, lat) {
var lat = +lat;
var lng = +lng;
// 纬度 3.86~53.55, 经度 73.66~135.05
return !(lng > 73.66 && lng < 135.05 && lat > 3.86 && lat < 53.55);
}; | 判断是否在国内,不在国内则不做偏移
@param lng
@param lat
@returns {boolean} | out_of_china ( lng , lat ) | javascript | wandergis/coordtransform | index.js | https://github.com/wandergis/coordtransform/blob/master/index.js | MIT |
toJson(content, type){
const _ts = this;
type = type || 'html';
let json = '',
sortOutJson;
if (type === 'markdown') {
json = new _ts.m.toJson(_ts.md2html(content)).getData();
} else if (type === 'html') {
json = new _ts.m.toJson(content).getData();
};
json.theme = 'light';
return json;
} | html2json
@param {string} content html或markdown字符串
@param {string} type 'html'、'marddown'
@param {object} app 小程序对象 | toJson ( content , type ) | javascript | nslogx/Gitter | src/components/towxml/main.js | https://github.com/nslogx/Gitter/blob/master/src/components/towxml/main.js | Apache-2.0 |
isEmpty(object) {
for (const i in object) {
return false;
}
return true;
}, | 判断一个 object 是否为 空
@param {object} object | isEmpty ( object ) | javascript | nslogx/Gitter | src/components/painter/painter.js | https://github.com/nslogx/Gitter/blob/master/src/components/painter/painter.js | Apache-2.0 |
String.prototype.toPx = function toPx(minus) {
let reg;
if (minus) {
reg = /^-?[0-9]+([.]{1}[0-9]+){0,1}(rpx|px)$/g;
} else {
reg = /^[0-9]+([.]{1}[0-9]+){0,1}(rpx|px)$/g;
}
const results = reg.exec(this);
if (!this || !results) {
console.error(`The size: ${this} is illegal`);
return 0;
}
const unit = results[2];
const value = parseFloat(this);
let res = 0;
if (unit === 'rpx') {
res = Math.round(value * screenK);
} else if (unit === 'px') {
res = value;
}
return res;
}; | 是否支持负数
@param {Boolean} minus 是否支持负数 | toPx ( minus ) | javascript | nslogx/Gitter | src/components/painter/painter.js | https://github.com/nslogx/Gitter/blob/master/src/components/painter/painter.js | Apache-2.0 |
draw: function (str, ctx, startX, startY, cavW, cavH, bg, color, $this, ecc) {
var that = this;
ecclevel = ecc || ecclevel;
if (!ctx) {
console.warn('No canvas provided to draw QR code in!')
return;
}
var size = Math.min(cavW, cavH);
str = that.utf16to8(str);//增加中文显示
var frame = that.getFrame(str);
var px = size / width;
if (bg) {
ctx.setFillStyle(bg)
ctx.fillRect(startX, startY, cavW, cavW);
}
ctx.setFillStyle(color || 'black');
for (var i = 0; i < width; i++) {
for (var j = 0; j < width; j++) {
if (frame[j * width + i]) {
ctx.fillRect(startX + px * i, startY + px * j, px, px);
}
}
}
} | 新增$this参数,传入组件的this,兼容在组件中生成
@param bg 目前只能设置颜色值 | draw ( str , ctx , startX , startY , cavW , cavH , bg , color , $this , ecc ) | javascript | nslogx/Gitter | src/components/painter/lib/qrcode.js | https://github.com/nslogx/Gitter/blob/master/src/components/painter/lib/qrcode.js | Apache-2.0 |
/* eslint-disable */
function equal(a, b) {
if (a === b) return true;
if (a && b && typeof a == 'object' && typeof b == 'object') {
var arrA = Array.isArray(a)
, arrB = Array.isArray(b)
, i
, length
, key;
if (arrA && arrB) {
length = a.length;
if (length != b.length) return false;
for (i = length; i-- !== 0;)
if (!equal(a[i], b[i])) return false;
return true;
}
if (arrA != arrB) return false;
var dateA = a instanceof Date
, dateB = b instanceof Date;
if (dateA != dateB) return false;
if (dateA && dateB) return a.getTime() == b.getTime();
var regexpA = a instanceof RegExp
, regexpB = b instanceof RegExp;
if (regexpA != regexpB) return false;
if (regexpA && regexpB) return a.toString() == b.toString();
var keys = Object.keys(a);
length = keys.length;
if (length !== Object.keys(b).length)
return false;
for (i = length; i-- !== 0;)
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
for (i = length; i-- !== 0;) {
key = keys[i];
if (!equal(a[key], b[key])) return false;
}
return true;
}
return a!==a && b!==b; | 深度对比两个对象是否一致
from: https://github.com/epoberezkin/fast-deep-equal
@param {Object} a 对象a
@param {Object} b 对象b
@return {Boolean} 是否相同 | equal ( a , b ) | javascript | nslogx/Gitter | src/components/painter/lib/util.js | https://github.com/nslogx/Gitter/blob/master/src/components/painter/lib/util.js | Apache-2.0 |
export const info = (name, option) => {
option = stringify(option)
report(name, option, 'info')
} | (信息)在粗粒度级别上突出强调应用程序的运行过程,打印一些感兴趣的或者重要的信息。
@param {string} name 错误名字
@param {string} message 错误信息
@param {Objec} option 可选 一般信息 | info | javascript | nslogx/Gitter | src/utils/log.js | https://github.com/nslogx/Gitter/blob/master/src/utils/log.js | Apache-2.0 |
export const warn = (name, option) => {
option = stringify(option)
report(name, option, 'warn')
} | (警告)表明会出现潜在错误的情形,有些信息不是错误信息,但是也要上报一些提示。
@param {string} name 错误名字
@param {Object} option 错误信息,通常是 fail 返回的 | warn | javascript | nslogx/Gitter | src/utils/log.js | https://github.com/nslogx/Gitter/blob/master/src/utils/log.js | Apache-2.0 |
export const debug = (name, option) => {
// todo: 之后增加详细调用 stack
option = stringify(option)
report(name, option, 'debug')
} | (调试)指出细粒度信息事件对调试应用程序是非常有帮助的,主要用于开发过程中打印一些运行信息。
@param {string} name 错误名字
@param {string} message 错误信息
@param {Objec} option 可选 一般信息 | debug | javascript | nslogx/Gitter | src/utils/log.js | https://github.com/nslogx/Gitter/blob/master/src/utils/log.js | Apache-2.0 |
export const error = (name, option) => {
option = stringify(option)
report(name, option, 'error')
} | (错误)指出虽然发生错误事件,但仍然不影响系统的继续运行。
@param {string} name 错误名字
@param {Object} option 错误信息,通常是 fail 返回的 | error | javascript | nslogx/Gitter | src/utils/log.js | https://github.com/nslogx/Gitter/blob/master/src/utils/log.js | Apache-2.0 |
export const fatal = (name, option) => {
option = stringify(option)
report(name, option, 'fatal')
} | (致命)指出每个严重的错误事件将会导致应用程序的退出。
@param {string} name 错误名字
@param {Object} option 错误信息,通常是 fail 返回的 | fatal | javascript | nslogx/Gitter | src/utils/log.js | https://github.com/nslogx/Gitter/blob/master/src/utils/log.js | Apache-2.0 |
export const logError = (name, action, info) => {
if (!info) {
info = 'empty'
}
try {
var device = JSON.stringify(deviceInfo)
} catch (e) {
console.error('not support getSystemInfoSync api', err.message)
}
let time = formatTime(new Date())
console.error(time, name, action, info, device)
// if (typeof action !== 'object') {
// fundebug.notify(name, action, info)
// }
// fundebug.notifyError(info, { name, action, device, time })
if (typeof info === 'object') {
info = JSON.stringify(info)
}
} | @param {string} name 错误名字
@param {string} action 错误动作描述
@param {string} info 错误信息,通常是 fail 返回的 | logError | javascript | nslogx/Gitter | src/utils/error.js | https://github.com/nslogx/Gitter/blob/master/src/utils/error.js | Apache-2.0 |
async function create(options = {}) {
const {initSkeleton} = require('./init-skeleton');
const BrunchError = require('./utils/error');
const loggy = require('loggy');
// Check for legacy syntax
if (options.parent) {
const rawArgs = options.parent.rawArgs;
const newArgs = rawArgs.slice(rawArgs.indexOf('new') + 1);
const oldSyntax = !options.skeleton && newArgs.length === 2;
if (oldSyntax) {
throw new BrunchError('LEGACY_NEW_SYNTAX', {
skeleton: newArgs[0],
path: newArgs[1],
});
}
}
try {
return await initSkeleton(options.skeleton, options.path);
} catch (error) {
loggy.error(error);
}
}; | Initialize new brunch project.
@param {Object} options - skeleton like 'simple', path like '.' | create ( options = { } ) | javascript | brunch/brunch | lib/index.js | https://github.com/brunch/brunch/blob/master/lib/index.js | MIT |
function configureAsError(rules) {
return fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
} | @param {object} rules - rules object mapping rule name to rule module
@returns {Record<string, SEVERITY_ERROR | 'error'>} | configureAsError ( rules ) | javascript | jsx-eslint/eslint-plugin-react | index.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/index.js | MIT |
function isPropTypesDeclaration(node) {
if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
// Flow support
if (node.typeAnnotation && node.key.name === 'props') {
return true;
}
}
return astUtil.getPropertyName(node) === 'propTypes';
} | Checks if the Identifier node passed in looks like a propTypes declaration.
@param {ASTNode} node The node to check. Must be an Identifier node.
@returns {boolean} `true` if the node is a propTypes declaration, `false` if not | isPropTypesDeclaration ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function isContextTypesDeclaration(node) {
if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
// Flow support
if (node.typeAnnotation && node.key.name === 'context') {
return true;
}
}
return astUtil.getPropertyName(node) === 'contextTypes';
} | Checks if the node passed in looks like a contextTypes declaration.
@param {ASTNode} node The node to check.
@returns {boolean} `true` if the node is a contextTypes declaration, `false` if not | isContextTypesDeclaration ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function isContextTypeDeclaration(node) {
return astUtil.getPropertyName(node) === 'contextType';
} | Checks if the node passed in looks like a contextType declaration.
@param {ASTNode} node The node to check.
@returns {boolean} `true` if the node is a contextType declaration, `false` if not | isContextTypeDeclaration ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function isChildContextTypesDeclaration(node) {
return astUtil.getPropertyName(node) === 'childContextTypes';
} | Checks if the node passed in looks like a childContextTypes declaration.
@param {ASTNode} node The node to check.
@returns {boolean} `true` if the node is a childContextTypes declaration, `false` if not | isChildContextTypesDeclaration ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function isDefaultPropsDeclaration(node) {
const propName = astUtil.getPropertyName(node);
return (propName === 'defaultProps' || propName === 'getDefaultProps');
} | Checks if the Identifier node passed in looks like a defaultProps declaration.
@param {ASTNode} node The node to check. Must be an Identifier node.
@returns {boolean} `true` if the node is a defaultProps declaration, `false` if not | isDefaultPropsDeclaration ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function isDisplayNameDeclaration(node) {
switch (node.type) {
case 'ClassProperty':
case 'PropertyDefinition':
return node.key && node.key.name === 'displayName';
case 'Identifier':
return node.name === 'displayName';
case 'Literal':
return node.value === 'displayName';
default:
return false;
}
} | Checks if we are declaring a display name
@param {ASTNode} node The AST node being checked.
@returns {boolean} True if we are declaring a display name, false if not. | isDisplayNameDeclaration ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function isRequiredPropType(propTypeExpression) {
return propTypeExpression.type === 'MemberExpression'
&& propTypeExpression.property.name === 'isRequired';
} | Checks if the PropTypes MemberExpression node passed in declares a required propType.
@param {ASTNode} propTypeExpression node to check. Must be a `PropTypes` MemberExpression.
@returns {boolean} `true` if this PropType is required, `false` if not. | isRequiredPropType ( propTypeExpression ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function getTypeArguments(node) {
if ('typeArguments' in node) {
return node.typeArguments;
}
return node.typeParameters;
} | Returns the type arguments of a node or type parameters if type arguments are not available.
@param {ASTNode} node The node to get the type arguments from.
@returns {ASTNode} The type arguments or type parameters of the node. | getTypeArguments ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function getSuperTypeArguments(node) {
if ('superTypeArguments' in node) {
return node.superTypeArguments;
}
return node.superTypeParameters;
} | Returns the super type arguments of a node or super type parameters if type arguments are not available.
@param {ASTNode} node The node to get the super type arguments from.
@returns {ASTNode} The super type arguments or parameters of the node. | getSuperTypeArguments ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/props.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/props.js | MIT |
function isDOMComponent(node) {
const name = elementType(node);
return COMPAT_TAG_REGEX.test(name);
} | Checks if a node represents a DOM element according to React.
@param {object} node - JSXOpeningElement to check.
@returns {boolean} Whether or not the node corresponds to a DOM element. | isDOMComponent ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/jsx.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/jsx.js | MIT |
function isFragment(node, reactPragma, fragmentPragma) {
const name = node.openingElement.name;
// <Fragment>
if (name.type === 'JSXIdentifier' && name.name === fragmentPragma) {
return true;
}
// <React.Fragment>
if (
name.type === 'JSXMemberExpression'
&& name.object.type === 'JSXIdentifier'
&& name.object.name === reactPragma
&& name.property.type === 'JSXIdentifier'
&& name.property.name === fragmentPragma
) {
return true;
}
return false;
} | Test whether a JSXElement is a fragment
@param {JSXElement} node
@param {string} reactPragma
@param {string} fragmentPragma
@returns {boolean} | isFragment ( node , reactPragma , fragmentPragma ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/jsx.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/jsx.js | MIT |
function isJSX(node) {
return node && ['JSXElement', 'JSXFragment'].indexOf(node.type) >= 0;
} | Checks if a node represents a JSX element or fragment.
@param {object} node - node to check.
@returns {boolean} Whether or not the node if a JSX element or fragment. | isJSX ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/jsx.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/jsx.js | MIT |
function isJSXAttributeKey(node) {
return node.type === 'JSXAttribute'
&& node.name
&& node.name.type === 'JSXIdentifier'
&& node.name.name === 'key';
} | Check if node is like `key={...}` as in `<Foo key={...} />`
@param {ASTNode} node
@returns {boolean} | isJSXAttributeKey ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/jsx.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/jsx.js | MIT |
function isWhiteSpaces(value) {
return typeof value === 'string' ? /^\s*$/.test(value) : false;
} | Check if value has only whitespaces
@param {unknown} value
@returns {boolean} | isWhiteSpaces ( value ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/jsx.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/jsx.js | MIT |
function getTokenBeforeClosingBracket(node) {
const attributes = node.attributes;
if (!attributes || attributes.length === 0) {
return node.name;
}
return attributes[attributes.length - 1];
} | Find the token before the closing bracket.
@param {ASTNode} node - The JSX element node.
@returns {Token} The token before the closing bracket. | getTokenBeforeClosingBracket ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/getTokenBeforeClosingBracket.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/getTokenBeforeClosingBracket.js | MIT |
function findVariable(variables, name) {
return variables.some((variable) => variable.name === name);
} | Search a particular variable in a list
@param {Array} variables The variables list.
@param {string} name The name of the variable to search.
@returns {boolean} True if the variable was found, false if not. | findVariable ( variables , name ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/variable.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/variable.js | MIT |
function getVariable(variables, name) {
return variables.find((variable) => variable.name === name);
} | Find and return a particular variable in a list
@param {Array} variables The variables list.
@param {string} name The name of the variable to search.
@returns {Object} Variable if the variable was found, null if not. | getVariable ( variables , name ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/variable.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/variable.js | MIT |
function getVariableFromContext(context, node, name) {
let scope = getScope(context, node);
while (scope) {
let variable = getVariable(scope.variables, name);
if (!variable && scope.childScopes.length) {
variable = getVariable(scope.childScopes[0].variables, name);
if (!variable && scope.childScopes[0].childScopes.length) {
variable = getVariable(scope.childScopes[0].childScopes[0].variables, name);
}
}
if (variable) {
return variable;
}
scope = scope.upper;
}
return undefined;
} | Searches for a variable in the given scope.
@param {Object} context The current rule context.
@param {ASTNode} node The node to start looking from.
@param {string} name The name of the variable to search.
@returns {Object | undefined} Variable if the variable was found, undefined if not. | getVariableFromContext ( context , node , name ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/variable.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/variable.js | MIT |
function findVariableByName(context, node, name) {
const variable = getVariableFromContext(context, node, name);
if (!variable || !variable.defs[0] || !variable.defs[0].node) {
return null;
}
if (variable.defs[0].node.type === 'TypeAlias') {
return variable.defs[0].node.right;
}
if (variable.defs[0].type === 'ImportBinding') {
return variable.defs[0].node;
}
return variable.defs[0].node.init;
} | Find a variable by name in the current scope.
@param {Object} context The current rule context.
@param {ASTNode} node The node to check. Must be an Identifier node.
@param {string} name Name of the variable to look for.
@returns {ASTNode|null} Return null if the variable could not be found, ASTNode otherwise. | findVariableByName ( context , node , name ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/variable.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/variable.js | MIT |
function getLatestVariableDefinition(variable) {
return variable.defs[variable.defs.length - 1];
} | Returns the latest definition of the variable.
@param {Object} variable
@returns {Object | undefined} The latest variable definition or undefined. | getLatestVariableDefinition ( variable ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/variable.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/variable.js | MIT |
module.exports = function isCreateElement(context, node) {
if (!node.callee) {
return false;
}
if (
node.callee.type === 'MemberExpression'
&& node.callee.property.name === 'createElement'
&& node.callee.object
&& node.callee.object.name === pragmaUtil.getFromContext(context)
) {
return true;
}
if (
node.callee.name === 'createElement'
&& isDestructuredFromPragmaImport(context, node, 'createElement')
) {
return true;
}
return false;
}; | Checks if the node is a createElement call
@param {Context} context - The AST node being checked.
@param {ASTNode} node - The AST node being checked.
@returns {boolean} - True if node is a createElement call object literal, False if not. | isCreateElement ( context , node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/isCreateElement.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/isCreateElement.js | MIT |
add(node, confidence) {
const id = getId(node);
const list = Lists.get(this);
if (list[id]) {
if (confidence === 0 || list[id].confidence === 0) {
list[id].confidence = 0;
} else {
list[id].confidence = Math.max(list[id].confidence, confidence);
}
return list[id];
}
list[id] = {
node,
confidence,
};
return list[id];
} | Add a node to the components list, or update it if it's already in the list
@param {ASTNode} node The AST node being added.
@param {number} confidence Confidence in the component detection (0=banned, 1=maybe, 2=yes)
@returns {Object} Added component object | add ( node , confidence ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
get(node) {
const id = getId(node);
const item = Lists.get(this)[id];
if (item && item.confidence >= 1) {
return item;
}
return null;
} | Find a component in the list using its node
@param {ASTNode} node The AST node being searched.
@returns {Object} Component object, undefined if the component is not found or has confidence value of 0. | get ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
list() {
const thisList = Lists.get(this);
const list = {};
const usedPropTypes = {};
// Find props used in components for which we are not confident
Object.keys(thisList).filter((i) => thisList[i].confidence < 2).forEach((i) => {
let component = null;
let node = null;
node = thisList[i].node;
while (!component && node.parent) {
node = node.parent;
// Stop moving up if we reach a decorator
if (node.type === 'Decorator') {
break;
}
component = this.get(node);
}
if (component) {
const newUsedProps = (thisList[i].usedPropTypes || []).filter((propType) => !propType.node || propType.node.kind !== 'init');
const componentId = getId(component.node);
usedPropTypes[componentId] = mergeUsedPropTypes(usedPropTypes[componentId] || [], newUsedProps);
}
});
// Assign used props in not confident components to the parent component
Object.keys(thisList).filter((j) => thisList[j].confidence >= 2).forEach((j) => {
const id = getId(thisList[j].node);
list[j] = thisList[j];
if (usedPropTypes[id]) {
list[j].usedPropTypes = mergeUsedPropTypes(list[j].usedPropTypes || [], usedPropTypes[id]);
}
});
return list;
} | Return the components list
Components for which we are not confident are not returned
@returns {Object} Components list | list ( ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
length() {
const list = Lists.get(this);
return values(list).filter((component) => component.confidence >= 2).length;
} | Return the length of the components list
Components for which we are not confident are not counted
@returns {number} Components list length | length ( ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
getDefaultReactImports() {
return ReactImports.get(this).defaultReactImports;
} | Return the node naming the default React import
It can be used to determine the local name of import, even if it's imported
with an unusual name.
@returns {ASTNode} React default import node | getDefaultReactImports ( ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
getNamedReactImports() {
return ReactImports.get(this).namedReactImports;
} | Return the nodes of all React named imports
@returns {Object} The list of React named imports | getNamedReactImports ( ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
function mergeRules(rules) {
/** @type {Map<string, Function[]>} */
const handlersByKey = new Map();
rules.forEach((rule) => {
Object.keys(rule).forEach((key) => {
const fns = handlersByKey.get(key);
if (!fns) {
handlersByKey.set(key, [rule[key]]);
} else {
fns.push(rule[key]);
}
});
});
/** @type {{ [key: string]: Function }} */
return fromEntries(map(iterFrom(handlersByKey), (entry) => [
entry[0],
function mergedHandler(node) {
entry[1].forEach((fn) => {
fn(node);
});
},
]));
} | Merge many eslint rules into one
@param {{[_: string]: Function}[]} rules the returned values for eslint rule.create(context)
@returns {{[_: string]: Function}} merged rule | mergeRules ( rules ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
isDestructuredFromPragmaImport(node, variable) {
return isDestructuredFromPragmaImport(context, node, variable);
}, | Check if variable is destructured from pragma import
@param {ASTNode} node The AST node to check
@param {string} variable The variable name to check
@returns {boolean} True if createElement is destructured from the pragma | isDestructuredFromPragmaImport ( node , variable ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
isReturningJSX(node, strict) {
return jsxUtil.isReturningJSX(context, node, strict, true);
}, | @param {ASTNode} node
@param {boolean=} strict
@returns {boolean} | isReturningJSX ( node , strict ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
getNameOfWrappedComponent(node) {
if (node.length < 1) {
return null;
}
const body = node[0].body;
if (!body) {
return null;
}
if (body.type === 'JSXElement') {
return this.getComponentNameFromJSXElement(body);
}
if (body.type === 'BlockStatement') {
const jsxElement = body.body.find((item) => item.type === 'ReturnStatement');
return jsxElement
&& jsxElement.argument
&& this.getComponentNameFromJSXElement(jsxElement.argument);
}
return null;
}, | Getting the first JSX element's name.
@param {object} node
@returns {string | null} | getNameOfWrappedComponent ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
getDetectedComponents() {
const list = components.list();
return values(list).filter((val) => {
if (val.node.type === 'ClassDeclaration') {
return true;
}
if (
val.node.type === 'ArrowFunctionExpression'
&& val.node.parent
&& val.node.parent.type === 'VariableDeclarator'
&& val.node.parent.id
) {
return true;
}
return false;
}).map((val) => {
if (val.node.type === 'ArrowFunctionExpression') return val.node.parent.id.name;
return val.node.id && val.node.id.name;
});
}, | Get the list of names of components created till now
@returns {string | boolean} | getDetectedComponents ( ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
nodeWrapsComponent(node) {
const childComponent = this.getNameOfWrappedComponent(node.arguments);
const componentList = this.getDetectedComponents();
return !!childComponent && arrayIncludes(componentList, childComponent);
}, | It will check whether memo/forwardRef is wrapping existing component or
creating a new one.
@param {object} node
@returns {boolean} | nodeWrapsComponent ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
getParentComponent(node) {
return (
componentUtil.getParentES6Component(context, node)
|| componentUtil.getParentES5Component(context, node)
|| utils.getParentStatelessComponent(node)
);
}, | Get the parent component node from the current scope
@param {ASTNode} node
@returns {ASTNode} component node, null if we are not in a component | getParentComponent ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
isInAllowedPositionForComponent(node) {
switch (node.parent.type) {
case 'VariableDeclarator':
case 'AssignmentExpression':
case 'Property':
case 'ReturnStatement':
case 'ExportDefaultDeclaration':
case 'ArrowFunctionExpression': {
return true;
}
case 'SequenceExpression': {
return utils.isInAllowedPositionForComponent(node.parent)
&& node === node.parent.expressions[node.parent.expressions.length - 1];
}
default:
return false;
}
}, | @param {ASTNode} node
@returns {boolean} | isInAllowedPositionForComponent ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
getStatelessComponent(node) {
const parent = node.parent;
if (
node.type === 'FunctionDeclaration'
&& (!node.id || isFirstLetterCapitalized(node.id.name))
&& utils.isReturningJSXOrNull(node)
) {
return node;
}
if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
const isPropertyAssignment = parent.type === 'AssignmentExpression'
&& parent.left.type === 'MemberExpression';
const isModuleExportsAssignment = isPropertyAssignment
&& parent.left.object.name === 'module'
&& parent.left.property.name === 'exports';
if (node.parent.type === 'ExportDefaultDeclaration') {
if (utils.isReturningJSX(node)) {
return node;
}
return undefined;
}
if (node.parent.type === 'VariableDeclarator' && utils.isReturningJSXOrNull(node)) {
if (isFirstLetterCapitalized(node.parent.id.name)) {
return node;
}
return undefined;
}
// case: const any = () => { return (props) => null }
// case: const any = () => (props) => null
if (
(node.parent.type === 'ReturnStatement' || (node.parent.type === 'ArrowFunctionExpression' && node.parent.expression))
&& !utils.isReturningJSX(node)
) {
return undefined;
}
// case: any = () => { return => null }
// case: any = () => null
if (node.parent.type === 'AssignmentExpression' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
if (isFirstLetterCapitalized(node.parent.left.name)) {
return node;
}
return undefined;
}
// case: any = () => () => null
if (node.parent.type === 'ArrowFunctionExpression' && node.parent.parent.type === 'AssignmentExpression' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
if (isFirstLetterCapitalized(node.parent.parent.left.name)) {
return node;
}
return undefined;
}
// case: { any: () => () => null }
if (node.parent.type === 'ArrowFunctionExpression' && node.parent.parent.type === 'Property' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
if (isFirstLetterCapitalized(node.parent.parent.key.name)) {
return node;
}
return undefined;
}
// case: any = function() {return function() {return null;};}
if (node.parent.type === 'ReturnStatement') {
if (isFirstLetterCapitalized(node.id && node.id.name)) {
return node;
}
const functionExpr = node.parent.parent.parent;
if (functionExpr.parent.type === 'AssignmentExpression' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
if (isFirstLetterCapitalized(functionExpr.parent.left.name)) {
return node;
}
return undefined;
}
}
// case: { any: function() {return function() {return null;};} }
if (node.parent.type === 'ReturnStatement') {
const functionExpr = node.parent.parent.parent;
if (functionExpr.parent.type === 'Property' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
if (isFirstLetterCapitalized(functionExpr.parent.key.name)) {
return node;
}
return undefined;
}
}
// for case abc = { [someobject.somekey]: props => { ... return not-jsx } }
if (
node.parent
&& node.parent.key
&& node.parent.key.type === 'MemberExpression'
&& !utils.isReturningJSX(node)
&& !utils.isReturningOnlyNull(node)
) {
return undefined;
}
if (
node.parent.type === 'Property' && (
(node.parent.method && !node.parent.computed) // case: { f() { return ... } }
|| (!node.id && !node.parent.computed) // case: { f: () => ... }
)
) {
if (
isFirstLetterCapitalized(node.parent.key.name)
&& utils.isReturningJSX(node)
) {
return node;
}
return undefined;
}
// Case like `React.memo(() => <></>)` or `React.forwardRef(...)`
const pragmaComponentWrapper = utils.getPragmaComponentWrapper(node);
if (pragmaComponentWrapper && utils.isReturningJSXOrNull(node)) {
return pragmaComponentWrapper;
}
if (!(utils.isInAllowedPositionForComponent(node) && utils.isReturningJSXOrNull(node))) {
return undefined;
}
if (utils.isParentComponentNotStatelessComponent(node)) {
return undefined;
}
if (node.id) {
return isFirstLetterCapitalized(node.id.name) ? node : undefined;
}
if (
isPropertyAssignment
&& !isModuleExportsAssignment
&& !isFirstLetterCapitalized(parent.left.property.name)
) {
return undefined;
}
if (parent.type === 'Property' && utils.isReturningOnlyNull(node)) {
return undefined;
}
return node;
}
return undefined;
}, | Get node if node is a stateless component, or node.parent in cases like
`React.memo` or `React.forwardRef`. Otherwise returns `undefined`.
@param {ASTNode} node
@returns {ASTNode | undefined} | getStatelessComponent ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
getParentStatelessComponent(node) {
let scope = getScope(context, node);
while (scope) {
const statelessComponent = utils.getStatelessComponent(scope.block);
if (statelessComponent) {
return statelessComponent;
}
scope = scope.upper;
}
return null;
}, | Get the parent stateless component node from the current scope
@param {ASTNode} node The AST node being checked
@returns {ASTNode} component node, null if we are not in a component | getParentStatelessComponent ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
getRelatedComponent(node) {
let i;
let j;
let k;
let l;
let componentNode;
// Get the component path
const componentPath = [];
let nodeTemp = node;
while (nodeTemp) {
if (nodeTemp.property && nodeTemp.property.type === 'Identifier') {
componentPath.push(nodeTemp.property.name);
}
if (nodeTemp.object && nodeTemp.object.type === 'Identifier') {
componentPath.push(nodeTemp.object.name);
}
nodeTemp = nodeTemp.object;
}
componentPath.reverse();
const componentName = componentPath.slice(0, componentPath.length - 1).join('.');
// Find the variable in the current scope
const variableName = componentPath.shift();
if (!variableName) {
return null;
}
const variableInScope = variableUtil.getVariableFromContext(context, node, variableName);
if (!variableInScope) {
return null;
}
// Try to find the component using variable references
variableInScope.references.some((ref) => {
let refId = ref.identifier;
if (refId.parent && refId.parent.type === 'MemberExpression') {
refId = refId.parent;
}
if (getText(context, refId) !== componentName) {
return false;
}
if (refId.type === 'MemberExpression') {
componentNode = refId.parent.right;
} else if (
refId.parent
&& refId.parent.type === 'VariableDeclarator'
&& refId.parent.init
&& refId.parent.init.type !== 'Identifier'
) {
componentNode = refId.parent.init;
}
return true;
});
if (componentNode) {
// Return the component
return components.add(componentNode, 1);
}
// Try to find the component using variable declarations
const defs = variableInScope.defs;
const defInScope = defs.find((def) => (
def.type === 'ClassName'
|| def.type === 'FunctionName'
|| def.type === 'Variable'
));
if (!defInScope || !defInScope.node) {
return null;
}
componentNode = defInScope.node.init || defInScope.node;
// Traverse the node properties to the component declaration
for (i = 0, j = componentPath.length; i < j; i++) {
if (!componentNode.properties) {
continue; // eslint-disable-line no-continue
}
for (k = 0, l = componentNode.properties.length; k < l; k++) {
if (componentNode.properties[k].key && componentNode.properties[k].key.name === componentPath[i]) {
componentNode = componentNode.properties[k];
break;
}
}
if (!componentNode || !componentNode.value) {
return null;
}
componentNode = componentNode.value;
}
// Return the component
return components.add(componentNode, 1);
}, | Get the related component from a node
@param {ASTNode} node The AST node being checked (must be a MemberExpression).
@returns {ASTNode | null} component node, null if we cannot find the component | getRelatedComponent ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
isReactHookCall(node, expectedHookNames) {
if (!astUtil.isCallExpression(node)) {
return false;
}
const defaultReactImports = components.getDefaultReactImports();
const namedReactImports = components.getNamedReactImports();
const defaultReactImportName = defaultReactImports
&& defaultReactImports[0]
&& defaultReactImports[0].local.name;
const reactHookImportSpecifiers = namedReactImports
&& namedReactImports.filter((specifier) => USE_HOOK_PREFIX_REGEX.test(specifier.imported.name));
const reactHookImportNames = reactHookImportSpecifiers
&& fromEntries(reactHookImportSpecifiers.map((specifier) => [specifier.local.name, specifier.imported.name]));
const isPotentialReactHookCall = defaultReactImportName
&& node.callee.type === 'MemberExpression'
&& node.callee.object.type === 'Identifier'
&& node.callee.object.name === defaultReactImportName
&& node.callee.property.type === 'Identifier'
&& node.callee.property.name.match(USE_HOOK_PREFIX_REGEX);
const isPotentialHookCall = reactHookImportNames
&& node.callee.type === 'Identifier'
&& node.callee.name.match(USE_HOOK_PREFIX_REGEX);
const scope = (isPotentialReactHookCall || isPotentialHookCall) && getScope(context, node);
const reactResolvedDefs = isPotentialReactHookCall
&& scope.references
&& scope.references.find(
(reference) => reference.identifier.name === defaultReactImportName
).resolved.defs;
const isReactShadowed = isPotentialReactHookCall && reactResolvedDefs
&& reactResolvedDefs.some((reactDef) => reactDef.type !== 'ImportBinding');
const potentialHookReference = isPotentialHookCall
&& scope.references
&& scope.references.find(
(reference) => reactHookImportNames[reference.identifier.name]
);
const hookResolvedDefs = potentialHookReference && potentialHookReference.resolved.defs;
const localHookName = (
isPotentialReactHookCall
&& node.callee.property.name
) || (
isPotentialHookCall
&& potentialHookReference
&& node.callee.name
);
const isHookShadowed = isPotentialHookCall
&& hookResolvedDefs
&& hookResolvedDefs.some(
(hookDef) => hookDef.name.name === localHookName
&& hookDef.type !== 'ImportBinding'
);
const isHookCall = (isPotentialReactHookCall && !isReactShadowed)
|| (isPotentialHookCall && localHookName && !isHookShadowed);
if (!isHookCall) {
return false;
}
if (!expectedHookNames) {
return true;
}
return arrayIncludes(
expectedHookNames,
(reactHookImportNames && reactHookImportNames[localHookName]) || localHookName
);
}, | Identify whether a node (CallExpression) is a call to a React hook
@param {ASTNode} node The AST node being searched. (expects CallExpression)
@param {('useCallback'|'useContext'|'useDebugValue'|'useEffect'|'useImperativeHandle'|'useLayoutEffect'|'useMemo'|'useReducer'|'useRef'|'useState')[]} [expectedHookNames] React hook names to which search is limited.
@returns {boolean} True if the node is a call to a React hook | isReactHookCall ( node , expectedHookNames ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/Components.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/Components.js | MIT |
module.exports = function isFirstLetterCapitalized(word) {
if (!word) {
return false;
}
const firstLetter = word.replace(/^_+/, '').charAt(0);
return firstLetter.toUpperCase() === firstLetter;
}; | Check if the first letter of a string is capitalized.
@param {string} word String to check
@returns {boolean} True if first letter is capitalized. | isFirstLetterCapitalized ( word ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/isFirstLetterCapitalized.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/isFirstLetterCapitalized.js | MIT |
module.exports = function isCreateContext(node) {
if (
node.init
&& node.init.callee
) {
if (
astUtil.isCallExpression(node.init)
&& node.init.callee.name === 'createContext'
) {
return true;
}
if (
node.init.callee.type === 'MemberExpression'
&& node.init.callee.property
&& node.init.callee.property.name === 'createContext'
) {
return true;
}
}
if (
node.expression
&& node.expression.type === 'AssignmentExpression'
&& node.expression.operator === '='
&& astUtil.isCallExpression(node.expression.right)
&& node.expression.right.callee
) {
const right = node.expression.right;
if (right.callee.name === 'createContext') {
return true;
}
if (
right.callee.type === 'MemberExpression'
&& right.callee.property
&& right.callee.property.name === 'createContext'
) {
return true;
}
}
return false;
}; | Checks if the node is a React.createContext call
@param {ASTNode} node - The AST node being checked.
@returns {boolean} - True if node is a React.createContext call, false if not. | isCreateContext ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/isCreateContext.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/isCreateContext.js | MIT |
function isAnnotatedFunctionPropsDeclaration(node, context) {
if (!node || !node.params || !node.params.length) {
return false;
}
const typeNode = node.params[0].type === 'AssignmentPattern' ? node.params[0].left : node.params[0];
const tokens = getFirstTokens(context, typeNode, 2);
const isAnnotated = typeNode.typeAnnotation;
const isDestructuredProps = typeNode.type === 'ObjectPattern';
const isProps = tokens[0].value === 'props' || (tokens[1] && tokens[1].value === 'props');
return (isAnnotated && (isDestructuredProps || isProps));
} | Checks if we are declaring a `props` argument with a flow type annotation.
@param {ASTNode} node The AST node being checked.
@param {Object} context
@returns {boolean} True if the node is a type annotated props declaration, false if not. | isAnnotatedFunctionPropsDeclaration ( node , context ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/annotations.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/annotations.js | MIT |
function memoize(fn) {
const cache = new WeakMap();
// @ts-ignore
return function memoizedFn(arg) {
const cachedValue = cache.get(arg);
if (cachedValue !== undefined) {
return cachedValue;
}
const v = fn(arg);
cache.set(arg, v);
return v;
};
} | @template {(_: object) => any} T
@param {T} fn
@returns {T} | memoize ( fn ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/componentUtil.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/componentUtil.js | MIT |
function isES5Component(node, context) {
const pragma = getPragma(context);
const createClass = getCreateClass(context);
if (!node.parent || !node.parent.callee) {
return false;
}
const callee = node.parent.callee;
// React.createClass({})
if (callee.type === 'MemberExpression') {
return callee.object.name === pragma && callee.property.name === createClass;
}
// createClass({})
if (callee.type === 'Identifier') {
return callee.name === createClass;
}
return false;
} | @param {ASTNode} node
@param {Context} context
@returns {boolean} | isES5Component ( node , context ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/componentUtil.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/componentUtil.js | MIT |
function isExplicitComponent(node, context) {
const sourceCode = getSourceCode(context);
let comment;
// Sometimes the passed node may not have been parsed yet by eslint, and this function call crashes.
// Can be removed when eslint sets "parent" property for all nodes on initial AST traversal: https://github.com/eslint/eslint-scope/issues/27
// eslint-disable-next-line no-warning-comments
// FIXME: Remove try/catch when https://github.com/eslint/eslint-scope/issues/27 is implemented.
try {
comment = sourceCode.getJSDocComment(node);
} catch (e) {
comment = null;
}
if (comment === null) {
return false;
}
let commentAst;
try {
commentAst = doctrine.parse(comment.value, {
unwrap: true,
tags: ['extends', 'augments'],
});
} catch (e) {
// handle a bug in the archived `doctrine`, see #2596
return false;
}
const relevantTags = commentAst.tags.filter((tag) => tag.name === 'React.Component' || tag.name === 'React.PureComponent');
return relevantTags.length > 0;
} | Check if the node is explicitly declared as a descendant of a React Component
@param {any} node
@param {Context} context
@returns {boolean} | isExplicitComponent ( node , context ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/componentUtil.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/componentUtil.js | MIT |
function getParentES5Component(context, node) {
let scope = getScope(context, node);
while (scope) {
// @ts-ignore
node = scope.block && scope.block.parent && scope.block.parent.parent;
if (node && isES5Component(node, context)) {
return node;
}
scope = scope.upper;
}
return null;
} | Get the parent ES5 component node from the current scope
@param {Context} context
@param {ASTNode} node
@returns {ASTNode|null} | getParentES5Component ( context , node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/componentUtil.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/componentUtil.js | MIT |
function getParentES6Component(context, node) {
let scope = getScope(context, node);
while (scope && scope.type !== 'class') {
scope = scope.upper;
}
node = scope && scope.block;
if (!node || !isES6Component(node, context)) {
return null;
}
return node;
} | Get the parent ES6 component node from the current scope
@param {Context} context
@param {ASTNode} node
@returns {ASTNode | null} | getParentES6Component ( context , node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/componentUtil.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/componentUtil.js | MIT |
function isPureComponent(node, context) {
const pragma = getPragma(context);
if (node.superClass) {
return new RegExp(`^(${pragma}\\.)?PureComponent$`).test(getText(context, node.superClass));
}
return false;
} | Checks if a component extends React.PureComponent
@param {ASTNode} node
@param {Context} context
@returns {boolean} | isPureComponent ( node , context ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/componentUtil.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/componentUtil.js | MIT |
function traverse(ASTnode, visitor) {
const opts = Object.assign({}, {
fallback(node) {
return Object.keys(node).filter((key) => key === 'children' || key === 'argument');
},
}, visitor);
opts.keys = Object.assign({}, visitor.keys, {
JSXElement: ['children'],
JSXFragment: ['children'],
});
estraverse.traverse(ASTnode, opts);
} | Wrapper for estraverse.traverse
@param {ASTNode} ASTnode The AST node being checked
@param {Object} visitor Visitor Object for estraverse | traverse ( ASTnode , visitor ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/ast.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/ast.js | MIT |
function findReturnStatement(node) {
if (
(!node.value || !node.value.body || !node.value.body.body)
&& (!node.body || !node.body.body)
) {
return false;
}
const bodyNodes = node.value ? node.value.body.body : node.body.body;
return loopNodes(bodyNodes);
} | Find a return statement in the current node
@param {ASTNode} node The AST node being checked
@returns {ASTNode | false} | findReturnStatement ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/ast.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/ast.js | MIT |
function getPropertyNameNode(node) {
if (
node.key
|| node.type === 'MethodDefinition'
|| node.type === 'Property'
) {
return node.key;
}
if (node.type === 'MemberExpression') {
return node.property;
}
return null;
} | Get node with property's name
@param {Object} node - Property.
@returns {Object} Property name node. | getPropertyNameNode ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/ast.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/ast.js | MIT |
function getPropertyName(node) {
const nameNode = getPropertyNameNode(node);
return nameNode ? nameNode.name : '';
} | Get properties name
@param {Object} node - Property.
@returns {string} Property name. | getPropertyName ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/ast.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/ast.js | MIT |
function getComponentProperties(node) {
switch (node.type) {
case 'ClassDeclaration':
case 'ClassExpression':
return node.body.body;
case 'ObjectExpression':
return node.properties;
default:
return [];
}
} | Get properties for a given AST node
@param {ASTNode} node The AST node being checked.
@returns {Array} Properties array. | getComponentProperties ( node ) | javascript | jsx-eslint/eslint-plugin-react | lib/util/ast.js | https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/util/ast.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.