UNPKG

2.57 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4var attributes = 'accept acceptCharset accessKey action allowFullScreen allowTransparency\nalt async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge\ncharSet checked classID className colSpan cols content contentEditable contextMenu\ncontrols coords crossOrigin data dateTime default defer dir disabled download draggable\nencType form formAction formEncType formMethod formNoValidate formTarget frameBorder\nheaders height hidden high href hrefLang htmlFor httpEquiv icon id inputMode integrity\nis keyParams keyType kind label lang list loop low manifest marginHeight marginWidth max maxLength media\nmediaGroup method min minLength multiple muted name noValidate nonce open\noptimum pattern placeholder poster preload radioGroup readOnly rel required\nreversed role rowSpan rows sandbox scope scoped scrolling seamless selected\nshape size sizes span spellCheck src srcDoc srcLang srcSet start step style\nsummary tabIndex target title type useMap value width wmode wrap'.replace(/\s+/g, ' ').replace(/\t|\n|\r/g, '').split(' ');
5
6var eventsName = 'onCopy onCut onPaste onCompositionEnd onCompositionStart onCompositionUpdate onKeyDown\n onKeyPress onKeyUp onFocus onBlur onChange onInput onSubmit onClick onContextMenu onDoubleClick\n onDrag onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop onMouseDown\n onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onSelect onTouchCancel\n onTouchEnd onTouchMove onTouchStart onScroll onWheel onAbort onCanPlay onCanPlayThrough\n onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata\n onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError'.replace(/\s+/g, ' ').replace(/\t|\n|\r/g, '').split(' ');
7
8var attrsPrefix = ['data-', 'aria-'];
9/**
10 * 过滤掉无效的透传到 DOM 属性
11 */
12
13exports.default = function (props) {
14 var attrs = {};
15
16 var _loop = function _loop(key) {
17 if (attributes.indexOf(key) > -1 || eventsName.indexOf(key) > -1) {
18 attrs[key] = props[key];
19 } else if (attrsPrefix.map(function (prefix) {
20 return new RegExp('^' + prefix);
21 }).some(function (reg) {
22 return key.replace(reg, '') !== key;
23 })) {
24 attrs[key] = props[key];
25 }
26 };
27
28 for (var key in props) {
29 _loop(key);
30 }
31 return attrs;
32};
33
34module.exports = exports['default'];
\No newline at end of file