lodash#isBoolean TypeScript Examples

The following examples show how to use lodash#isBoolean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: is-resource.ts    From js-client with MIT License 6 votes vote down vote up
isResource = (value: any): value is Resource => {
	try {
		const r = <Resource>value;
		return (
			isUUID(r.id) &&
			isNumericID(r.userID) &&
			r.groupIDs.every(isNumericID) &&
			isString(r.name) &&
			isString(r.description) &&
			r.labels.every(isString) &&
			isBoolean(r.isGlobal) &&
			isDate(r.lastUpdateDate) &&
			isInteger(r.version) &&
			isString(r.hash) &&
			isInteger(r.size)
		);
	} catch {
		return false;
	}
}
Example #2
Source File: is-dashboard.ts    From js-client with MIT License 6 votes vote down vote up
isDashboard = (value: unknown): value is Dashboard => {
	try {
		const d = <Dashboard>value;
		return (
			isNumericID(d.id) &&
			isUUID(d.globalID) &&
			isNumericID(d.userID) &&
			isArray(d.groupIDs) &&
			d.groupIDs.every(isNumericID) &&
			isString(d.name) &&
			(isNull(d.description) || isString(d.description)) &&
			isArray(d.labels) &&
			d.labels.every(isString) &&
			isDate(d.creationDate) &&
			isDate(d.lastUpdateDate) &&
			isDate(d.lastMainUpdateDate) &&
			isVersion(d.version) &&
			isBoolean(d.updateOnZoom) &&
			isDashboardLiveUpdate(d.liveUpdate) &&
			isTimeframe(d.timeframe) &&
			isArray(d.searches) &&
			d.searches.every(isDashboardSearch) &&
			isArray(d.tiles) &&
			d.tiles.every(isDashboardTile) &&
			(isNull(d.gridOptions.gutter) || isNumber(d.gridOptions.gutter)) &&
			(isNull(d.gridOptions.margin) || isNumber(d.gridOptions.margin))
		);
	} catch {
		return false;
	}
}
Example #3
Source File: shard.ts    From js-client with MIT License 6 votes vote down vote up
isShard = (value: unknown): value is Shard => {
	try {
		const s = <Shard>value;

		return (
			isString(s.name) &&
			isDate(s.start) &&
			isDate(s.end) &&
			isNumber(s.entries) &&
			isNumber(s.size) &&
			isBoolean(s.cold) &&
			(isUndefined(s.remoteState) ||
				(isUUID(s.remoteState.uuid) && isNumber(s.remoteState.entries) && isNumber(s.remoteState.size)))
		);
	} catch {
		return false;
	}
}
Example #4
Source File: is-local-kit.ts    From js-client with MIT License 6 votes vote down vote up
isLocalKit = (v: any): v is LocalKit => {
	try {
		const k = <LocalKit>v;
		return (
			isID(k.customID) &&
			isUUID(k.globalID) &&
			isNumericID(k.userID) &&
			k.groupIDs.every(isNumericID) &&
			isString(k.name) &&
			isString(k.description) &&
			k.labels.every(isString) &&
			isDate(k.installationDate) &&
			isVersion(k.version) &&
			isVersion(k.gravwellCompatibility.min) &&
			isVersion(k.gravwellCompatibility.max) &&
			['installed', 'uploaded'].includes(k.status) &&
			isBoolean(k.isSigned) &&
			isBoolean(k.requiresAdminPrivilege) &&
			k.items.every(isKitItem) &&
			k.configMacros.every(
				s =>
					isString(s.macroName) &&
					isString(s.description) &&
					isString(s.defaultValue) &&
					(isString(s.value) || (isNull(s.value) && ['tag', 'string'].includes(s.type))),
			)
		);
	} catch {
		return false;
	}
}
Example #5
Source File: is-remote-kit.ts    From js-client with MIT License 6 votes vote down vote up
isRemoteKit = (v: any): v is RemoteKit => {
	try {
		const k = <RemoteKit>v;
		return (
			isUUID(k.customID) &&
			isUUID(k.globalID) &&
			isString(k.name) &&
			isString(k.description) &&
			k.labels.every(isString) &&
			isDate(k.creationDate) &&
			isVersion(k.version) &&
			isVersion(k.gravwellCompatibility.min) &&
			isVersion(k.gravwellCompatibility.max) &&
			isNumber(k.size) &&
			k.ingesters.every(isString) &&
			isBoolean(k.isSigned) &&
			isBoolean(k.requiresAdminPrivilege) &&
			k.assets.every(isKitAsset) &&
			k.dependencies.every(isKitDependency) &&
			k.items.every(isKitItem)
		);
	} catch {
		return false;
	}
}
Example #6
Source File: kit-asset.ts    From js-client with MIT License 6 votes vote down vote up
isKitAsset = (v: any): v is KitAsset => {
	try {
		const k = <KitAsset>v;
		switch (k.type) {
			case 'readme':
				return isString(k.url) && isBoolean(k.isFeatured);
			case 'image':
				return isString(k.description) && isString(k.url) && isBoolean(k.isFeatured);
			default:
				return false;
		}
	} catch {
		return false;
	}
}
Example #7
Source File: is-template.ts    From js-client with MIT License 6 votes vote down vote up
isTemplate = (value: any): value is Template => {
	try {
		const t = <Template>value;
		return (
			isUUID(t.globalID) &&
			isUUID(t.id) &&
			isNumericID(t.userID) &&
			t.groupIDs.every(isNumericID) &&
			isString(t.name) &&
			(isString(t.description) || isNull(t.description)) &&
			t.labels.every(isString) &&
			isBoolean(t.isGlobal) &&
			isDate(t.lastUpdateDate) &&
			isString(t.query) &&
			t.variables.every(isTemplateVariable)
		);
	} catch {
		return false;
	}
}
Example #8
Source File: is-mail-server-config.ts    From js-client with MIT License 6 votes vote down vote up
isMailServerConfig = (v: any): v is MailServerConfig => {
	if (isPlainObject(v)) {
		return (
			isOfTypeOrNil(v.server, isString) &&
			isOfTypeOrNil(v.password, isString) &&
			isOfTypeOrNil(v.string, isString) &&
			isOfTypeOrNil(v.port, isNumber) &&
			isOfTypeOrNil(v.useTLS, isBoolean) &&
			isOfTypeOrNil(v.insecureSkipVerify, isBoolean)
		);
	}
	return false;
}
Example #9
Source File: is-playbook.ts    From js-client with MIT License 6 votes vote down vote up
isPlaybook = (value: any): value is Playbook => {
	try {
		const p = <Playbook>value;
		return (
			isUUID(p.id) &&
			isUUID(p.globalID) &&
			isNumericID(p.userID) &&
			p.groupIDs.every(isNumericID) &&
			isString(p.name) &&
			(isString(p.description) || isNull(p.description)) &&
			p.labels.every(isString) &&
			isBoolean(p.isGlobal) &&
			isDate(p.lastUpdateDate) &&
			isMarkdown(p.body) &&
			(isUUID(p.coverImageFileGlobalID) || isNull(p.coverImageFileGlobalID)) &&
			(isUUID(p.bannerImageFileGlobalID) || isNull(p.bannerImageFileGlobalID)) &&
			(isString(p.author.name) || isNull(p.author.name)) &&
			(isString(p.author.email) || isNull(p.author.email)) &&
			(isString(p.author.company) || isNull(p.author.company)) &&
			(isString(p.author.url) || isNull(p.author.url))
		);
	} catch {
		return false;
	}
}
Example #10
Source File: is-actionable.ts    From js-client with MIT License 6 votes vote down vote up
isActionableCommand = (value: any): value is ActionableCommand => {
	try {
		const cmd = <ActionableCommand>value;
		switch (cmd.type) {
			case 'query':
				return isString(cmd.userQuery);
			case 'template':
				return isUUID(cmd.templateID);
			case 'savedQuery':
				return isUUID(cmd.queryID);
			case 'dashboard':
				return isUUID(cmd.dashboardID) && (isString(cmd.dashboardVariable) || isNull(cmd.dashboardVariable));
			case 'url':
				return (
					isString(cmd.urlTemplate) &&
					isBoolean(cmd.modal) &&
					(isInteger(cmd.modalWidthPercentage) || isNull(cmd.modalWidthPercentage))
				);
			default:
				throw Error();
		}
	} catch {
		return false;
	}
}
Example #11
Source File: is-saved-query.ts    From js-client with MIT License 6 votes vote down vote up
isSavedQuery = (value: any): value is SavedQuery => {
	try {
		const q = <SavedQuery>value;
		return (
			isUUID(q.id) &&
			isUUID(q.globalID) &&
			isNumericID(q.userID) &&
			q.groupIDs.every(isNumericID) &&
			isBoolean(q.isGlobal) &&
			isString(q.name) &&
			(isString(q.description) || isNull(q.description)) &&
			q.labels.every(isString) &&
			isString(q.query) &&
			(isTimeframe(q.defaultTimeframe) || isNull(q.defaultTimeframe))
		);
	} catch {
		return false;
	}
}
Example #12
Source File: is-scheduled-query.ts    From js-client with MIT License 6 votes vote down vote up
isScheduledQuery = (value: any): value is ScheduledQuery => {
	try {
		const sq = <ScheduledQuery>value;
		return (
			isScheduledTaskBase(sq) &&
			sq.type === 'query' &&
			isString(sq.query) &&
			(isNumber(sq.searchSince.secondsAgo) || isBoolean(sq.searchSince.lastRun))
		);
	} catch {
		return false;
	}
}
Example #13
Source File: is-scheduled-script.ts    From js-client with MIT License 6 votes vote down vote up
isScheduledScript = (value: any): value is ScheduledScript => {
	try {
		const ss = <ScheduledScript>value;
		return (
			isScheduledTaskBase(ss) &&
			ss.type === 'script' &&
			isString(ss.script) &&
			isBoolean(ss.isDebugging) &&
			(isString(ss.debugOutput) || isNull(ss.debugOutput))
		);
	} catch {
		return false;
	}
}
Example #14
Source File: is-scheduled-task-base.ts    From js-client with MIT License 6 votes vote down vote up
isScheduledTaskBase = (value: any): value is ScheduledTaskBase => {
	try {
		const ss = <ScheduledTaskBase>value;
		return (
			isNumericID(ss.id) &&
			isUUID(ss.globalID) &&
			isNumericID(ss.userID) &&
			ss.groupIDs.every(isNumericID) &&
			isString(ss.name) &&
			isString(ss.description) &&
			ss.labels.every(isString) &&
			isBoolean(ss.oneShot) &&
			isBoolean(ss.isDisabled) &&
			isDate(ss.lastUpdateDate) &&
			isDate(ss.lastRunDate) &&
			isNull(ss.lastSearchIDs) &&
			isNumber(ss.lastRunDuration) &&
			(isString(ss.lastError) || isNull(ss.lastError)) &&
			isString(ss.schedule) &&
			(isString(ss.timezone) || isNull(ss.timezone))
		);
	} catch {
		return false;
	}
}
Example #15
Source File: data-explorer-entry.ts    From js-client with MIT License 6 votes vote down vote up
isDataExplorerElement = (v: unknown): v is DataExplorerElement => {
	try {
		const element = v as DataExplorerElement;
		const childrenOK = isArray(element.children) && element.children.every(isDataExplorerElement);
		return (
			childrenOK &&
			isString(element.module) &&
			isString(element.name) &&
			isString(element.path) &&
			(isString(element.arguments) || isNull(element.arguments)) &&
			(isString(element.value) || isNumber(element.value) || isBoolean(element.value) || isNull(element.value)) &&
			isArray(element.filters) &&
			element.filters.every(isElementFilterOperation)
		);
	} catch {
		return false;
	}
}
Example #16
Source File: is-search-module.ts    From js-client with MIT License 6 votes vote down vote up
isSearchModule = (value: any): value is SearchModule => {
	try {
		const m = <SearchModule>value;
		return (
			isString(m.name) &&
			isString(m.description) &&
			m.examples.every(isString) &&
			isBoolean(m.frontendOnly) &&
			isBoolean(m.collapsing) &&
			isBoolean(m.sorting)
		);
	} catch {
		return false;
	}
}
Example #17
Source File: is-system-settings.ts    From js-client with MIT License 6 votes vote down vote up
isSystemSettings = (value: any): value is SystemSettings => {
	try {
		const s = <SystemSettings>value;
		return (
			isString(s.mapTileURL) &&
			isBoolean(s.disableMapTileProxy) &&
			isBoolean(s.webServerIsDistributed) &&
			isInteger(s.maxFileSize) &&
			isInteger(s.maxResourceSize)
		);
	} catch {
		return false;
	}
}
Example #18
Source File: is-actionable.ts    From js-client with MIT License 6 votes vote down vote up
isActionable = (value: any): value is Actionable => {
	try {
		const a = <Actionable>value;
		return (
			isUUID(a.globalID) &&
			isUUID(a.id) &&
			isNumericID(a.userID) &&
			a.groupIDs.every(isNumericID) &&
			isString(a.name) &&
			(isString(a.description) || isNull(a.description)) &&
			(isString(a.menuLabel) || isNull(a.menuLabel)) &&
			a.labels.every(isString) &&
			isBoolean(a.isGlobal) &&
			isBoolean(a.isDisabled) &&
			isDate(a.lastUpdateDate) &&
			a.triggers.every(isActionableTrigger) &&
			a.actions.every(isActionableAction)
		);
	} catch {
		return false;
	}
}
Example #19
Source File: update-one-user.ts    From js-client with MIT License 6 votes vote down vote up
makeUpdateOneUser = (context: APIContext) => {
	const updateOneUserLockedState = makeUpdateOneUserLockedState(context);
	const updateOneUserInformation = makeUpdateOneUserInformation(context);
	const updateOneUserRole = makeUpdateOneUserRole(context);
	const updateOneUserPassword = makeUpdateOneUserPassword(context);
	const getOneUser = makeGetOneUser(context);
	const updateOneUserSearchGroup = makeUpdateOneUserSearchGroup(context);

	return async (data: UpdatableUser): Promise<User> => {
		try {
			const promises: Array<Promise<void>> = [];

			// Update .locked
			if (isBoolean(data.locked)) promises.push(updateOneUserLockedState(data.id, data.locked));

			// Update .role
			if (isValidUserRole(data.role)) promises.push(updateOneUserRole(data.id, data.role));

			// Update .username .name or .email
			if ([data.username, data.name, data.email].some(negate(isUndefined)))
				promises.push(updateOneUserInformation(data));

			// Update password
			if (isString(data.password)) promises.push(updateOneUserPassword(data.id, data.password, data.currentPassword));

			// Search group ID
			if (isNumericID(data.searchGroupID) || isNull(data.searchGroupID))
				promises.push(updateOneUserSearchGroup(data.id, data.searchGroupID));

			await Promise.all(promises);
			return await getOneUser(data.id);
		} catch (err) {
			if (err instanceof Error) throw err;
			throw Error('Unknown error');
		}
	};
}
Example #20
Source File: is-template.ts    From js-client with MIT License 6 votes vote down vote up
isTemplateVariable = (value: unknown): value is TemplateVariable => {
	try {
		const v = <TemplateVariable>value;
		return (
			isString(v.label) &&
			isString(v.name) &&
			(isString(v.description) || isUndefined(v.description)) &&
			(isBoolean(v.required) || isUndefined(v.required)) &&
			(isString(v.defaultValue) || isUndefined(v.defaultValue)) &&
			(isString(v.previewValue) || isUndefined(v.previewValue) || isNull(v.previewValue))
		);
	} catch {
		return false;
	}
}
Example #21
Source File: is-valid-user.ts    From js-client with MIT License 6 votes vote down vote up
isValidUser = (value: any): value is User => {
	try {
		const u = <User>value;
		return (
			isNumericID(u.id) &&
			u.groupIDs.every(isNumericID) &&
			isString(u.username) &&
			isString(u.name) &&
			isString(u.email) &&
			isValidUserRole(u.role) &&
			isBoolean(u.locked) &&
			(isString(u.searchGroupID) || isNull(u.searchGroupID)) &&
			(isDate(u.lastActivityDate) || isNull(u.lastActivityDate))
		);
	} catch {
		return false;
	}
}
Example #22
Source File: in-params-drawer.tsx    From erda-ui with GNU Affero General Public License v3.0 6 votes vote down vote up
formDataToYmlData = (data: IFormData[]): PIPELINE.IPipelineInParams[] => {
  return compact(
    map(data, (item) => {
      const { key, required, defaultValue, component, labelTip } = item;
      const type = get(find(typeMapping, { component }), 'type') || component;
      let _default = defaultValue as any;
      if (type === 'int') _default = isNaN(+_default) ? undefined : +_default;
      if (type === 'boolean') _default = isBoolean(_default) ? _default : _default === 'true';
      if (!key) return null;
      const dataItem = {
        name: key,
        required,
        default: _default || undefined,
        type,
        desc: labelTip,
      };
      const res = {};
      map(dataItem, (val, k) => {
        if (val !== undefined) {
          res[k] = val;
        }
      });
      return res as PIPELINE.IPipelineInParams;
    }),
  );
}
Example #23
Source File: table-facet.ts    From S2 with MIT License 6 votes vote down vote up
protected updateRowResizeArea() {
    const { foregroundGroup, options } = this.spreadsheet;
    const resize = get(options, 'interaction.resize');

    const shouldDrawResize = isBoolean(resize)
      ? resize
      : (resize as ResizeActiveOptions)?.rowCellVertical;
    if (!shouldDrawResize) {
      return;
    }

    const rowResizeGroup = foregroundGroup.findById(KEY_GROUP_ROW_RESIZE_AREA);
    const rowResizeFrozenGroup = foregroundGroup.findById(
      KEY_GROUP_FROZEN_ROW_RESIZE_AREA,
    );
    if (rowResizeGroup) {
      rowResizeGroup.set('children', []);
    }
    if (rowResizeFrozenGroup) {
      rowResizeFrozenGroup.set('children', []);
    }
    const allCells: TableRowCell[] = getAllChildCells(
      this.panelGroup.getChildren() as IElement[],
      TableRowCell,
    );

    allCells.forEach((cell) => {
      cell.drawResizeArea();
    });
  }
