feat(editor): Add examples for number & boolean, add new methods (#9358)

This commit is contained in:
Elias Meire
2024-05-13 16:28:27 +02:00
committed by GitHub
parent da6088d0bb
commit 7b45dc313f
7 changed files with 192 additions and 27 deletions

View File

@@ -6,7 +6,12 @@ export const booleanMethods: NativeDoc = {
toString: {
doc: {
name: 'toString',
description: 'returns a string representing this boolean value.',
description:
"Converts <code>true</code> to the string <code>'true'</code> and <code>false</code> to the string <code>'false'</code>.",
examples: [
{ example: 'true.toString()', evaluated: "'true'" },
{ example: 'false.toString()', evaluated: "'false'" },
],
docURL:
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString',
returnType: 'string',

View File

@@ -29,18 +29,63 @@ export const numberMethods: NativeDoc = {
toString: {
doc: {
name: 'toString',
description: 'Returns a string representing this number value.',
description:
'Converts the number to a string. For more formatting options, see <code>toLocaleString()</code>.',
examples: [
{ example: '(2).toString()', evaluated: "'2'" },
{ example: '(50.125).toString()', evaluated: "'50.125'" },
{ example: '(5).toString(2)', evaluated: "'101'" },
{ example: '(412).toString(16)', evaluated: "'19c'" },
],
docURL:
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString',
args: [
{
name: 'base',
optional: true,
description:
'The base to use. Must be an integer between 2 and 36. E.g. base <code>2</code> is binary and base <code>16</code> is hexadecimal.',
default: '10',
type: 'number',
},
],
returnType: 'string',
},
},
toLocaleString: {
doc: {
name: 'toLocaleString',
description: 'Returns a string with a language-sensitive representation of this number.',
description:
"Returns a localized string representing the number, i.e. in the language and format corresponding to its locale. Defaults to the system's locale if none specified.",
examples: [
{
example: '(500000.125).toLocaleString()',
evaluated: "'500,000.125' (if in US English locale)",
},
{ example: "(500000.125).toLocaleString('fr-FR')", evaluated: "'500 000,125'" },
{
example: "(500000.125).toLocaleString('fr-FR', {style:'currency', currency:'EUR'})",
evaluated: "'500 000,13 €'",
},
],
docURL:
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString',
args: [
{
name: 'locale(s)',
optional: true,
description:
'The locale to use, e.g. \'en-GB\' for British English or \'pt-BR\' for Brazilian Portuguese. See <a target="_blank" href="https://www.localeplanet.com/icu/">full list</a> (unofficial). Also accepts an <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument">array of locales</a>. Defaults to the system locale if not specified.',
type: 'string | string[]',
},
{
name: 'options',
optional: true,
description:
'An object with <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#parameters">formatting options</a>',
type: 'object',
},
],
returnType: 'string',
},
},