Format styles with updated prettier config
In the system color PR I updated the prettier config to match what we use on zed.dev. I didn't want to format all of styles as it would add a lot of unrelated line changes to that PR. Doing that format now.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import chroma from "chroma-js";
|
||||
import chroma from "chroma-js"
|
||||
|
||||
export function withOpacity(color: string, opacity: number): string {
|
||||
return chroma(color).alpha(opacity).hex();
|
||||
return chroma(color).alpha(opacity).hex()
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
import { snakeCase } from "case-anything";
|
||||
import { snakeCase } from "case-anything"
|
||||
|
||||
// https://stackoverflow.com/questions/60269936/typescript-convert-generic-object-from-snake-to-camel-case
|
||||
|
||||
// Typescript magic to convert any string from camelCase to snake_case at compile time
|
||||
type SnakeCase<S> = S extends string
|
||||
? S extends `${infer T}${infer U}`
|
||||
? `${T extends Capitalize<T> ? "_" : ""}${Lowercase<T>}${SnakeCase<U>}`
|
||||
? S extends `${infer T}${infer U}`
|
||||
? `${T extends Capitalize<T> ? "_" : ""}${Lowercase<T>}${SnakeCase<U>}`
|
||||
: S
|
||||
: S
|
||||
: S;
|
||||
|
||||
type SnakeCased<Type> = {
|
||||
[Property in keyof Type as SnakeCase<Property>]: SnakeCased<Type[Property]>;
|
||||
};
|
||||
[Property in keyof Type as SnakeCase<Property>]: SnakeCased<Type[Property]>
|
||||
}
|
||||
|
||||
export default function snakeCaseTree<T>(object: T): SnakeCased<T> {
|
||||
const snakeObject: any = {};
|
||||
for (const key in object) {
|
||||
snakeObject[snakeCase(key, { keepSpecialCharacters: true })] =
|
||||
snakeCaseValue(object[key]);
|
||||
}
|
||||
return snakeObject;
|
||||
const snakeObject: any = {}
|
||||
for (const key in object) {
|
||||
snakeObject[snakeCase(key, { keepSpecialCharacters: true })] =
|
||||
snakeCaseValue(object[key])
|
||||
}
|
||||
return snakeObject
|
||||
}
|
||||
|
||||
function snakeCaseValue(value: any): any {
|
||||
if (typeof value === "object") {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(snakeCaseValue);
|
||||
if (typeof value === "object") {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(snakeCaseValue)
|
||||
} else {
|
||||
return snakeCaseTree(value)
|
||||
}
|
||||
} else {
|
||||
return snakeCaseTree(value);
|
||||
return value
|
||||
}
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user