Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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.0 to 0.2.1

dist/index.js

79

dist/index.d.ts

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

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>>;
'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;
}
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]>;
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);
};
}
export { GetVariants, twix };
exports.twix = twix;
{
"name": "@asyarb/twix",
"version": "0.2.0",
"version": "0.2.1",
"description": "Create variant based className strings.",

@@ -15,8 +15,9 @@ "repository": {

".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./package.json": "./package.json"
},
"main": "dist/index.cjs",
"main": "dist/index.js",
"module": "dist/index.mjs",

@@ -23,0 +24,0 @@ "types": "dist/index.d.ts",

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