Socket
Socket
Sign inDemoInstall

@asyarb/twix

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asyarb/twix - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

dist/index.cjs

79

dist/index.d.ts

@@ -1,56 +0,27 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const clsx = require('clsx');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
const clsx__default = /*#__PURE__*/_interopDefaultLegacy(clsx);
function resolveVariants(defaultVariants, activeVariants) {
const result = { ...defaultVariants };
for (const key in activeVariants) {
const value = activeVariants[key];
if (value === void 0)
continue;
result[key] = value;
}
return result;
type Variant = Record<string, string>;
type DefaultVariants<TVariants extends Record<string, Variant>> = {
[K in keyof TVariants]?: ResolvedVariantKeys<TVariants[K]>;
};
type ResolvedVariantKeys<TVariant extends Variant> = Extract<keyof TVariant, 'true'> extends never ? keyof TVariant : Exclude<keyof TVariant, 'true'> | true | false;
type ActiveVariants<TVariants extends Record<string, Variant>, TDefaultVariants extends DefaultVariants<TVariants>> = {
[K in keyof Omit<TVariants, keyof TDefaultVariants>]: ResolvedVariantKeys<TVariants[K]>;
} & {
[K in keyof TVariants]?: ResolvedVariantKeys<TVariants[K]>;
} & {
class?: string;
};
type CompoundVariant<TVariants extends Record<string, Variant>> = {
[K in keyof TVariants]?: ResolvedVariantKeys<TVariants[K]>;
} & {
class: string;
};
interface TwvxOptions<TVariants extends Record<string, Variant>, TDefaultVariants extends DefaultVariants<TVariants>> {
base: string;
variants: TVariants;
defaultVariants: TDefaultVariants;
compoundVariants?: Array<CompoundVariant<TVariants>>;
}
function twix({
base,
variants,
defaultVariants,
compoundVariants = []
}) {
return ({
class: _class,
...activeVariants
}) => {
const resolvedVariants = resolveVariants(defaultVariants, activeVariants);
const classes = [];
for (const key in resolvedVariants) {
const value = resolvedVariants[key];
if (!value)
continue;
classes.push(variants[key][value]);
}
for (const compoundV of compoundVariants) {
let shouldIncludeCompoundVariant = true;
for (const [key, value] of Object.entries(compoundV)) {
if (key === "class")
continue;
if (resolvedVariants[key] !== value) {
shouldIncludeCompoundVariant = false;
}
}
if (shouldIncludeCompoundVariant) {
classes.push(compoundV.class);
}
}
return clsx__default["default"](classes, base, _class);
};
}
declare function twix<TVariants extends Record<string, Variant>, TDefaultVariants extends DefaultVariants<TVariants>>({ base, variants, defaultVariants, compoundVariants, }: TwvxOptions<TVariants, TDefaultVariants>): ({ class: _class, ...activeVariants }: ActiveVariants<TVariants, TDefaultVariants>) => string;
type GetVariants<TVariantsFn extends (...args: any) => string> = NonNullable<Parameters<TVariantsFn>[0]>;
exports.twix = twix;
export { type GetVariants, twix };

@@ -1,11 +0,3 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const clsx = require('clsx');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
const clsx__default = /*#__PURE__*/_interopDefaultLegacy(clsx);
// src/index.ts
import clsx from "clsx";
function resolveVariants(defaultVariants, activeVariants) {

@@ -31,3 +23,6 @@ const result = { ...defaultVariants };

}) => {
const resolvedVariants = resolveVariants(defaultVariants, activeVariants);
const resolvedVariants = resolveVariants(
defaultVariants,
activeVariants
);
const classes = [];

@@ -38,3 +33,6 @@ for (const key in resolvedVariants) {

continue;
classes.push(variants[key][value]);
const resolvedClass = variants[key]?.[value];
if (!resolvedClass)
continue;
classes.push(resolvedClass);
}

@@ -54,6 +52,8 @@ for (const compoundV of compoundVariants) {

}
return clsx__default["default"](classes, base, _class);
return clsx(classes, base, _class);
};
}
exports.twix = twix;
export {
twix
};
module.exports = module.exports.default
{
"name": "@asyarb/twix",
"version": "0.2.1",
"version": "0.3.0",
"description": "Create variant based className strings.",
"repository": {
"type": "git",
"url": "https://github.com/asyarb/twix.git"
},
"repository": "https://github.com/asyarb/twix",
"author": "Anthony Yarbrough <asyarb@hawaii.edu>",
"license": "MIT",
"author": "Anthony Yarbrough <asyarb@hawaii.edu>",
"sideEffects": false,
"type": "module",
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"exports": {

@@ -18,35 +23,21 @@ ".": {

"require": "./dist/index.js"
},
"./package.json": "./package.json"
}
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"types": "./dist/index.d.ts",
"scripts": {
"build": "siroc build",
"dev": "siroc build --watch",
"dev": "vitest",
"build": "NODE_ENV=production tsup",
"test": "vitest run",
"format": "prettier --write .",
"lint": "eslint --ext .js,.ts .",
"release": "npm run build && npm run test && npm run lint && standard-version",
"test": "uvu -r tsm tests"
"release": "npm run build && npm run test && standard-version"
},
"browserslist": ">2%, not ie 11, not op_mini all",
"devDependencies": {
"@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0",
"@typescript-eslint/eslint-plugin": "^5.3.1",
"@typescript-eslint/parser": "^5.3.1",
"clsx": "^2.0.0",
"eslint": "^8.2.0",
"eslint-plugin-tsdoc": "^0.2.14",
"prettier": "^2.4.1",
"siroc": "^0.16.0",
"clsx": "^2.1.0",
"prettier": "^3.2.5",
"standard-version": "^9.3.2",
"tsm": "^2.1.4",
"typescript": "^4.4.4",
"uvu": "^0.5.2"
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"vite": "^5.2.8",
"vitest": "^1.4.0"
},

@@ -53,0 +44,0 @@ "peerDependencies": {

@@ -20,12 +20,12 @@ # twix 🍫

const button = twix({
base: "rounded",
base: 'rounded',
variants: {
color: {
purple: "bg-purple",
blue: "bg-blue",
purple: 'bg-purple',
blue: 'bg-blue',
},
size: {
small: "p-5",
large: "p-8",
small: 'p-5',
large: 'p-8',
},

@@ -36,5 +36,5 @@ },

{
color: "purple",
size: "small",
class: "font-bold",
color: 'purple',
size: 'small',
class: 'font-bold',
},

@@ -44,3 +44,3 @@ ],

defaultVariants: {
size: "large",
size: 'large',
},

@@ -50,6 +50,6 @@ })

// => "rounded p-8 bg-purple"
button({ color: "purple" })
button({ color: 'purple' })
// => "rounded p-5 bg-purple font-bold"
button({ color: "purple", size: "small" })
button({ color: 'purple', size: 'small' })
```

@@ -63,3 +63,3 @@

```ts
import type { GetVariants } from "@asyarb/twix"
import type { GetVariants } from '@asyarb/twix'

@@ -72,3 +72,3 @@ // ... Same button from above.

// => TypeScript error - Must provide `color` since no defaultVariant exists.
button({ size: "small" })
button({ size: 'small' })

@@ -90,3 +90,3 @@ // => Get variants as a type you can re-use elsewhere:

// => "rounded p-5 bg-purple font-bold arbitrary"
button({ color: "purple", size: "small", class: "arbitrary" })
button({ color: 'purple', size: 'small', class: 'arbitrary' })
```

@@ -99,3 +99,3 @@

import { GetVariants, twix } from "@asyarb/twix"
import { GetVariants, twix } from '@asyarb/twix'

@@ -102,0 +102,0 @@ const button = twix({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc