當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript coreutils.JSONExt類代碼示例

本文整理匯總了TypeScript中@phosphor/coreutils.JSONExt的典型用法代碼示例。如果您正苦於以下問題:TypeScript JSONExt類的具體用法?TypeScript JSONExt怎麽用?TypeScript JSONExt使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了JSONExt類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: validateMimeValue

  export function validateMimeValue(
    type: string,
    value: MultilineString | JSONObject
  ): boolean {
    // Check if "application/json" or "application/foo+json"
    const jsonTest = /^application\/(.*?)+\+json$/;
    const isJSONType = type === 'application/json' || jsonTest.test(type);

    let isString = (x: any) => {
      return Object.prototype.toString.call(x) === '[object String]';
    };

    // If it is an array, make sure if is not a JSON type and it is an
    // array of strings.
    if (Array.isArray(value)) {
      if (isJSONType) {
        return false;
      }
      let valid = true;
      (value as string[]).forEach(v => {
        if (!isString(v)) {
          valid = false;
        }
      });
      return valid;
    }

    // If it is a string, make sure we are not a JSON type.
    if (isString(value)) {
      return !isJSONType;
    }

    // It is not a string, make sure it is a JSON type.
    if (!isJSONType) {
      return false;
    }

    // It is a JSON type, make sure it is a valid JSON object.
    return JSONExt.isObject(value);
  }
開發者ID:afshin,項目名稱:jupyterlab,代碼行數:40,代碼來源:nbformat.ts

示例2: getOption

  function getOption(name: string): string {
    if (configData) {
      return configData[name] || '';
    }
    configData = Object.create(null);
    let found = false;

    // Use script tag if available.
    if (typeof document !== 'undefined') {
      let el = document.getElementById('jupyter-config-data');
      if (el) {
        configData = JSON.parse(el.textContent || '') as { [key: string]: string };
        found = true;
      }
    }
    // Otherwise use CLI if given.
    if (!found && typeof process !== 'undefined') {
      try {
        let cli = minimist(process.argv.slice(2));
        if ('jupyter-config-data' in cli) {
          let path: any = require('path');
          let fullPath = path.resolve(cli['jupyter-config-data']);
          // Force Webpack to ignore this require.
          configData = eval('require')(fullPath) as { [key: string]: string };
        }
      } catch (e) {
        console.error(e);
      }
    }

    if (!JSONExt.isObject(configData)) {
      configData = Object.create(null);
    } else {
      for (let key in configData) {
        // Quote characters are escaped, unescape them.
        configData[key] = String(configData[key]).split(''').join('"');
      }
    }
    return configData[name] || '';
  }
開發者ID:charnpreetsingh185,項目名稱:jupyterlab,代碼行數:40,代碼來源:pageconfig.ts

示例3: populate

      compose: plugin => {
        // Only override the canonical schema the first time.
        if (!canonical) {
          canonical = JSONExt.deepCopy(plugin.schema);
          populate(canonical);
        }

        const defaults = canonical.properties.shortcuts.default;
        const user = {
          shortcuts: ((plugin.data && plugin.data.user) || {}).shortcuts || []
        };
        const composite = {
          shortcuts: SettingRegistry.reconcileShortcuts(
            defaults,
            user.shortcuts as ISettingRegistry.IShortcut[]
          )
        };

        plugin.data = { composite, user };

        return plugin;
      },
開發者ID:AlbertHilb,項目名稱:jupyterlab,代碼行數:22,代碼來源:index.ts

示例4: expect

 manager.runningChanged.connect((sender, args) => {
   expect(sender).to.be(manager);
   expect(JSONExt.deepEqual(toArray(args), data)).to.be(true);
   done();
 });
開發者ID:faricacarroll,項目名稱:jupyterlab,代碼行數:5,代碼來源:manager.spec.ts

示例5: it

 it('should get the running sessions', () => {
   let test = JSONExt.deepEqual(toArray(data), toArray(manager.running()));
   expect(test).to.be(true);
 });
開發者ID:faricacarroll,項目名稱:jupyterlab,代碼行數:4,代碼來源:manager.spec.ts

示例6: it

 it('should get the value of the object', () => {
   let value = new ObservableValue('value');
   expect(value.get()).to.be('value');
   let value2 = new ObservableValue({ one: 'one', two: 2 });
   expect(JSONExt.deepEqual(value2.get(), { one: 'one', two: 2 })).to.be(true);
 });
開發者ID:7125messi,項目名稱:jupyterlab,代碼行數:6,代碼來源:modeldb.spec.ts

示例7: it

 it('should compare two JSON values for deep equality', () => {
   expect(JSONExt.deepEqual([], [])).to.equal(true);
   expect(JSONExt.deepEqual([1], [1])).to.equal(true);
   expect(JSONExt.deepEqual({}, {})).to.equal(true);
   expect(JSONExt.deepEqual({a: []}, {a: []})).to.equal(true);
   expect(JSONExt.deepEqual({a: { b: null }}, {a: { b: null }})).to.equal(true);
   expect(JSONExt.deepEqual({a: '1'}, {a: '1'})).to.equal(true);
   expect(JSONExt.deepEqual({a: { b: null }}, {a: { b: '1' }})).to.equal(false);
   expect(JSONExt.deepEqual({a: []}, {a: [1]})).to.equal(false);
   expect(JSONExt.deepEqual([1], [1, 2])).to.equal(false);
   expect(JSONExt.deepEqual(null, [1, 2])).to.equal(false);
   expect(JSONExt.deepEqual([1], {})).to.equal(false);
   expect(JSONExt.deepEqual([1], [2])).to.equal(false);
   expect(JSONExt.deepEqual({}, { a: 1 })).to.equal(false);
   expect(JSONExt.deepEqual({ b: 1 }, { a: 1 })).to.equal(false);
 });
開發者ID:afshin,項目名稱:phosphor,代碼行數:16,代碼來源:json.spec.ts

示例8: expect

 }).then((info) => {
   content = info.content;
   expect(JSONExt.deepEqual(content, kernel.info)).to.be(true);
   return kernel.shutdown();
 });
開發者ID:faricacarroll,項目名稱:jupyterlab,代碼行數:5,代碼來源:integration.ts


注:本文中的@phosphor/coreutils.JSONExt類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。