@applitools/utils
Advanced tools
Comparing version 1.2.4 to 1.2.5
# Changelog | ||
- improve `geometry.rotate` to also rotate coordinates | ||
- fix `geometry.isEmpty` | ||
- fix `geometry.isIntersected` | ||
## Unreleased | ||
## 1.2.4 - 2021/10/27 | ||
## 1.2.5 - 2021/12/22 | ||
- add a method to validate that a url is a google font resource | ||
- remove `guard.isGoogleFont` method form utils and transfer it to rGridResource | ||
## 1.2.4 - 2021/10/27 | ||
- add a method to validate that a url is a google font resource | ||
## 1.2.3 - 2021/9/9 | ||
@@ -11,0 +19,0 @@ |
@@ -40,3 +40,3 @@ "use strict"; | ||
function isEmpty(sizeOrRegion) { | ||
return sizeOrRegion.width === 0 && sizeOrRegion.height === 0; | ||
return sizeOrRegion.width === 0 || sizeOrRegion.height === 0; | ||
} | ||
@@ -57,9 +57,44 @@ exports.isEmpty = isEmpty; | ||
exports.round = round; | ||
function rotate(target, degree) { | ||
const result = Object.assign({}, target); | ||
const rotate = Boolean(Math.floor(degree / 90) % 2); | ||
if (rotate) { | ||
result.width = target.height; | ||
result.height = target.width; | ||
function rotate(target, degrees, size) { | ||
degrees = (360 + degrees) % 360; | ||
const result = {}; | ||
if (types.has(target, ['width', 'height'])) { | ||
// rotate size | ||
if (degrees === 90 || degrees === 270) { | ||
result.width = target.height; | ||
result.height = target.width; | ||
} | ||
else { | ||
result.width = target.width; | ||
result.height = target.height; | ||
} | ||
} | ||
if (types.has(target, ['x', 'y'])) { | ||
const hasSize = types.has(target, ['width', 'height']); | ||
// rotate coordinate system around a target | ||
if (degrees === 0) { | ||
result.x = target.x; | ||
result.y = target.y; | ||
} | ||
else if (degrees === 90) { | ||
result.x = size.height - target.y; | ||
result.y = target.x; | ||
if (hasSize) | ||
result.x -= result.width; | ||
} | ||
else if (degrees === 180) { | ||
result.x = size.width - target.x; | ||
result.y = size.height - target.y; | ||
if (hasSize) { | ||
result.x -= result.width; | ||
result.y -= result.height; | ||
} | ||
} | ||
else if (degrees === 270) { | ||
result.x = target.y; | ||
result.y = size.width - target.x; | ||
if (hasSize) | ||
result.y -= result.height; | ||
} | ||
} | ||
return result; | ||
@@ -107,6 +142,4 @@ } | ||
function isIntersected(region1, region2) { | ||
return (((region1.x <= region2.x && region2.x <= region1.x + region1.width) || | ||
(region2.x <= region1.x && region1.x <= region2.y + region2.width)) && | ||
((region1.y <= region2.y && region2.y <= region1.y + region1.height) || | ||
(region2.y <= region1.y && region1.y <= region2.y + region2.height))); | ||
return ((region1.x <= region2.x ? region2.x < region1.x + region1.width : region1.x < region2.y + region2.width) && | ||
(region1.y <= region2.y ? region2.y < region1.y + region1.height : region1.y < region2.y + region2.height)); | ||
} | ||
@@ -113,0 +146,0 @@ exports.isIntersected = isIntersected; |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isGoogleFont = exports.custom = exports.instanceOf = exports.isOneOf = exports.isEnumValue = exports.isObject = exports.isArray = exports.isNumeric = exports.isAlpha = exports.isAlphanumeric = exports.isString = exports.isGreaterThenOrEqual = exports.isGreaterThen = exports.isLessThenOrEqual = exports.isLessThen = exports.isInteger = exports.isNumber = exports.isBoolean = exports.notNull = void 0; | ||
exports.custom = exports.instanceOf = exports.isOneOf = exports.isEnumValue = exports.isObject = exports.isArray = exports.isNumeric = exports.isAlpha = exports.isAlphanumeric = exports.isString = exports.isGreaterThenOrEqual = exports.isGreaterThen = exports.isLessThenOrEqual = exports.isLessThen = exports.isInteger = exports.isNumber = exports.isBoolean = exports.notNull = void 0; | ||
const types = __importStar(require("./types")); | ||
@@ -158,8 +158,1 @@ function notNull(value, { name }) { | ||
exports.custom = custom; | ||
function isGoogleFont(url) { | ||
if (/https:\/\/fonts.googleapis.com/.test(url)) | ||
return true; | ||
else | ||
return false; | ||
} | ||
exports.isGoogleFont = isGoogleFont; |
{ | ||
"name": "@applitools/utils", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"keywords": [ | ||
@@ -53,3 +53,3 @@ "applitools", | ||
"devDependencies": { | ||
"@applitools/sdk-release-kit": "0.13.3", | ||
"@applitools/sdk-release-kit": "0.13.4", | ||
"@types/node": "^14.14.7", | ||
@@ -56,0 +56,0 @@ "@typescript-eslint/eslint-plugin": "^4.7.0", |
@@ -23,4 +23,5 @@ declare type Location = { | ||
export declare function round(region: Location): Location; | ||
export declare function rotate(region: Region, degree: number): Region; | ||
export declare function rotate(size: RectangleSize, degree: number): RectangleSize; | ||
export declare function rotate(size: RectangleSize, degrees: number): RectangleSize; | ||
export declare function rotate(region: Region, degrees: number, size: RectangleSize): Region; | ||
export declare function rotate(location: Location, degrees: number, size: RectangleSize): RectangleSize; | ||
export declare function scale(region: Region, scaleRatio: number): Region; | ||
@@ -27,0 +28,0 @@ export declare function scale(size: RectangleSize, scaleRatio: number): RectangleSize; |
@@ -38,3 +38,2 @@ declare type NamedParam = { | ||
export declare function custom(value: any, check: (value: any) => boolean, { name, strict, message }: CustomParam): void; | ||
export declare function isGoogleFont(url: string): boolean; | ||
export {}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51121
759