grunt.util 各色工具函数/库
发布时间:2023-05-15 14:10:43 所属栏目:教程 来源:
导读:各色工具函数/库,包括 Lo-Dash、Async 和 Hooker。
grunt.util.kindOf
返回给定值的"类型(kind)"。就像typeof,但是其返回的是内部的[Class](class/)值。可能返回的结果是"number"、"string"、"boolean"、"fu
grunt.util.kindOf
返回给定值的"类型(kind)"。就像typeof,但是其返回的是内部的[Class](class/)值。可能返回的结果是"number"、"string"、"boolean"、"fu
|
各色工具函数/库,包括 Lo-Dash、Async 和 Hooker。 grunt.util.kindOf 返回给定值的"类型(kind)"。就像typeof,但是其返回的是内部的[Class](class/)值。可能返回的结果是"number"、"string"、"boolean"、"function"、"regexp"、"array"、"date"、"error"、"null"、"undefined"和可以表示一切类型的 "object"。 grunt.util.kindOf(value) grunt.util.error 返回一个新的Error实例(也可以抛出)与相应的消息。如果指定的是Error对象而不是message,则返回对象。 另外,如果为 origError 参数指定的是Error对象,并且使用 --stack 选项运行Grunt,则输出原始的Error堆栈。 grunt.util.error(message [, origError]) grunt.util.lineFeed 将换行符转换为当前系统所采用的形式(Window上是\r\n,其他系统为\n)。 grunt.util.normalizelf 对于一个给定的字符串,将其所有换行符转换为当前系统所采用的形式,然后返回一个新的字符串。(Window上是\r\n,其他系统为\n) grunt.util.normalizelf(string) grunt.util.recurse 递归嵌套的对象和数组,为每个非对象值执行callbackFunction。如果continueFunction返回false, 给定的对象或值将会被跳过。 grunt.util.recurse(object, callbackFunction, continueFunction) grunt.util.repeat 返回被重复n次的字符串str。 grunt.util.repeat(n, str) grunt.util.pluralize 给定一个"a/b"形式的str,如果n为1,返回"a",否则返回"b"。如果不能使用'/',也可以指定一个自定义的分隔符。 grunt.util.pluralize(n, str, separator) grunt.util.spawn 生成一个子进程,并跟踪其stdout、stderr和退出码。此方法返回子进程的引用。当子进程退出时,doneFunction 函数被调用。 grunt.util.spawn(options, doneFunction) options 对象可以指定以下属性: var options = { // The command to execute. It should be in the system path. cmd: commandToExecute, // If specified, the same grunt bin that is currently running will be // spawned as the child command, instead of the "cmd" option. Defaults // to false. grunt: boolean, // An array of arguments to pass to the command. args: arrayOfArguments, // Additional options for the Node.js child_process spawn method. opts: nodeSpawnoptions, // If this value is set and an error occurs, it will be used as the value // and null will be passed as the error value. fallback: fallbackValue }; doneFunction 函数可以接收以下参数: function doneFunction(error, result, code) { // If the exit code was non-zero and a fallback wasn't specified, an Error // object, otherwise null. error // The result object is an object with the properties .stdout, .stderr, and // .code (exit code). result // When result is coerced to a string, the value is stdout if the exit code // was zero, the fallback if the exit code was non-zero and a fallback was // specified, or stderr if the exit code was non-zero and a fallback was // not specified. String(result) // The numeric exit code. code } grunt.util.toArray 对于传入的数组或类数组对象,返回一个数组。对于将arguments对象转换为数组是非常有用的。 (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
