UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

31 lines (28 loc) 681 B
/** * adds the character 0 at the beginning of a workd * * @remarks * It takes 2 arguments. * * `padzero(count, word_or_number)` * * - `count` - number of character the word will have * - `word_or_number` start of the word * * ## Usage * * - `padzero(4, 5)` - returns '0005' * */ import {BaseMethod} from './_Base'; export class PadzeroExpression extends BaseMethod { static override requiredArguments() { return [['string', 'number']]; } override async processArguments(args: any[]): Promise<string> { const pad: number = args[0] || 2; const srcNumber: number = args[1] || 0; const unpadded = `${srcNumber}`; return unpadded.padStart(pad, '0'); } }