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

@tokey/css-value-parser

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tokey/css-value-parser - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

10

dist/ast-types.d.ts

@@ -47,8 +47,8 @@ import type { lengthValidUnits, angleValidUnits, frequencyValidUnits, resolutionValidUnits, timeValidUnits } from './units';

export type Ratio = CSSValueAST<`<ratio>`>;
export type Length = Unit<`<length>`, AnyCase<typeof lengthValidUnits[number]>>;
export type Length = Unit<`<length>`, AnyCase<(typeof lengthValidUnits)[number]>>;
export type Flex = Unit<`<flex>`, AnyCase<`fr`>>;
export type Angle = Unit<`<angle>`, AnyCase<typeof angleValidUnits[number]>>;
export type Time = Unit<`<time>`, AnyCase<typeof timeValidUnits[number]>>;
export type Frequency = Unit<`<frequency>`, AnyCase<typeof frequencyValidUnits[number]>>;
export type Resolution = Unit<`<resolution>`, AnyCase<typeof resolutionValidUnits[number]>>;
export type Angle = Unit<`<angle>`, AnyCase<(typeof angleValidUnits)[number]>>;
export type Time = Unit<`<time>`, AnyCase<(typeof timeValidUnits)[number]>>;
export type Frequency = Unit<`<frequency>`, AnyCase<(typeof frequencyValidUnits)[number]>>;
export type Resolution = Unit<`<resolution>`, AnyCase<(typeof resolutionValidUnits)[number]>>;
export type Color = CSSValueAST<`<color>`>;

@@ -55,0 +55,0 @@ export type Image = CSSValueAST<`<image>`>;

import type { Token, Descriptors } from '@tokey/core';
type Delimiters = '(' | ')' | ',' | '/' | '+' | '-' | '*' | '#' | '.';
type Delimiters = '(' | ')' | ',' | '/' | '+' | '-' | '*' | '#' | '.' | '%';
export type CSSValueToken = Token<Descriptors | Delimiters>;

@@ -4,0 +4,0 @@ export declare function tokenizeValue(source: string, options?: {

@@ -20,2 +20,16 @@ "use strict";

getUnclosedComment: core_1.getUnclosedComment,
shouldClose(ch, previousChar) {
if ((0, core_1.isWhitespace)(ch) && (0, core_1.isWhitespace)(previousChar)) {
return false;
}
if (previousChar === '\\') {
return false;
}
const isAllowedChars = /[-_a-zA-Z0-9]/.test(ch);
if (isAllowedChars) {
return false;
}
// match css identifier char don't allow non-ascii chars
return ch.charCodeAt(0) <= 127;
},
offset: options.offset,

@@ -46,3 +60,4 @@ });

char === '#' ||
char === '%' ||
char === '.');
//# sourceMappingURL=tokenizer.js.map

@@ -204,2 +204,3 @@ "use strict";

nextToken.type === `.` ||
nextToken.type === `%` ||
nextToken.type === `text`) {

@@ -312,3 +313,3 @@ const nextValue = numberValue + nextToken.value;

const match = value.match(NumberRegExp);
const numVal = match === null || match === void 0 ? void 0 : match[0];
const numVal = match?.[0];
return !!numVal && numVal === value;

@@ -318,3 +319,3 @@ }

const match = value.match(new RegExp(`^(` + validNumberRegex + `)`, `i`));
const numVal = match === null || match === void 0 ? void 0 : match[0];
const numVal = match?.[0];
return numVal ? [numVal, value.substring(numVal.length)] : false;

@@ -324,5 +325,5 @@ }

const match = value.match(NumberRegExp);
const numVal = match === null || match === void 0 ? void 0 : match[0];
const numVal = match?.[0];
return numVal ? [numVal, value.substring(numVal.length)] : false;
}
//# sourceMappingURL=value-parser.js.map

@@ -16,5 +16,4 @@ "use strict";

function stringifyNode(node) {
var _a;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return ((_a = stringifyByType[node.type]) === null || _a === void 0 ? void 0 : _a.call(stringifyByType, node)) || ``;
return stringifyByType[node.type]?.(node) || ``;
}

@@ -21,0 +20,0 @@ const stringifyByType = {

@@ -79,3 +79,2 @@ "use strict";

const handleToken = (token, { ast }, _source, s) => {
var _a, _b, _c, _d, _e;
if (token.type === '<') {

@@ -184,3 +183,3 @@ let closed = false;

}
(_a = node.multipliers) !== null && _a !== void 0 ? _a : (node.multipliers = {});
node.multipliers ?? (node.multipliers = {});
if (node.multipliers.range) {

@@ -211,3 +210,3 @@ throw new Error('multiple multipliers on same node');

}
(_b = node.multipliers) !== null && _b !== void 0 ? _b : (node.multipliers = {});
node.multipliers ?? (node.multipliers = {});
if (node.multipliers.range) {

@@ -218,3 +217,3 @@ throw new Error('multiple multipliers on same node');

parseNumber(start.value),
parseNumber((_c = end === null || end === void 0 ? void 0 : end.value) !== null && _c !== void 0 ? _c : '∞'),
parseNumber(end?.value ?? '∞'),
];

@@ -227,3 +226,3 @@ }

}
(_d = node.multipliers) !== null && _d !== void 0 ? _d : (node.multipliers = {});
node.multipliers ?? (node.multipliers = {});
if (node.multipliers.range) {

@@ -241,3 +240,3 @@ throw new Error('multiple multipliers on same node');

}
(_e = node.multipliers) !== null && _e !== void 0 ? _e : (node.multipliers = {});
node.multipliers ?? (node.multipliers = {});
node.multipliers.list = true;

