nodeJS 内置对象

// 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))   //深度严格比较

  

posted on 2024-05-23 19:50  龍瀧尨呀  阅读(4)  评论(0编辑  收藏  举报

导航