This repository has been archived by the owner on Aug 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
122 lines (107 loc) · 2.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'use strict';
import defaultOptions from './defaults';
/**
* Creates output profile for given options
*/
export default class Profile {
/**
* @param {EmmetOutputProfile} options
*/
constructor(options) {
/** @type {EmmetOutputProfile} */
this.options = Object.assign({}, defaultOptions, options);
this.quoteChar = this.options.attributeQuotes === 'single' ? '\'' : '"';
}
/**
* Returns value of given option name
* @param {String} name
* @return {*}
*/
get(name) {
return this.options[name];
}
/**
* Quote given string according to profile
* @param {String} str String to quote
* @return {String}
*/
quote(str) {
return `${this.quoteChar}${str != null ? str : ''}${this.quoteChar}`;
}
/**
* Output given tag name according to options
* @param {String} name
* @return {String}
*/
name(name) {
return strcase(name, this.options.tagCase);
}
/**
* Outputs attribute name according to current settings
* @param {String} attr Attribute name
* @return {String}
*/
attribute(attr) {
return strcase(attr, this.options.attributeCase);
}
/**
* Check if given attribute is boolean
* @param {Object} attr
* @return {Boolean}
*/
isBooleanAttribute(attr) {
return attr.options.boolean
|| this.get('booleanAttributes').indexOf((attr.name || '').toLowerCase()) !== -1;
}
/**
* Returns a token for self-closing tag, depending on current options
* @return {String}
*/
selfClose() {
switch (this.options.selfClosingStyle) {
case 'xhtml': return ' /';
case 'xml': return '/';
default: return '';
}
}
/**
* Returns indent for given level
* @param {Number} level Indentation level
* @return {String}
*/
indent(level) {
level = level || 0;
let output = '';
while (level--) {
output += this.options.indent;
}
return output;
}
/**
* Check if given tag name belongs to inline-level element
* @param {Object|String} node Parsed node or tag name
* @return {Boolean}
*/
isInline(node) {
if (typeof node === 'string') {
return this.get('inlineElements').indexOf(node.toLowerCase()) !== -1;
}
// inline node is a node either with inline-level name or text-only node
return node.name != null ? this.isInline(node.name) : node.isTextOnly;
}
/**
* Outputs formatted field for given params
* @param {Number} index Field index
* @param {String} [placeholder] Field placeholder, can be empty
* @return {String}
*/
field(index, placeholder) {
return this.options.field(index, placeholder);
}
};
function strcase(string, type) {
if (type) {
return type === 'upper' ? string.toUpperCase() : string.toLowerCase();
}
return string;
}