Example #24
Source File: file_export.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
function formatRow(row: any[], addEndRowDelimiter = true) {
  let text = '';
  for (let i = 0; i < row.length; i += 1) {
    if (isBoolean(row[i]) || isNumber(row[i]) || isNullOrUndefined(row[i])) {
      text += row[i];
    } else {
      text += `${QUOTE}${csvEscaped(htmlUnescaped(htmlDecoded(row[i])))}${QUOTE}`;
    }

    if (i < row.length - 1) {
      text += END_COLUMN;
    }
  }
  return addEndRowDelimiter ? text + END_ROW : text;
}
Example #25
Source File: processDataFrame.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/**
 * Given a value this will guess the best column type
 *
 * TODO: better Date/Time support!  Look for standard date strings?
 */
export function guessFieldTypeFromValue(v: any): FieldType {
  if (isNumber(v)) {
    return FieldType.number;
  }

  if (isString(v)) {
    if (NUMBER.test(v)) {
      return FieldType.number;
    }

    if (v === 'true' || v === 'TRUE' || v === 'True' || v === 'false' || v === 'FALSE' || v === 'False') {
      return FieldType.boolean;
    }

    return FieldType.string;
  }

  if (isBoolean(v)) {
    return FieldType.boolean;
  }

  if (v instanceof Date || isDateTime(v)) {
    return FieldType.time;
  }

  return FieldType.other;
}
Example #26
Source File: helpers.ts    From querybook with Apache License 2.0 6 votes vote down vote up
export function detectVariableType(value: any): TSupportedTypes {
    if (isBoolean(value)) {
        return 'boolean';
    }
    if (isNumber(value)) {
        return 'number';
    }
    return 'string';
}
Example #27
Source File: index.tsx    From Search-Next with GNU General Public License v3.0 5 votes vote down vote up
getVersionInfo = () => {
  const account = localStorage.getItem('account');
  const message = getAuthDataByKey(account ?? '', 'message');
  const latestVersion = getAuthDataByKey(account ?? '', 'latestVersion');

  latest().then((res) => {
    if (res.data) {
      const { tag_name = '' } = res.data;
      if (latestVersion === tag_name) return;
      updateAuthDataByKey(account ?? '', 'latestVersion', tag_name);

      if (isBoolean(message?.update)) {
        message?.update && updateModal(res.data, account || '', message);
      } else {
        const {
          update: privUpdate,
          remind = 'popup',
          interval = 0,
          lastTime,
        } = message?.update || {};

        if (!privUpdate) {
          return;
        }
        let remindUpdate;

        switch (remind) {
          case 'message':
            remindUpdate = updateToast;
            break;
          case 'notification':
            remindUpdate = updateNotification;
            break;
          case 'popup':
          default:
            remindUpdate = updateModal;
            break;
        }
        if (!interval) {
          remindUpdate(res.data, account || '', message);
        } else {
          const now = dayjs();
          const last = dayjs(lastTime);
          if (last.isBefore(now.subtract(interval, 'day'))) {
            remindUpdate(res.data, account || '', message);
          }
        }
      }
    }
  });
}
Example #28
Source File: layout-hooks.ts    From S2 with MIT License 5 votes vote down vote up
layoutHierarchy = (
  facetCfg: SpreadSheetFacetCfg,
  parentNode: Node,
  currentNode: Node,
  hierarchy: Hierarchy,
): boolean => {
  let expandCurrentNode = true;
  const addNode = (node: Node, insetIndex = -1, hierarchyIndex = -1) => {
    if (insetIndex === -1) {
      // add in parent
      parentNode.children.push(node);
      hierarchy.pushNode(node);
    } else {
      parentNode.children.splice(insetIndex, 0, node);
      hierarchy.pushNode(node, hierarchyIndex);
    }
  };
  if (facetCfg.layoutHierarchy) {
    const facetLayoutHierarchy = facetCfg.layoutHierarchy(
      facetCfg.spreadsheet,
      currentNode,
    );
    if (facetLayoutHierarchy) {
      const deleteNode = !isBoolean(facetLayoutHierarchy?.delete)
        ? false
        : facetLayoutHierarchy?.delete;
      expandCurrentNode = !deleteNode;
      const { push: pushNodes, unshift: unshiftNodes } = facetLayoutHierarchy;
      let currentIndex = parentNode.children.length;
      let hierarchyIndex = hierarchy.getNodes().length;
      if (!isEmpty(unshiftNodes)) {
        each(unshiftNodes, (v) => {
          addNode(v);
        });
        currentIndex = parentNode.children.length;
        hierarchyIndex = hierarchy.getNodes().length;
      }
      if (!isEmpty(pushNodes)) {
        each(pushNodes, (v) => {
          addNode(v);
        });
      }
      if (!deleteNode) {
        addNode(currentNode, currentIndex, hierarchyIndex);
      }
    } else {
      addNode(currentNode);
    }
  } else {
    addNode(currentNode);
  }
  return expandCurrentNode;
}
Example #29
Source File: helpers.ts    From leda with MIT License 5 votes vote down vote up
getOpen = (isOpen?: [boolean | undefined, boolean| undefined] | boolean): [boolean | undefined, boolean| undefined] => {
  if (isBoolean(isOpen)) return [isOpen, isOpen];

  if (Array.isArray(isOpen)) return isOpen;

  return [undefined, undefined];
}