Skip to content

Commit d19d514

Browse files
Merge pull request #1 from shreyas-jadhav/main
Add TypeScript support
2 parents e604cdf + 798fedc commit d19d514

15 files changed

+3284
-143
lines changed

.eslintrc.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"prettier"
11+
],
12+
"overrides": [
13+
],
14+
"parser": "@typescript-eslint/parser",
15+
"parserOptions": {
16+
"ecmaVersion": "latest",
17+
"sourceType": "module"
18+
},
19+
"plugins": [
20+
"@typescript-eslint",
21+
"prettier"
22+
],
23+
"rules": {
24+
"prettier/prettier": 1,
25+
"@typescript-eslint/no-explicit-any": "off"
26+
}
27+
}

.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"arrowParens": "always",
5+
"bracketSameLine": false,
6+
"printWidth": 120,
7+
"tabWidth": 2,
8+
"semi": true
9+
}

dist/cjs/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

dist/cjs/index.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
const plugin_1 = __importDefault(require("tailwindcss/plugin"));
7+
module.exports = plugin_1.default.withOptions(function (options = {}) {
8+
return function ({ matchUtilities, theme, config }) {
9+
const context = {
10+
theme,
11+
config,
12+
...(options !== null && options !== void 0 ? options : {}),
13+
};
14+
matchUtilities({
15+
js: (value) => {
16+
const escape = (str) => {
17+
console.log(`escaping \`${str}\``);
18+
return str.replace(/_/g, '\\_').replace(/ /g, '_');
19+
};
20+
const unescape = (str) => {
21+
console.log(`unescaping \`${str}\``);
22+
str = str.replace(/(?<!\\)_/g, ' ');
23+
str = str.replace(/\\_/g, '_');
24+
return str;
25+
};
26+
const parseString = (str) => {
27+
console.log(`parsing \`${str}\``);
28+
return str.split(/(#{.*?})/g).map((el, i) => (i % 2 === 1 ? el.slice(2, -1) : el));
29+
};
30+
const parts = parseString(escape(value));
31+
const utility = parts
32+
.map((part, i) => {
33+
if (i % 2 === 0) {
34+
return part;
35+
}
36+
else {
37+
const args = Object.keys(context);
38+
const values = Object.values(context);
39+
const func = new Function(...args, `return ${unescape(part)};`);
40+
return escape(`${func(...values)}`);
41+
}
42+
})
43+
.join('');
44+
return {
45+
[`@apply ${utility}`]: {},
46+
};
47+
},
48+
});
49+
};
50+
});

dist/esm/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

dist/esm/index.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import plugin from 'tailwindcss/plugin';
2+
module.exports = plugin.withOptions(function (options = {}) {
3+
return function ({ matchUtilities, theme, config }) {
4+
const context = {
5+
theme,
6+
config,
7+
...(options !== null && options !== void 0 ? options : {}),
8+
};
9+
matchUtilities({
10+
js: (value) => {
11+
const escape = (str) => {
12+
console.log(`escaping \`${str}\``);
13+
return str.replace(/_/g, '\\_').replace(/ /g, '_');
14+
};
15+
const unescape = (str) => {
16+
console.log(`unescaping \`${str}\``);
17+
str = str.replace(/(?<!\\)_/g, ' ');
18+
str = str.replace(/\\_/g, '_');
19+
return str;
20+
};
21+
const parseString = (str) => {
22+
console.log(`parsing \`${str}\``);
23+
return str.split(/(#{.*?})/g).map((el, i) => (i % 2 === 1 ? el.slice(2, -1) : el));
24+
};
25+
const parts = parseString(escape(value));
26+
const utility = parts
27+
.map((part, i) => {
28+
if (i % 2 === 0) {
29+
return part;
30+
}
31+
else {
32+
const args = Object.keys(context);
33+
const values = Object.values(context);
34+
const func = new Function(...args, `return ${unescape(part)};`);
35+
return escape(`${func(...values)}`);
36+
}
37+
})
38+
.join('');
39+
return {
40+
[`@apply ${utility}`]: {},
41+
};
42+
},
43+
});
44+
};
45+
});

dist/types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

index.js

-50
This file was deleted.

index.ts

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import plugin from 'tailwindcss/plugin';
2+
3+
type Options = Record<string, any>;
4+
5+
module.exports = plugin.withOptions(function (options: Options = {}) {
6+
return function ({ matchUtilities, theme, config }) {
7+
const context = {
8+
theme,
9+
config,
10+
...(options ?? {}),
11+
};
12+
matchUtilities({
13+
js: (value) => {
14+
const escape = (str: string) => {
15+
console.log(`escaping \`${str}\``);
16+
return str.replace(/_/g, '\\_').replace(/ /g, '_');
17+
};
18+
19+
const unescape = (str: string) => {
20+
console.log(`unescaping \`${str}\``);
21+
str = str.replace(/(?<!\\)_/g, ' ');
22+
str = str.replace(/\\_/g, '_');
23+
return str;
24+
};
25+
26+
const parseString = (str: string) => {
27+
console.log(`parsing \`${str}\``);
28+
return str.split(/(#{.*?})/g).map((el, i) => (i % 2 === 1 ? el.slice(2, -1) : el));
29+
};
30+
31+
const parts = parseString(escape(value));
32+
33+
const utility = parts
34+
.map((part, i) => {
35+
if (i % 2 === 0) {
36+
return part;
37+
} else {
38+
const args = Object.keys(context);
39+
const values = Object.values(context);
40+
const func = new Function(...args, `return ${unescape(part)};`);
41+
return escape(`${func(...values)}`);
42+
}
43+
})
44+
.join('');
45+
46+
return {
47+
[`@apply ${utility}`]: {},
48+
};
49+
},
50+
});
51+
};
52+
});

0 commit comments

Comments
 (0)