String helpers

Following is the list of available string helpers that you can use with in your edge templates. The framework core and official packages of AdonisJS are already using these helpers, its just we have also injected them as view helpers.


camelCase

Convert a string to its camelCase version.

{{ camelCase('hello-world') }}
<!-- Output: helloWorld -->

snakeCase

Convert a string to its snake_case version.

{{ snakeCase('helloWorld') }}
<!-- Output: hello_world -->

dashCase

Convert a string to its dash-case version. Optionally, you can also capitalize the first letter of each segment.

{{ string.dashCase('helloWorld') }} <!-- hello-world -->
{{
string.dashCase('helloWorld', { capitalize: true })
}} <!-- Hello-World -->

pascalCase

Convert a string to its PascalCase version.

{{ pascalCase('helloWorld') }}
<!-- Output: HelloWorld -->

capitalCase

Capitalize a string value.

{{ capitalCase('helloWorld') }}
<!-- Output: Hello World -->

sentenceCase

Convert string to sentence case.

{{ sentenceCase('hello-world') }}
<!-- Output: Hello world -->

dotCase

Convert string to its dot.case version.

{{ dotCase('hello-world') }}
<!-- Output: hello.world -->

noCase

Remove all sorts of casing from a string.

{{ noCase('hello-world') }} <!-- hello world -->
{{ noCase('hello_world') }} <!-- hello world -->
{{ noCase('helloWorld') }} <!-- hello world -->

titleCase

Convert a sentence to title case.

{{ titleCase('Here is a fox') }}
<!-- Output: Here Is a fox -->

pluralize

Pluralize a word.

{{ pluralize('box') }} <!-- boxes -->
{{ pluralize('i') }} <!-- we -->

toSentence

Join an array of words with a separator to form a sentence.

{{
toSentence([
'route',
'middleware',
'controller'
])
}}
<!-- route, middleware, and controller -->

You can also define the following options to customize the separators.

{{
toSentence([
'route',
'middleware',
'controller'
], {
separator: '/ ',
lastSeparator: '/or '
})
}}
<!-- route/ middleware/or controller -->

prettyBytes

Convert bytes value to a human readable string. Accepts and forwards all the options to the bytes package.

{{ prettyBytes(1024) }} <!-- 1KB -->
{{
prettyBytes(1024, { unitSeparator: ' ' })
}} <!-- 1 KB -->

toBytes

Convert human readable string to bytes. This method is the opposite of the prettyBytes method.

{{ toBytes('1KB') }} <!-- 1024 -->

prettyMs

Convert time represented in milliseconds to a human readable string.

{{ prettyMs(60000) }} <!-- 1min -->
{{ prettyMs(60000, { long: true }) }} <!-- 1 minute -->

toMs

Convert human readable string to milliseconds. This method is the opposite of the prettyMs method.

{{ toMs('1min') }} <!-- 60000 -->

ordinalize

Ordinalize a string or a number value.

{{ ordinalize(1) }} <!-- 1st -->
{{ ordinalize(99) }} <!-- 99th -->