<!DOCTYPE HTML>
<html style="height: 100%;">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Demo</title>
  <script id="sap-ui-bootstrap"
    src="https://sdk.openui5.org/resources/sap-ui-core.js"
    data-sap-ui-oninit="onUI5Init"
    data-sap-ui-theme="sap_horizon"
    data-sap-ui-libs="sap.ui.core,sap.m,sap.ui.layout,sap.ui.unified"
    data-sap-ui-async="true"
    data-sap-ui-modules="demo/model/type/NumericBoolean"
    data-sap-ui-resourceroots='{"demo": "./"}'
    data-sap-ui-compatVersion="edge"
    data-sap-ui-excludejquerycompat="true"
    data-sap-ui-xx-waitfortheme="init"
  ></script>
  <script>
    globalThis.onUI5Init = () => sap.ui.require([
      "sap/ui/core/mvc/XMLView",
      "sap/ui/model/json/JSONModel",
    ], async (XMLView, JSONModel) => {
      "use strict";

      const control = await XMLView.create({
        definition: `<mvc:View xmlns:mvc="sap.ui.core.mvc"
          xmlns="sap.m"
          xmlns:core="sap.ui.core"
          core:require="{ NumericBoolean: 'demo/model/type/NumericBoolean' }"
          displayBlock="true"
        >
          <App autoFocus="false">
            <Page showHeader="false">
              <VBox class="sapUiTinyMargin">
                <ObjectAttribute title="Model data" text="{/1or0}" />
                <Switch state="{
                  path: '/1or0',
                  type: 'NumericBoolean'
                }" type="AcceptReject" />
                <CheckBox selected="{
                  path: '/1or0',
                  type: 'NumericBoolean'
                }" />
              </VBox>
            </Page>
          </App>
        </mvc:View>`,
        models: new JSONModel({ "1or0": "1" }),
      });
      
      control.placeAt("content");
    });
  </script>
</head>
<body id="content" class="sapUiBody">
</body>
</html>
sap.ui.define([
  "sap/ui/model/SimpleType",
], Type => Type.extend("demo.model.type.NumericBoolean", {
  constructor: function() { // JS doesn't allow arrow function for constructors
    Type.apply(this, arguments);
  },
  formatValue: iValue => !!+iValue,
  parseValue: bValue => bValue ? 1 : 0,
  validateValue: (/*...*/) => {/*...*/},
}));