postcss-normalize-charset 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
- # 1.1.0
2
-
3
- * Added `add` option (thanks to @ben-eb)
4
-
5
- # 1.0.0
6
-
7
- * Initial release.
1
+ # 1.1.1
2
+
3
+ * Performance tweaks; test that `node.parent` is equal to the AST rather than
4
+ checking its type is `root`, and use the AST directly to prepend the
5
+ `@charset` to, rather than using the superfluous `root()` method.
6
+
7
+ # 1.1.0
8
+
9
+ * Added `add` option (thanks to @ben-eb)
10
+
11
+ # 1.0.0
12
+
13
+ * Initial release.
package/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- The MIT License (MIT)
2
-
3
- Copyright 2015 Bogdan Chadkin <trysound@yandex.ru>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2015 Bogdan Chadkin <trysound@yandex.ru>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,44 +1,44 @@
1
- # postcss-normalize-charset [![Build Status][ci-img]][ci]
2
-
3
- Add necessary or remove extra charset with PostCSS
4
-
5
- ```css
6
- a{
7
- content: "©";
8
- }
9
- ```
10
-
11
- ```css
12
- @charset "utf-8";
13
- a{
14
- content: "©";
15
- }
16
- ```
17
-
18
- ## API
19
-
20
- ### normalizeCharset([options])
21
-
22
- #### options
23
-
24
- ##### add
25
-
26
- Type: `boolean`
27
- Default: `true`
28
-
29
- Pass `false` to stop the module from adding a `@charset` declaration if it was
30
- missing from the file (and the file contained non-ascii characters).
31
-
32
- ## Usage
33
-
34
- ```js
35
- postcss([ require('postcss-normalize-charset') ])
36
- ```
37
-
38
- See [PostCSS] docs for examples for your environment.
39
-
40
- MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)
41
-
42
- [PostCSS]: https://github.com/postcss/postcss
43
- [ci-img]: https://travis-ci.org/TrySound/postcss-normalize-charset.svg
44
- [ci]: https://travis-ci.org/TrySound/postcss-normalize-charset
1
+ # postcss-normalize-charset [![Build Status][ci-img]][ci]
2
+
3
+ Add necessary or remove extra charset with PostCSS
4
+
5
+ ```css
6
+ a{
7
+ content: "©";
8
+ }
9
+ ```
10
+
11
+ ```css
12
+ @charset "utf-8";
13
+ a{
14
+ content: "©";
15
+ }
16
+ ```
17
+
18
+ ## API
19
+
20
+ ### normalizeCharset([options])
21
+
22
+ #### options
23
+
24
+ ##### add
25
+
26
+ Type: `boolean`
27
+ Default: `true`
28
+
29
+ Pass `false` to stop the module from adding a `@charset` declaration if it was
30
+ missing from the file (and the file contained non-ascii characters).
31
+
32
+ ## Usage
33
+
34
+ ```js
35
+ postcss([ require('postcss-normalize-charset') ])
36
+ ```
37
+
38
+ See [PostCSS] docs for examples for your environment.
39
+
40
+ MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)
41
+
42
+ [PostCSS]: https://github.com/postcss/postcss
43
+ [ci-img]: https://travis-ci.org/ben-eb/postcss-normalize-charset.svg
44
+ [ci]: https://travis-ci.org/ben-eb/postcss-normalize-charset
package/index.js CHANGED
@@ -1,35 +1,37 @@
1
- var postcss = require('postcss');
2
-
3
- module.exports = postcss.plugin('postcss-normalize-charset', function (opts) {
4
- opts = opts || {};
5
-
6
- return function (css) {
7
- var charsetRule;
8
- var nonAsciiNode;
9
- var nonAscii = /[^\x00-\x7F]/;
10
-
11
- css.walk(function (node) {
12
- if (node.type === 'atrule' && node.name === 'charset') {
13
- if (!charsetRule) {
14
- charsetRule = node;
15
- }
16
- node.remove();
17
- } else if (!nonAsciiNode && node.parent && node.parent.type === 'root' && nonAscii.test(node)) {
18
- nonAsciiNode = node;
19
- }
20
- });
21
-
22
- if (nonAsciiNode) {
23
- if (!charsetRule && opts.add !== false) {
24
- charsetRule = postcss.atRule({
25
- name: 'charset',
26
- params: '"utf-8"'
27
- });
28
- }
29
- if (charsetRule) {
30
- charsetRule.source = nonAsciiNode.source;
31
- css.root().prepend(charsetRule);
32
- }
33
- }
34
- };
35
- });
1
+ var postcss = require('postcss');
2
+
3
+ var charset = 'charset';
4
+
5
+ module.exports = postcss.plugin('postcss-normalize-' + charset, function (opts) {
6
+ opts = opts || {};
7
+
8
+ return function (css) {
9
+ var charsetRule;
10
+ var nonAsciiNode;
11
+ var nonAscii = /[^\x00-\x7F]/;
12
+
13
+ css.walk(function (node) {
14
+ if (node.type === 'atrule' && node.name === charset) {
15
+ if (!charsetRule) {
16
+ charsetRule = node;
17
+ }
18
+ node.remove();
19
+ } else if (!nonAsciiNode && node.parent === css && nonAscii.test(node)) {
20
+ nonAsciiNode = node;
21
+ }
22
+ });
23
+
24
+ if (nonAsciiNode) {
25
+ if (!charsetRule && opts.add !== false) {
26
+ charsetRule = postcss.atRule({
27
+ name: charset,
28
+ params: '"utf-8"'
29
+ });
30
+ }
31
+ if (charsetRule) {
32
+ charsetRule.source = nonAsciiNode.source;
33
+ css.prepend(charsetRule);
34
+ }
35
+ }
36
+ };
37
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-normalize-charset",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Add necessary or remove extra charset with PostCSS",
5
5
  "keywords": [
6
6
  "postcss",
@@ -13,20 +13,20 @@
13
13
  "index.js"
14
14
  ],
15
15
  "license": "MIT",
16
- "repository": "TrySound/postcss-charset",
16
+ "repository": "ben-eb/postcss-charset",
17
17
  "bugs": {
18
- "url": "https://github.com/TrySound/postcss-charset/issues"
18
+ "url": "https://github.com/ben-eb/postcss-charset/issues"
19
19
  },
20
- "homepage": "https://github.com/TrySound/postcss-charset",
20
+ "homepage": "https://github.com/ben-eb/postcss-charset",
21
21
  "dependencies": {
22
22
  "postcss": "^5.0.5"
23
23
  },
24
24
  "devDependencies": {
25
+ "ava": "^0.16.0",
25
26
  "eslint": "^1.4.1",
26
- "tap-spec": "^4.1.0",
27
- "tape": "^4.2.0"
27
+ "postcss-devtools": "^1.1.1"
28
28
  },
29
29
  "scripts": {
30
- "test": "eslint index.js test && tape test/*.js | tap-spec"
30
+ "test": "eslint index.js test && ava"
31
31
  }
32
32
  }