Skip to content

Commit

Permalink
Fix Pad Left|Right
Browse files Browse the repository at this point in the history
  • Loading branch information
jessehouwing committed Feb 14, 2018
1 parent f79fc4b commit cc2942a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion vsts-variable-set/vsts-variable-set.njsproj
Expand Up @@ -5,6 +5,7 @@
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<Name>vsts-variable-set</Name>
<RootNamespace>vsts-variable-set</RootNamespace>
<ToolsVersionPromptShown>0.0</ToolsVersionPromptShown>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -39,7 +40,6 @@
<Content Include="task.json" />
<Content Include="tsconfig.json" />
<Content Include="tslint.json" />
<Content Include="typings.json" />
<Content Include="vsts-variable-set.ps1" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions vsts-variable-transform/package.json
Expand Up @@ -7,6 +7,7 @@
"email": "jesse.houwing@gmail.com"
},
"dependencies": {
"core-js": "^2.5.3",
"vsts-task-lib": "^2.1.0"
},
"scripts": {
Expand All @@ -15,6 +16,7 @@
"build": "tsc && npm dedupe && npm prune --production"
},
"devDependencies": {
"@types/core-js": "^0.9.46",
"@types/node": "^6.0.56",
"@types/q": "0.0.32",
"types": "^0.1.1",
Expand Down
2 changes: 1 addition & 1 deletion vsts-variable-transform/vsts-variable-transform.njsproj
Expand Up @@ -5,6 +5,7 @@
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<Name>vsts-variable-transform</Name>
<RootNamespace>NodejsConsoleApp1</RootNamespace>
<ToolsVersionPromptShown>0.0</ToolsVersionPromptShown>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -38,7 +39,6 @@
<Content Include="task.json" />
<Content Include="tsconfig.json" />
<Content Include="tslint.json" />
<Content Include="typings.json" />
<TypeScriptCompile Include="vsts-variable-transform.ts" />
<Content Include="package.json" />
</ItemGroup>
Expand Down
11 changes: 3 additions & 8 deletions vsts-variable-transform/vsts-variable-transform.ts
@@ -1,4 +1,5 @@
import tl = require("vsts-task-lib/task");
import "core-js";

const transformAction = tl.getInput("transformAction", true);
let value = tl.getInput("value") || "";
Expand Down Expand Up @@ -121,20 +122,14 @@ function applyManipulations(value: string): string {
if (!padCharacter) {
padCharacter = " ";
}
else if (padCharacter.length !== 1) {
console.log("More than one padding character specified.");
tl.setResult(tl.TaskResult.Failed, "Failed");
return;
}

const padLength = +tl.getInput("padLength", true);
const padBase = Array(padLength).join(padCharacter);
switch (padType) {
case "left":
value = (padBase + value).slice(value.length);
value = value.padStart(padLength, padCharacter);
break;
case "right":
value = (value + padBase).substring(0, padLength);
value = value.padEnd(padLength, padCharacter);
break;
}
}
Expand Down

0 comments on commit cc2942a

Please sign in to comment.