@@ -271,3 +270,3 @@ }

// assume the parse process in juxtaposing on each step
return (node === null || node === void 0 ? void 0 : node.type) === 'juxtaposing' ? (0, core_1.last)(node.nodes) : node;
return node?.type === 'juxtaposing' ? (0, core_1.last)(node.nodes) : node;
}

@@ -274,0 +273,0 @@ function applyPrecedence(ast) {

{
"name": "@tokey/css-value-parser",
"description": "value parser for css",
"version": "0.1.2",
"version": "0.1.3",
"main": "dist/index.js",

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

@@ -83,9 +83,9 @@ import type {

// distance
export type Length = Unit<`<length>`, AnyCase<typeof lengthValidUnits[number]>>;
export type Length = Unit<`<length>`, AnyCase<(typeof lengthValidUnits)[number]>>;
// other quantities
export type Flex = Unit<`<flex>`, AnyCase<`fr`>>;
export type Angle = Unit<`<angle>`, AnyCase<typeof angleValidUnits[number]>>;
export type Time = Unit<`<time>`, AnyCase<typeof timeValidUnits[number]>>;
export type Frequency = Unit<`<frequency>`, AnyCase<typeof frequencyValidUnits[number]>>;
export type Resolution = Unit<`<resolution>`, AnyCase<typeof resolutionValidUnits[number]>>;
export type Angle = Unit<`<angle>`, AnyCase<(typeof angleValidUnits)[number]>>;
export type Time = Unit<`<time>`, AnyCase<(typeof timeValidUnits)[number]>>;
export type Frequency = Unit<`<frequency>`, AnyCase<(typeof frequencyValidUnits)[number]>>;
export type Resolution = Unit<`<resolution>`, AnyCase<(typeof resolutionValidUnits)[number]>>;
// other

@@ -92,0 +92,0 @@ export type Color = CSSValueAST<`<color>`>;

@@ -13,3 +13,3 @@ import {

type Delimiters = '(' | ')' | ',' | '/' | '+' | '-' | '*' | '#' | '.';
type Delimiters = '(' | ')' | ',' | '/' | '+' | '-' | '*' | '#' | '.' | '%';

@@ -33,2 +33,16 @@ export type CSSValueToken = Token<Descriptors | Delimiters>;

getUnclosedComment,
shouldClose(ch, previousChar) {
if (isWhitespace(ch) && isWhitespace(previousChar)) {
return false;
}
if (previousChar === '\\') {
return false;
}
const isAllowedChars = /[-_a-zA-Z0-9]/.test(ch);
if (isAllowedChars) {
return false;
}
// match css identifier char don't allow non-ascii chars
return ch.charCodeAt(0) <= 127;
},
offset: options.offset,

@@ -60,2 +74,3 @@ });

char === '#' ||
char === '%' ||
char === '.');

@@ -274,2 +274,3 @@ import {

nextToken.type === `.` ||
nextToken.type === `%` ||
nextToken.type === `text`

@@ -349,19 +350,19 @@ ) {

return units;
}, {} as Record<typeof lengthValidUnits[number], typeof length>),
}, {} as Record<(typeof lengthValidUnits)[number], typeof length>),
...angleValidUnits.reduce((units, unit) => {
units[unit] = angle;
return units;
}, {} as Record<typeof angleValidUnits[number], typeof angle>),
}, {} as Record<(typeof angleValidUnits)[number], typeof angle>),
...timeValidUnits.reduce((units, unit) => {
units[unit] = time;
return units;
}, {} as Record<typeof timeValidUnits[number], typeof time>),
}, {} as Record<(typeof timeValidUnits)[number], typeof time>),
...frequencyValidUnits.reduce((units, unit) => {
units[unit] = frequency;
return units;
}, {} as Record<typeof frequencyValidUnits[number], typeof frequency>),
}, {} as Record<(typeof frequencyValidUnits)[number], typeof frequency>),
...resolutionValidUnits.reduce((units, unit) => {
units[unit] = resolution;
return units;
}, {} as Record<typeof resolutionValidUnits[number], typeof resolution>),
}, {} as Record<(typeof resolutionValidUnits)[number], typeof resolution>),
} as const;

@@ -368,0 +369,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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