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


TypeScript utils.isString函數代碼示例

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


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

示例1: setEasing

    /**
      * set animator's easing.
      * @param curverArray - The speed curve of an animation.
      * @return {Animator} An instance itself.
      * @example
  animator.({
      delay: 2,
      diretion: "alternate",
      duration: 2,
      fillMode: "forwards",
      iterationCount: 3,
      easing: Scene.easing.EASE,
  });
      */
    public setEasing(curveArray: string | number[] | EasingFunction): this {
        let easing: EasingFunction;

        if (isString(curveArray)) {
            if (curveArray in EASINGS) {
                easing = EASINGS[curveArray];
            } else {
                const obj = toPropertyObject(curveArray);

                if (isString(obj)) {
                    return this;
                } else {
                    if (obj.model === "cubic-bezier") {
                        curveArray = obj.value.map(v => parseFloat(v));
                        easing = bezier(curveArray[0], curveArray[1], curveArray[2], curveArray[3]);
                    } else if (obj.model === "steps") {
                        easing = steps(parseFloat(obj.value[0]), obj.value[1]);
                    } else {
                        return this;
                    }
                }
            }
        } else if (isArray(curveArray)) {
            easing = bezier(curveArray[0], curveArray[1], curveArray[2], curveArray[3]);
        } else {
            easing = curveArray;
        }
        const easingName = easing[EASING_NAME] || "linear";

        const state = this.state;

        state[EASING] = easing;
        state[EASING_NAME] = easingName;
        return this;
    }
開發者ID:daybrush,項目名稱:scenejs,代碼行數:49,代碼來源:Animator.ts

示例2: toPropertyObject

export function toPropertyObject(value: string | IObject<any> | any[]) {
  if (!isString(value)) {
    if (isArray(value)) {
      return arrayToPropertyObject(value, ",");
    }
    return value;
  }
  let values = splitComma(value);

  if (values.length > 1) {
    return arrayToPropertyObject(values.map(v => toPropertyObject(v)), ",");
  }
  values = splitSpace(value);
  if (values.length > 1) {
    return arrayToPropertyObject(values.map(v => toPropertyObject(v)), " ");
  }
  values = /^(['"])([^'"]*)(['"])$/g.exec(value);
  if (values && values[1] === values[3]) {
    // Quotes
    return new PropertyObject([toPropertyObject(values[2])], {
      prefix: values[1],
      suffix: values[1],
    });
  } else if (value.indexOf("(") !== -1) {
    // color
    return stringToBracketObject(value);
  } else if (value.charAt(0) === "#") {
    return stringToColorObject(value);
  }
  return value;
}
開發者ID:daybrush,項目名稱:scenejs,代碼行數:31,代碼來源:property.ts

示例3: set

    /**
      * set property
      * @param {...Number|String|PropertyObject} args - property names or values
      * @return {Frame} An instance itself
      * @example
  // one parameter
  frame.set({
      display: "none",
      transform: {
          translate: "10px, 10px",
          scale: "1",
      },
      filter: {
          brightness: "50%",
          grayscale: "100%"
      }
  });

  // two parameters
  frame.set("transform", {
      translate: "10px, 10px",
      scale: "1",
  });

  // three parameters
  frame.set("transform", "translate", "50px");
    */
    public set(...args: any[]) {
        const self = this;
        const length = args.length;
        const params = args.slice(0, -1);
        const value = args[length - 1];

        if (params[0] in ALIAS) {
            self._set(ALIAS[params[0]], value);
        } else if (length === 2 && isArray(params[0])) {
            self._set(params[0], value);
        } else if (isArray(value)) {
            self._set(params, value);
        } else if (isPropertyObject(value)) {
            if (isRole(params)) {
                self.set(...params, toObject(value));
            } else {
                self._set(params, value);
            }
        } else if (isObject(value)) {
            for (const name in value) {
                self.set(...params, name, value[name]);
            }
        } else if (isString(value)) {
            if (isRole(params, true)) {
                if (isFixed(params) || !isRole(params)) {
                    this._set(params, value);
                } else  {
                    const obj = toPropertyObject(value);

                    if (isObject(obj)) {
                        self.set(...params, obj);
                    }
                }
                return this;
            } else {
                const { styles, length: stylesLength } = splitStyle(value);

                for (const name in styles) {
                    self.set(...params, name, styles[name]);
                }
                if (stylesLength) {
                    return this;
                }
            }
            self._set(params, value);
        } else {
            self._set(params, value);
        }
        return self;
    }
開發者ID:daybrush,項目名稱:scenejs,代碼行數:77,代碼來源:Frame.ts

示例4: _set

    private _set(args: NameType[], value: any) {
        let properties = this.properties;
        const length = args.length;

        for (let i = 0; i < length - 1; ++i) {
            const name = args[i];

            !(name in properties) && (properties[name] = {});
            properties = properties[name];
        }
        if (!length) {
            return;
        }
        properties[args[length - 1]] = isString(value) ? toPropertyObject(value) : value;
    }
開發者ID:daybrush,項目名稱:scenejs,代碼行數:15,代碼來源:Frame.ts

示例5: getUnitTime

    public getUnitTime(time: string | number) {
        if (isString(time)) {
            const duration = this.getDuration() || 100;

            if (time === "from") {
                return 0;
            } else if (time === "to") {
                return duration;
            }
            const { unit, value } = splitUnit(time);

            if (unit === "%") {
                !this.getDuration() && (this.setDuration(duration));
                return toFixed(parseFloat(time) / 100 * duration);
            } else if (unit === ">") {
                return value + THRESHOLD;
            } else {
                return value;
            }
        } else {
            return toFixed(time);
        }
    }
開發者ID:daybrush,項目名稱:scenejs,代碼行數:23,代碼來源:Animator.ts

示例6: toCSSObject

    /**
      * Specifies an css object that coverted the frame.
      * @return {object} cssObject
      */
    public toCSSObject() {
        const properties = this.get();
        const cssObject: IObject<string> = {};

        for (const name in properties) {
            if (isRole([name], true)) {
                continue;
            }
            const value = properties[name];

            if (name === TIMING_FUNCTION) {
                cssObject[TIMING_FUNCTION.replace("animation", ANIMATION)] =
                    (isString(value) ? value : value[EASING_NAME]) || "initial";
                continue;
            }
            cssObject[name] = value;
        }
        const transform = toInnerProperties(properties[TRANSFORM_NAME]);
        const filter = toInnerProperties(properties.filter);

        TRANSFORM && transform && (cssObject[TRANSFORM] = transform);
        FILTER && filter && (cssObject[FILTER] = filter);
        return cssObject;
    }
開發者ID:daybrush,項目名稱:scenejs,代碼行數:28,代碼來源:Frame.ts


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