Modern Full-Stack Development



Download 5,64 Mb.
Pdf ko'rish
bet36/107
Sana06.08.2021
Hajmi5,64 Mb.
#140576
1   ...   32   33   34   35   36   37   38   39   ...   107
Bog'liq
Modern Full-Stack Development Using TypeScript, React, Node

 Path  (path)
You’ll notice that in several modules discussed thus far, you need to reference file and 
directory paths. Node provides some additional functions for working with them housed 
in the Path module.
For example, the path.basename() method returns the last portion of a path:
path.basename("/my/path/index.htm"); // "index.html"
By contrast, if you want just the path portion:
path.dirname("/my/path/index.htm"); // "/some/path"
And if you just want the extension:
path.extname("/my/path/index.htm"); // ".htm"
Finally, the path.parse() method is handy for, in a way, doing in one call what all of 
those do, plus a bit more:
path.parse("/home/users/mydata/accounts.dat");
This will return you an object in the form:
{ root : "/", dir : "/home/users/mydata",
  base : "accounts.dat", ext : ".dat", name : "accounts" }
If you need to know the platform-specific path delimiter (; for windows and : for 
∗nix 
systems), then you can get the value from the path.delimiter property.
Then there is the path.join() method which joins path segments into a final form 
that uses the platform-specific separator automatically (this example is on a Windows 
system):
path.join("/my", "path", "index.htm"); // "my\path\index.htm"
Because it is common to have to build paths dynamically in code, and because that 
process can result in munged string easily, Node offers a helpful method to deal with 
such issues in the path.normalize() method:
path.normalize("C:////tmp\\/\\/dat.md") // "C:\\temp\\dat.md"
Chapter 2   a Few More words: advanCed node and npM


36
Here, assume that some logic produced the string passed to path.normalize(), and 
that logic has to take a lot of things into account, so it can wind up with some sequences 
as you see that need to be reduced down to platform-specific and valid sequences. That’s 
what path.normalize() can do for you.

Download 5,64 Mb.

Do'stlaringiz bilan baham:
1   ...   32   33   34   35   36   37   38   39   ...   107




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish