Skip to content
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

Export regexes as the rules to reuse by other tools #35

Closed
khanguy00 opened this issue May 14, 2021 · 4 comments
Closed

Export regexes as the rules to reuse by other tools #35

khanguy00 opened this issue May 14, 2021 · 4 comments

Comments

@khanguy00
Copy link

Hi, me again.

Can we expose these regexes?

const matchImports = /^(.+?|\([\s\S]+?\))\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/;
const matchValueDefinition = /(?:\s+|^)([\w-]+)(:?\s+)(.+?)(\s*)$/g;
const matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/;
const matchPath = /"[^"]*"|'[^']*'/;

I think it will be helpful if other tools could reuse those patterns of @value for their purpose (for example validating postcss rules, or preprocess the file before this values-replace plugin).

@princed
Copy link
Owner

princed commented May 14, 2021

Hi Kha! What are actually trying to do? 😄

@khanguy00
Copy link
Author

Well, you may know that in my project (and you still remember what is that project, right?), we have a stylelint plugin to block people from using some CSS properties and transform properties. To do that, I have to parse the CSS in a specific way, which then along with #33 will boost the processing speed further. Which mean that I should reuse the regexes.

Currently, I just copy them into my internal plugin, but I wonder if you could expose those regexes from your plugin?

@princed
Copy link
Owner

princed commented May 14, 2021

Oh I see. To be honest I'm not sure if exposing such implementation details is a good idea as I wouldn't like to provide any compatibility guarantees for them. Also I should say I copied most of them myself from https://github.com/css-modules/postcss-modules-values/blob/master/src/index.js#L5-L7

To sum up I think it'd be better to copy them over just as you did already. If it helps in any way, this plugin also provides a list of extracted values via postcss messages — https://github.com/princed/postcss-modules-values-replace#extracting-values-for-programmatic-use.

@khanguy00
Copy link
Author

Fair point. Then I just keep the copied one. Thanks anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants