Skip to content

utilities #1286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 56 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/utilities/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
package-lock.json
yarn.lock
*.result.css
*.result.css.map
*.result.html
1 change: 1 addition & 0 deletions packages/utilities/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.2.0
5 changes: 5 additions & 0 deletions packages/utilities/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changes to Utilities

### Unreleased (major)

- Initial version
18 changes: 18 additions & 0 deletions packages/utilities/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
MIT No Attribution (MIT-0)

Copyright © CSSTools Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions packages/utilities/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Utilities

[<img alt="npm version" src="https://img.shields.io/npm/v/@csstools/utilities.svg" height="20">][npm-url]
[<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url]
[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]

Helpers that we use in many PostCSS plugins.

## API

[Read the API docs](./docs/utilities.md)

## Usage

Add [Utilities] to your project:

```bash
npm install @csstools/utilities --save-dev
```

[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
[discord]: https://discord.gg/bUadyRwkJS
[npm-url]: https://www.npmjs.com/package/@csstools/utilities

[Utilities]: https://github.com/csstools/postcss-plugins/tree/main/packages/utilities
7 changes: 7 additions & 0 deletions packages/utilities/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "../../api-extractor.json",
"docModel": {
"enabled": true
}
}
1 change: 1 addition & 0 deletions packages/utilities/dist/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +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};
24 changes: 24 additions & 0 deletions packages/utilities/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Declaration } from 'postcss';
import type { Node } from 'postcss';

/**
* Check if a declaration has a fallback.
* Returns true if a declaration with the same property name appears before the current declaration.
*
* @param {Declaration} node The declaration node to check
* @returns {boolean} Whether the declaration has a fallback
*/
export declare function hasFallback(node: Declaration): boolean;

/**
* Check if a node has a `@supports` at-rule ancestor with a given regex in its params.
*
* @param {Node} node The node to check
* @param {{ test(str: string): boolean }} predicate The test to match against the `@supports` at-rule's params
* @returns {boolean}
*/
export declare function hasSupportsAtRuleAncestor(node: Node, predicate: {
test(str: string): boolean;
}): boolean;

export { }
1 change: 1 addition & 0 deletions packages/utilities/dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +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};
12 changes: 12 additions & 0 deletions packages/utilities/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md)

## API Reference

## Packages

| Package | Description |
| --- | --- |
| [@csstools/utilities](./utilities.md) | |

Loading