Skip to content
Source
Sign inSign up
TanStack/cli
Open History to see the last commit

utils.ts

50 lines1.2 KB

1export function sortObject(
2 obj: Record<string, string>,
3): Record<string, string> {
4 return Object.keys(obj)
5 .sort()
6 .reduce<Record<string, string>>((acc, key) => {
7 acc[key] = obj[key]
8 return acc
9 }, {})
11​
12export function jsSafeName(name: string) {
13 return name
14 .split(/[^a-zA-Z0-9]/)
15 .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
16 .join('')
18​
19export function formatCommand({
20 command,
21 args,
22}: {
23 command: string
24 args: Array<string>
25}) {
26 return `${command} ${args.join(' ')}`.trim()
28​
29// Turn GitHub URLs into raw URLs
30export function handleSpecialURL(url: string) {
31 if (url.startsWith('https://github.com/') && url.includes('blob')) {
32 return url
33 .replace('https://github.com/', 'https://raw.githubusercontent.com/')
34 .replace('/blob/', '/refs/heads/')
35 }
36 if (url.startsWith('https://github.com/') && url.includes('tree')) {
37 return url
38 .replace('https://github.com/', 'https://raw.githubusercontent.com/')
39 .replace('/tree/', '/refs/heads/')
40 }
41 return url
43​
44export function hasDrive(path: string) {
45 return /^[A-Za-z]:/.test(path)
47​
48export function stripDrive(path: string) {
49 return path.replace(/^[A-Za-z]:/, '')