-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor code for using pipe pattern for transform source
- Loading branch information
Showing
8 changed files
with
530 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"scalawind": patch | ||
--- | ||
|
||
refactor code to use pipe pattern for transform source |
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,48 @@ | ||
// THIS FILE IS FOR INTERNAL USAGE, PLEASE IGNORE THIS FILE | ||
|
||
import { extractTw } from './transform'; | ||
|
||
function convertCamelCaseToSnakeCase(methodName) { | ||
const units = ["px", "pc", "vh", "tx"]; | ||
|
||
const step1 = methodName.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`); | ||
|
||
const step2 = step1.replace(/^([:a-z]+)([0-9]+)$/g, (match, p1, p2) => { | ||
if (units.includes(p1)) { | ||
return match; | ||
} else { | ||
return `${p1}_${p2}`; | ||
} | ||
}); | ||
|
||
const step3 = step2.replace(/_([a-z]+)([0-9]+)/g, (match, p1, p2) => { | ||
if (units.includes(p1)) { | ||
return match; | ||
} else { | ||
return `_${p1}_${p2}`; | ||
} | ||
}); | ||
|
||
return step3.toLowerCase(); | ||
} | ||
|
||
function toSnakeCase(methodName) { | ||
if (/^px[0-9]+$/.test(methodName)) { | ||
return `px_${methodName.substring(2)}`; | ||
} else { | ||
return convertCamelCaseToSnakeCase(methodName); | ||
} | ||
} | ||
|
||
export function transformSource(source) { | ||
try { | ||
return extractTw(source, toSnakeCase); | ||
} catch (error) { | ||
console.error("Error transforming source:", error); | ||
throw error; | ||
} | ||
} | ||
|
||
export const scalaSourceTransform = { | ||
scala: (content) => transformSource(content), | ||
}; |
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
Oops, something went wrong.