PHP 8.2.30
Preview: coerce.def Size: 2.17 KB
/proc/thread-self/root/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules/ajv/lib/dot/coerce.def

{{## def.coerceType:
  {{
    var $dataType = 'dataType' + $lvl
      , $coerced = 'coerced' + $lvl;
  }}
  var {{=$dataType}} = typeof {{=$data}};
  {{? it.opts.coerceTypes == 'array'}}
    if ({{=$dataType}} == 'object' && Array.isArray({{=$data}})) {{=$dataType}} = 'array';
  {{?}}

  var {{=$coerced}} = undefined;

  {{ var $bracesCoercion = ''; }}
  {{~ $coerceToTypes:$type:$i }}
    {{? $i }}
      if ({{=$coerced}} === undefined) {
      {{ $bracesCoercion += '}'; }}
    {{?}}

    {{? it.opts.coerceTypes == 'array' && $type != 'array' }}
      if ({{=$dataType}} == 'array' && {{=$data}}.length == 1) {
        {{=$coerced}} = {{=$data}} = {{=$data}}[0];
        {{=$dataType}} = typeof {{=$data}};
        /*if ({{=$dataType}} == 'object' && Array.isArray({{=$data}})) {{=$dataType}} = 'array';*/
      }
    {{?}}

    {{? $type == 'string' }}
      if ({{=$dataType}} == 'number' || {{=$dataType}} == 'boolean')
        {{=$coerced}} = '' + {{=$data}};
      else if ({{=$data}} === null) {{=$coerced}} = '';
    {{?? $type == 'number' || $type == 'integer' }}
      if ({{=$dataType}} == 'boolean' || {{=$data}} === null
          || ({{=$dataType}} == 'string' && {{=$data}} && {{=$data}} == +{{=$data}}
          {{? $type == 'integer' }} && !({{=$data}} % 1){{?}}))
        {{=$coerced}} = +{{=$data}};
    {{?? $type == 'boolean' }}
      if ({{=$data}} === 'false' || {{=$data}} === 0 || {{=$data}} === null)
        {{=$coerced}} = false;
      else if ({{=$data}} === 'true' || {{=$data}} === 1)
        {{=$coerced}} = true;
    {{?? $type == 'null' }}
      if ({{=$data}} === '' || {{=$data}} === 0 || {{=$data}} === false)
        {{=$coerced}} = null;
    {{?? it.opts.coerceTypes == 'array' && $type == 'array' }}
      if ({{=$dataType}} == 'string' || {{=$dataType}} == 'number' || {{=$dataType}} == 'boolean' || {{=$data}} == null)
        {{=$coerced}} = [{{=$data}}];
    {{?}}
  {{~}}

  {{= $bracesCoercion }}

  if ({{=$coerced}} === undefined) {
    {{# def.error:'type' }}
  } else {
    {{# def.setParentData }}
    {{=$data}} = {{=$coerced}};
    {{? !$dataLvl }}if ({{=$parentData}} !== undefined){{?}}
      {{=$parentData}}[{{=$parentDataProperty}}] = {{=$coerced}};
  }
#}}

Directory Contents

Dirs: 0 × Files: 28

Name Size Perms Modified Actions
629 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
943 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
2.17 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
280 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
1.18 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
4.85 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
859 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
3.80 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
1.80 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
552 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
8.07 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
3.09 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
2.57 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
1.17 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
618 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
861 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
922 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
348 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
10.08 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
1.28 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
2.37 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
2.80 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
837 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
7.06 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
3.25 KB lrw-r--r-- 2021-09-28 10:29:28
Edit Download
327 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
332 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download
350 B lrw-r--r-- 2021-09-28 10:29:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).