| 1918 | 1918 | ], |
| 1919 | 1919 | helpString: 'Converts the provided string to lowercase.', |
| 1920 | 1920 | })); |
| 1921 | + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 1922 | + name: 'substr', |
| 1923 | + aliases: ['substring'], |
| 1924 | + callback: (arg, text) => typeof text === 'string' ? text.slice(...[Number(arg.start), arg.end && Number(arg.end)]) : '', |
| 1925 | + returns: 'substring', |
| 1926 | + namedArgumentList: [ |
| 1927 | + new SlashCommandNamedArgument( |
| 1928 | + 'start', 'start index', [ARGUMENT_TYPE.NUMBER], false, false, |
| 1929 | + ), |
| 1930 | + new SlashCommandNamedArgument( |
| 1931 | + 'end', 'end index', [ARGUMENT_TYPE.NUMBER], false, false, |
| 1932 | + ), |
| 1933 | + ], |
| 1934 | + unnamedArgumentList: [ |
| 1935 | + new SlashCommandArgument( |
| 1936 | + 'string', [ARGUMENT_TYPE.STRING], true, false, |
| 1937 | + ), |
| 1938 | + ], |
| 1939 | + helpString: ` |
| 1940 | + <div> |
| 1941 | + Extracts text from the provided string. |
| 1942 | + </div> |
| 1943 | + <div> |
| 1944 | + If <code>start</code> is omitted, it's treated as 0.<br /> |
| 1945 | + If <code>start</code> < 0, the index is counted from the end of the string.<br /> |
| 1946 | + If <code>start</code> >= the string's length, an empty string is returned.<br /> |
| 1947 | + If <code>end</code> is omitted, or if <code>end</code> >= the string's length, extracts to the end of the string.<br /> |
| 1948 | + If <code>end</code> < 0, the index is counted from the end of the string.<br /> |
| 1949 | + If <code>end</code> <= <code>start</code> after normalizing negative values, an empty string is returned. |
| 1950 | + </div> |
| 1951 | + <div> |
| 1952 | + <strong>Example:</strong> |
| 1953 | + <pre>/let x The morning is upon us. || </pre> |
| 1954 | + <pre>/substr start=-3 {{var::x}} | /echo |/# us. ||</pre> |
| 1955 | + <pre>/substr start=-3 end=-1 {{var::x}} | /echo |/# us ||</pre> |
| 1956 | + <pre>/substr end=-1 {{var::x}} | /echo |/# The morning is upon us ||</pre> |
| 1957 | + <pre>/substr start=4 end=-1 {{var::x}} | /echo |/# morning is upon us ||</pre> |
| 1958 | + </div> |
| 1959 | + `, |
| 1960 | + })); |
| 1921 | 1961 | |
| 1922 | 1962 | registerVariableCommands(); |
| 1923 | 1963 | } |