tailwind-to-style 1.1.1 → 1.1.3

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.
Files changed (2) hide show
  1. package/index.js +23 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5711,25 +5711,40 @@ const breakpoints = {
5711
5711
  };
5712
5712
 
5713
5713
  function tws(classNames, convertToJson) {
5714
+ if (
5715
+ [
5716
+ !classNames,
5717
+ typeof classNames !== "string",
5718
+ classNames.trim() === "",
5719
+ ].includes(true)
5720
+ ) {
5721
+ return convertToJson ? {} : "";
5722
+ }
5723
+
5714
5724
  const cssString = generateTailwindCssString().replace(/\s\s+/g, " ");
5715
5725
  const cssObject = convertCssToObject(cssString);
5716
5726
 
5717
- const classes = classNames.split(" ");
5727
+ const classes = classNames.match(/[\w-]+(?:\[[^\]]+\])?|\w+/g);
5728
+
5718
5729
  let cssResult = classes.map((className) => {
5719
5730
  if (cssObject[className]) {
5720
5731
  return cssObject[className];
5721
5732
  } else if (className.includes("[")) {
5722
- const customValue = className.match(/\[([^\]]+)\]/)[1];
5723
- const baseKey = className.split("[")[0];
5724
- if (cssObject[`${baseKey}custom`]) {
5725
- return cssObject[`${baseKey}custom`].replace(
5726
- /custom_value/g,
5727
- customValue
5728
- );
5733
+ const match = className.match(/\[([^\]]+)\]/);
5734
+ if (match) {
5735
+ const customValue = match[1];
5736
+ const baseKey = className.split("[")[0];
5737
+ if (cssObject[`${baseKey}custom`]) {
5738
+ return cssObject[`${baseKey}custom`].replace(
5739
+ /custom_value/g,
5740
+ customValue
5741
+ );
5742
+ }
5729
5743
  }
5730
5744
  }
5731
5745
  return "";
5732
5746
  });
5747
+
5733
5748
  cssResult = replaceAndRemoveCSSVariables(cssResult.join(""));
5734
5749
  cssResult = inlineStyleToJson(cssResult);
5735
5750
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-to-style",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Convert tailwind classes to inline style",
5
5
  "main": "index.js",
6
6
  "scripts": {