nodeJS 内置对象
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | // const { log } = require("console"); // const { argv } = require("process"); // log(__dirname) // setImmediate(()=>{ // log(__filename) // }) // const buffer = Buffer.from('a1','utf-8') // log(buffer) // log('process.cwd'+ process.cwd()) // log('argv '+process.argv) // log('platform '+process.platform) // log('platform '+process.kill(10563)) // import { log } from "console"; // import {a} from "./myModule.js" // const data = require("./myModule.js"); // const path = require('path'); // console.log(path.basename('d/index.html','.html'));//匹配最后的名字 // console.log(path.sep); //操作系统路径分割符 // console.log(path.delimiter); //操作系统环境变量分割符 // console.log(path.dirname('a/a/index.html')); //文件夹路径 // console.log(path.join('c','a/a/index.html')); //拼接 // console.log(path.normalize('azz/a/../inddex.html')); //格式化 // console.log(path.relative('a/b/c/d','a/b/e/f')); //后面相对于前面的相对路径 // console.log(path.resolve('a/a.js')); //绝对路径 相对命令行的 动态 // console.log(path.resolve(__dirname,'./a.js')) //相对于当前模块的绝对路径 这样更准确 const URL = require( "url" ); const url = new URL.URL( "https://nodejs.org:80/a/b/c?t=3&u=5#abc" ); // const url = URL.parse('https://nodejs.org:80/a/b/c?t=3&u=5#abc'); // console.log(url); // console.log(new URL.URLSearchParams('?t=3&u=5#abc').get('t')) // console.log(url.searchParams.has('t')); // console.log(url.searchParams.get('t')); // console.log( // URL.format({ // protocol: "https:", // slashes: true, // auth: null, // host: "nodejs.org:80", // port: "80", // hostname: "nodejs.org", // hash: "#abc", // search: "?t=3&u=5", // query: "t=3&u=5", // pathname: "/a/b/c", // path: "/a/b/c?t=3&u=5", // href: "https://nodejs.org:80/a/b/c?t=3&u=5#abc", // }) // ); const util = require( 'util' ) async function delay(duration = 1000) { return new Promise(resolve=>{ setTimeout(() => { resolve(duration) }, duration); }) } // delay().then(d=>{ // console.log(d) // }) //将delay包装为回调函数 const delayCallback = util.callbackify(delay) // delayCallback(500,(err,dd)=>{ // console.log(dd) // }) function delayCallBack(duration = 1000,callback){ setTimeout(() => { callback( null ,duration) }, duration); } const delayAsync = util.promisify(delayCallBack); //回调函数包装为promise // delayAsync(500).then(d=>console.log) // promise then 调用 (async ()=>{ const r = await delayAsync(1000) console.log(r) })() const obj1 = { a:1, b:{ c:3, d:{ e:5 } } } const obj2 = { a:1, b:{ c:3, d:{ e:5 } } } console.log(util.isDeepStrictEqual(obj1,obj2)) //深度严格比较 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!