当前位置: 首页>>代码示例>>Golang>>正文


Golang Value.IsNumber方法代码示例

本文整理汇总了Golang中github.com/robertkrimen/otto.Value.IsNumber方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.IsNumber方法的具体用法?Golang Value.IsNumber怎么用?Golang Value.IsNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/robertkrimen/otto.Value的用法示例。


在下文中一共展示了Value.IsNumber方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: formatOneLine

func formatOneLine(v otto.Value, limit int, seen map[otto.Value]bool) (string, error) {
	if limit == 0 {
		return "...", nil
	}

	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
		return v.String(), nil
	case v.IsString():
		return fmt.Sprintf("%q", v.String()), nil
	case v.IsFunction():
		n, err := v.Object().Get("name")
		if err != nil {
			return "", err
		}
		if n.IsUndefined() {
			return "function", nil
		}
		return fmt.Sprintf("function %s", n.String()), nil
	case v.IsObject():
		switch v.Class() {
		case "Array":
			return formatArrayOneLine(v, limit, seen)
		default:
			return formatObjectOneLine(v, limit, seen)
		}
	default:
		return "", fmt.Errorf("couldn't format type %s", v.Class())
	}
}
开发者ID:deoxxa,项目名称:ottoext,代码行数:30,代码来源:print.go

示例2: ConsiderValue

func (es *ExpressionStats) ConsiderValue(val otto.Value) {
	// increment the count
	es.Count += 1

	if val.IsNumber() {
		f, err := val.ToFloat()
		if err != nil {
			log.Printf("Error converting number to float %v", err)
		} else {
			// update the sum
			es.Sum += f

			// if this is smaller than anything we've seen so far update the min
			if f < es.Min {
				es.Min = f
			}

			// if this is larger than anything we've seen so far update the max
			if f > es.Max {
				es.Max = f
			}

			// update the average (perhaps wasteful, could be done once at the end
			// but i'd have to walk the whole tree again, for now will do update it each time
			es.Avg = es.Sum / float64(es.Count) // we incremented es.count in this function, can not divide by 0
		}
	}
}
开发者ID:mschoch,项目名称:tuq,代码行数:28,代码来源:otto_grouper.go

示例3: inspect

func inspect(v otto.Value, width, indent int) string {
	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsString(), v.IsUndefined(), v.IsNaN():
		return fmt.Sprintf("%s%q", strings.Repeat("  ", indent), v.String())
	default:
		return ""
	}
}
开发者ID:deoxxa,项目名称:ottoext,代码行数:8,代码来源:repl.go

示例4: ottoToGo

// Converts an Otto value to a Go value. Handles all JSON-compatible types.
func ottoToGo(value otto.Value) (interface{}, error) {
	if value.IsBoolean() {
		return value.ToBoolean()
	} else if value.IsNull() || value.IsUndefined() {
		return nil, nil
	} else if value.IsNumber() {
		return value.ToFloat()
	} else if value.IsString() {
		return value.ToString()
	} else {
		switch value.Class() {
		case "Array":
			return ottoToGoArray(value.Object())
		}
	}
	return nil, fmt.Errorf("Unsupported Otto value: %v", value)
}
开发者ID:steveyen,项目名称:walrus,代码行数:18,代码来源:js_map_fn.go

示例5: convertToPrimitive

func convertToPrimitive(v otto.Value) interface{} {
	if v.IsBoolean() {
		v_b, err := v.ToBoolean()
		if err != nil {
			log.Printf("Error converting to boolean")
		}
		return v_b
	} else if v.IsNumber() {
		v_f, err := v.ToFloat()
		if err != nil {
			log.Printf("Error converting to float")
		}
		return v_f
	} else {
		v_s, err := v.ToString()
		if err != nil {
			log.Printf("Error converting to boolean")
		}
		return v_s
	}
	return nil
}
开发者ID:mschoch,项目名称:tuq,代码行数:22,代码来源:otto_util.go

示例6: printValue

func (ctx ppctx) printValue(v otto.Value, level int, inArray bool) {
	switch {
	case v.IsObject():
		ctx.printObject(v.Object(), level, inArray)
	case v.IsNull():
		specialColor.Print("null")
	case v.IsUndefined():
		specialColor.Print("undefined")
	case v.IsString():
		s, _ := v.ToString()
		stringColor.Printf("%q", s)
	case v.IsBoolean():
		b, _ := v.ToBoolean()
		specialColor.Printf("%t", b)
	case v.IsNaN():
		numberColor.Printf("NaN")
	case v.IsNumber():
		s, _ := v.ToString()
		numberColor.Printf("%s", s)
	default:
		fmt.Printf("<unprintable>")
	}
}
开发者ID:Xiaoyang-Zhu,项目名称:go-ethereum,代码行数:23,代码来源:pretty.go

示例7: formatIndent

func formatIndent(v otto.Value, width, indent, limit, level, additional int, seen map[otto.Value]bool) (string, error) {
	if limit == 0 {
		return "...", nil
	}

	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
		return v.String(), nil
	case v.IsString():
		return fmt.Sprintf("%q", v.String()), nil
	case v.IsFunction():
		n, err := v.Object().Get("name")
		if err != nil {
			return "", err
		}
		if n.IsUndefined() {
			return "function", nil
		}
		return fmt.Sprintf("function %s", n.String()), nil
	case v.IsObject():
		if d, err := formatOneLine(v, limit, seen); err != nil {
			return "", err
		} else if level*indent+additional+len(d) <= width {
			return d, nil
		}

		switch v.Class() {
		case "Array":
			return formatArray(v, width, indent, limit, level, seen)
		default:
			return formatObject(v, width, indent, limit, level, seen)
		}
	default:
		return "", fmt.Errorf("couldn't format type %s", v.Class())
	}
}
开发者ID:deoxxa,项目名称:ottoext,代码行数:36,代码来源:print.go


注:本文中的github.com/robertkrimen/otto.Value.IsNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。