-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathreplace.ts
More file actions
32 lines (26 loc) · 1 KB
/
replace.ts
File metadata and controls
32 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import path from 'path';
export const replaceNames = (content: string, names: string[]) => {
return content.replace(/#names#/g, names.join(`' | '`));
};
export const replaceSize = (content: string, size: number) => {
return content.replace(/#size#/g, String(size));
};
export const replacePlatform = (content: string, platform: string) => {
return content.replace(/#platform#/g, platform);
};
export const replaceIsRpx = (content: string, useRpx: boolean) => {
return content
.replace(/#rpx-1:(.+?):#/g, useRpx ? '$1' : '')
.replace(/#rpx-0:(.+?):#/g, useRpx ? '' : '$1');
};
export const replaceDesignWidth = (content: string, designWidth) => {
return content
.replace(/#designWidth#/g, designWidth)
};
export const replaceRelativePath = (content: string, saveDir: string) => {
const relativePath = path
.relative(path.resolve('src'), path.resolve(saveDir))
// To resolve the path separator on windows
.replace(/\\/g, '/');
return content.replace(/#relativePath#/g, relativePath);
};