Skip to content

Commit e65a4a4

Browse files
authored
utilities (#1286)
1 parent 21d3282 commit e65a4a4

File tree

145 files changed

+967
-757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+967
-757
lines changed

package-lock.json

+56-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/utilities/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
package-lock.json
3+
yarn.lock
4+
*.result.css
5+
*.result.css.map
6+
*.result.html

packages/utilities/.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.2.0

packages/utilities/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changes to Utilities
2+
3+
### Unreleased (major)
4+
5+
- Initial version

packages/utilities/LICENSE.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
MIT No Attribution (MIT-0)
2+
3+
Copyright © CSSTools Contributors
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
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so.
11+
12+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18+
SOFTWARE.

packages/utilities/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Utilities
2+
3+
[<img alt="npm version" src="https://img.shields.io/npm/v/@csstools/utilities.svg" height="20">][npm-url]
4+
[<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url]
5+
[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
6+
7+
Helpers that we use in many PostCSS plugins.
8+
9+
## API
10+
11+
[Read the API docs](./docs/utilities.md)
12+
13+
## Usage
14+
15+
Add [Utilities] to your project:
16+
17+
```bash
18+
npm install @csstools/utilities --save-dev
19+
```
20+
21+
[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
22+
[discord]: https://discord.gg/bUadyRwkJS
23+
[npm-url]: https://www.npmjs.com/package/@csstools/utilities
24+
25+
[Utilities]: https://github.com/csstools/postcss-plugins/tree/main/packages/utilities

packages/utilities/api-extractor.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"extends": "../../api-extractor.json",
4+
"docModel": {
5+
"enabled": true
6+
}
7+
}

packages/utilities/dist/index.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";exports.hasFallback=function hasFallback(t){const e=t.parent;if(!e)return!1;const r=t.prop.toLowerCase(),s=e.index(t);for(let t=0;t<s;t++){const s=e.nodes[t];if("decl"===s.type&&s.prop.toLowerCase()===r)return!0}return!1},exports.hasSupportsAtRuleAncestor=function hasSupportsAtRuleAncestor(t,e){let r=t.parent;for(;r;)if("atrule"===r.type&&"supports"===r.name.toLowerCase()){if(e.test(r.params))return!0;r=r.parent}else r=r.parent;return!1};

packages/utilities/dist/index.d.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Declaration } from 'postcss';
2+
import type { Node } from 'postcss';
3+
4+
/**
5+
* Check if a declaration has a fallback.
6+
* Returns true if a declaration with the same property name appears before the current declaration.
7+
*
8+
* @param {Declaration} node The declaration node to check
9+
* @returns {boolean} Whether the declaration has a fallback
10+
*/
11+
export declare function hasFallback(node: Declaration): boolean;
12+
13+
/**
14+
* Check if a node has a `@supports` at-rule ancestor with a given regex in its params.
15+
*
16+
* @param {Node} node The node to check
17+
* @param {{ test(str: string): boolean }} predicate The test to match against the `@supports` at-rule's params
18+
* @returns {boolean}
19+
*/
20+
export declare function hasSupportsAtRuleAncestor(node: Node, predicate: {
21+
test(str: string): boolean;
22+
}): boolean;
23+
24+
export { }

packages/utilities/dist/index.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function hasFallback(e){const t=e.parent;if(!t)return!1;const r=e.prop.toLowerCase(),o=t.index(e);for(let e=0;e<o;e++){const o=t.nodes[e];if("decl"===o.type&&o.prop.toLowerCase()===r)return!0}return!1}function hasSupportsAtRuleAncestor(e,t){let r=e.parent;for(;r;)if("atrule"===r.type&&"supports"===r.name.toLowerCase()){if(t.test(r.params))return!0;r=r.parent}else r=r.parent;return!1}export{hasFallback,hasSupportsAtRuleAncestor};

packages/utilities/docs/index.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md)
4+
5+
## API Reference
6+
7+
## Packages
8+
9+
| Package | Description |
10+
| --- | --- |
11+
| [@csstools/utilities](./utilities.md) | |
12+

0 commit comments

Comments
 (0)