chore(utils): migrate CSS dimensions utility to TypeScript
Added type annotations to the CSS dimensions utility (cssDimensions) and to its testing module. Both have been updated to .ts.
This commit is contained in:
2 files changed
+15
-3
No files matched your search
+8
-2
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { ensureUnit } from '../cssDimensions';
|
||||
import { ensureUnit, type RawDimension } from '../cssDimensions';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
describe('cssDimensions', () => {
|
||||
@@ -129,7 +129,13 @@ describe('cssDimensions', () => {
|
||||
},
|
||||
])(
|
||||
'ensureUnit returns $expected with input $dimension',
|
||||
({ dimension, expected }) => {
|
||||
({
|
||||
dimension,
|
||||
expected,
|
||||
}: {
|
||||
dimension: RawDimension;
|
||||
expected: string;
|
||||
}) => {
|
||||
expect(ensureUnit(dimension)).toBe(expected);
|
||||
},
|
||||
);
|
||||
@@ -14,7 +14,13 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export const ensureUnit = function ensureUnit(d) {
|
||||
/*
|
||||
* null and undefined because they are intended to represent empty input
|
||||
* values
|
||||
*/
|
||||
export type RawDimension = null | number | string | undefined;
|
||||
|
||||
export const ensureUnit = function ensureUnit(d: RawDimension): string {
|
||||
if (!d) d = 0;
|
||||
|
||||
// ensure that it is a string
|
||||
Reference in new issue
Block a user