-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Krister Kari <[email protected]>
- Loading branch information
1 parent
77650db
commit 26cdc5c
Showing
8 changed files
with
546 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const validateTypes = require("./validateTypes"); | ||
|
||
/** | ||
* Get the index of a declaration's value | ||
* | ||
* @param {import('postcss').Declaration} decl | ||
* @returns {number} | ||
*/ | ||
function declarationValueIndex(decl) { | ||
const raws = decl.raws; | ||
const prop = raws.prop; | ||
|
||
return [ | ||
validateTypes.isObject(prop) && "prefix" in prop && prop.prefix, | ||
(validateTypes.isObject(prop) && "raw" in prop && prop.raw) || decl.prop, | ||
validateTypes.isObject(prop) && "suffix" in prop && prop.suffix, | ||
raws.between || ":", | ||
raws.value && "prefix" in raws.value && raws.value.prefix | ||
].reduce((/** @type {number} */ count, str) => { | ||
if (validateTypes.isString(str)) { | ||
return count + str.length; | ||
} | ||
|
||
return count; | ||
}, 0); | ||
} | ||
|
||
module.exports = declarationValueIndex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** * Checks if the value is an object. | ||
* @param {unknown} value | ||
* @returns {value is object} | ||
*/ | ||
function isObject(value) { | ||
return value !== null && typeof value === "object"; | ||
} | ||
|
||
/** | ||
* Checks if the value is a string or a String object. | ||
* @param {unknown} value | ||
* @returns {value is string} | ||
*/ | ||
function isString(value) { | ||
return typeof value === "string" || value instanceof String; | ||
} | ||
|
||
exports.isObject = isObject; | ||
exports.isString = isString; |
Oops, something went wrong.