New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@teambit/component-version

Package Overview
Dependencies
Maintainers
16
Versions
210
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teambit/component-version - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

dist/preview-1696907926959.js

4

dist/index.d.ts
import { Version, LATEST_VERSION } from './version';
import versionParser, { isHash, isSnap, isTag } from './version-parser';
import versionParser, { isHash, isSnap, isTag, HASH_SIZE, SHORT_HASH_MINIMUM_SIZE } from './version-parser';
import { InvalidVersion } from './exceptions';
export { Version, LATEST_VERSION, versionParser, isHash, isSnap, isTag, InvalidVersion };
export { Version, LATEST_VERSION, versionParser, isHash, isSnap, isTag, InvalidVersion, HASH_SIZE, SHORT_HASH_MINIMUM_SIZE, };

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidVersion = exports.isTag = exports.isSnap = exports.isHash = exports.versionParser = exports.LATEST_VERSION = exports.Version = void 0;
exports.SHORT_HASH_MINIMUM_SIZE = exports.HASH_SIZE = exports.InvalidVersion = exports.isTag = exports.isSnap = exports.isHash = exports.versionParser = exports.LATEST_VERSION = exports.Version = void 0;
const version_1 = require("./version");

@@ -36,4 +36,6 @@ Object.defineProperty(exports, "Version", { enumerable: true, get: function () { return version_1.Version; } });

Object.defineProperty(exports, "isTag", { enumerable: true, get: function () { return version_parser_1.isTag; } });
Object.defineProperty(exports, "HASH_SIZE", { enumerable: true, get: function () { return version_parser_1.HASH_SIZE; } });
Object.defineProperty(exports, "SHORT_HASH_MINIMUM_SIZE", { enumerable: true, get: function () { return version_parser_1.SHORT_HASH_MINIMUM_SIZE; } });
const exceptions_1 = require("./exceptions");
Object.defineProperty(exports, "InvalidVersion", { enumerable: true, get: function () { return exceptions_1.InvalidVersion; } });
//# sourceMappingURL=index.js.map
import { Version } from './version';
export declare const HASH_SIZE = 40;
/**
* because the directory structure is `XX/YY....`, it needs to have at least three characters.
*/
export declare const SHORT_HASH_MINIMUM_SIZE = 3;
/**
* a snap is a 40 characters hash encoded in HEX. so it can be a-f and 0-9.
* also, for convenience, a short-hash can be used, which is a minimum of 3 characters.
*/
export declare function isHash(str: string | null | undefined): boolean;

@@ -7,3 +15,3 @@ /**

*/
export declare function isTag(str: string | null | undefined): boolean;
export declare function isTag(str?: string): boolean;
/**

@@ -10,0 +18,0 @@ * a component version can be a tag (semver) or a snap (hash)

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.isSnap = exports.isTag = exports.isHash = exports.HASH_SIZE = void 0;
exports.isSnap = exports.isTag = exports.isHash = exports.SHORT_HASH_MINIMUM_SIZE = exports.HASH_SIZE = void 0;
const semver_1 = __importDefault(require("semver"));

@@ -12,2 +12,6 @@ const exceptions_1 = require("./exceptions");

exports.HASH_SIZE = 40;
/**
* because the directory structure is `XX/YY....`, it needs to have at least three characters.
*/
exports.SHORT_HASH_MINIMUM_SIZE = 3;
function isLatest(versionStr) {

@@ -17,3 +21,3 @@ return versionStr === version_1.LATEST_VERSION;

function isSemverValid(versionStr) {
return semver_1.default.valid(versionStr);
return Boolean(semver_1.default.valid(versionStr));
}

@@ -29,4 +33,8 @@ function returnSemver(versionStr) {

}
/**
* a snap is a 40 characters hash encoded in HEX. so it can be a-f and 0-9.
* also, for convenience, a short-hash can be used, which is a minimum of 3 characters.
*/
function isHash(str) {
return typeof str === 'string' && str.length === exports.HASH_SIZE && !semver_1.default.valid(str);
return typeof str === 'string' && isHex(str) && str.length >= exports.SHORT_HASH_MINIMUM_SIZE && str.length <= exports.HASH_SIZE;
}

@@ -38,3 +46,3 @@ exports.isHash = isHash;

function isTag(str) {
return !isHash(str);
return typeof str === 'string' && isSemverValid(str);
}

@@ -46,3 +54,3 @@ exports.isTag = isTag;

function isSnap(str) {
return isHash(str);
return isHash(str) && typeof str === 'string' && str.length === exports.HASH_SIZE;
}

@@ -62,2 +70,9 @@ exports.isSnap = isSnap;

exports.default = versionParser;
/**
* check if the string consists of valid hexadecimal characters
*/
function isHex(str) {
const hexRegex = /^[0-9a-fA-F]+$/;
return hexRegex.test(str);
}
//# sourceMappingURL=version-parser.js.map
import { Version, LATEST_VERSION } from './version';
import versionParser, { isHash, isSnap, isTag } from './version-parser';
import versionParser, { isHash, isSnap, isTag, HASH_SIZE, SHORT_HASH_MINIMUM_SIZE } from './version-parser';
import { InvalidVersion } from './exceptions';
export { Version, LATEST_VERSION, versionParser, isHash, isSnap, isTag, InvalidVersion };
export {
Version,
LATEST_VERSION,
versionParser,
isHash,
isSnap,
isTag,
InvalidVersion,
HASH_SIZE,
SHORT_HASH_MINIMUM_SIZE,
};
{
"name": "@teambit/component-version",
"version": "1.0.2",
"version": "1.0.3",
"homepage": "https://bit.cloud/teambit/component/component-version",

@@ -9,3 +9,3 @@ "main": "dist/index.js",

"name": "component-version",
"version": "1.0.2"
"version": "1.0.3"
},

@@ -12,0 +12,0 @@ "dependencies": {

@@ -7,2 +7,7 @@ import semver from 'semver';

/**
* because the directory structure is `XX/YY....`, it needs to have at least three characters.
*/
export const SHORT_HASH_MINIMUM_SIZE = 3;
function isLatest(versionStr: string): boolean {

@@ -13,3 +18,3 @@ return versionStr === LATEST_VERSION;

function isSemverValid(versionStr: string) {
return semver.valid(versionStr);
return Boolean(semver.valid(versionStr));
}

@@ -29,4 +34,8 @@

/**
* a snap is a 40 characters hash encoded in HEX. so it can be a-f and 0-9.
* also, for convenience, a short-hash can be used, which is a minimum of 3 characters.
*/
export function isHash(str: string | null | undefined): boolean {
return typeof str === 'string' && str.length === HASH_SIZE && !semver.valid(str);
return typeof str === 'string' && isHex(str) && str.length >= SHORT_HASH_MINIMUM_SIZE && str.length <= HASH_SIZE;
}

@@ -37,4 +46,4 @@

*/
export function isTag(str: string | null | undefined): boolean {
return !isHash(str);
export function isTag(str?: string): boolean {
return typeof str === 'string' && isSemverValid(str);
}

@@ -46,3 +55,3 @@

export function isSnap(str: string | null | undefined): boolean {
return isHash(str);
return isHash(str) && typeof str === 'string' && str.length === HASH_SIZE;
}

@@ -58,1 +67,9 @@

}
/**
* check if the string consists of valid hexadecimal characters
*/
function isHex(str: string) {
const hexRegex = /^[0-9a-fA-F]+$/;
return hexRegex.test(str);
}

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