forked from adispring/adispring.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
3320 lines (2944 loc) · 266 KB
/
index.html
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.ico">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon.ico">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon.ico">
<link rel="mask-icon" href="/logo.svg" color="#222">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<script id="hexo-configurations">
var NexT = window.NexT || {};
var CONFIG = {"hostname":"adispring.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
</script>
<meta name="description" content="[email protected]">
<meta property="og:type" content="website">
<meta property="og:title" content="wangzengdi's Blog">
<meta property="og:url" content="https://adispring.github.io/index.html">
<meta property="og:site_name" content="wangzengdi's Blog">
<meta property="og:description" content="[email protected]">
<meta property="og:locale" content="en">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="wangzengdi's Blog">
<meta name="twitter:description" content="[email protected]">
<link rel="canonical" href="https://adispring.github.io/">
<script id="page-configurations">
// https://hexo.io/docs/variables.html
CONFIG.page = {
sidebar: "",
isHome : true,
isPost : false,
lang : 'en'
};
</script>
<title>wangzengdi's Blog</title>
<noscript>
<style>
.use-motion .brand,
.use-motion .menu-item,
.sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-header { opacity: initial; }
.use-motion .site-title,
.use-motion .site-subtitle {
opacity: initial;
top: initial;
}
.use-motion .logo-line-before i { left: initial; }
.use-motion .logo-line-after i { right: initial; }
</style>
</noscript>
</head>
<body itemscope itemtype="http://schema.org/WebPage">
<div class="container use-motion">
<div class="headband"></div>
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-container">
<div class="site-nav-toggle">
<div class="toggle" aria-label="Toggle navigation bar">
<span class="toggle-line toggle-line-first"></span>
<span class="toggle-line toggle-line-middle"></span>
<span class="toggle-line toggle-line-last"></span>
</div>
</div>
<div class="site-meta">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<h1 class="site-title">wangzengdi's Blog</h1>
<span class="logo-line-after"><i></i></span>
</a>
<p class="site-subtitle" itemprop="description">Functional Programming</p>
</div>
<div class="site-nav-right">
<div class="toggle popup-trigger">
</div>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="main-menu menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a>
</li>
</ul>
</nav>
</div>
</header>
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
<span>0%</span>
</div>
<main class="main">
<div class="main-inner">
<div class="content-wrap">
<div class="content index posts-expand">
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://adispring.github.io/2021/04/30/Hexo-Workflow/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="wangzengdi">
<meta itemprop="description" content="[email protected]">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="wangzengdi's Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2021/04/30/Hexo-Workflow/" class="post-title-link" itemprop="url">Hexo Workflow</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2021-04-30 11:50:53" itemprop="dateCreated datePublished" datetime="2021-04-30T11:50:53+00:00">2021-04-30</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>Welcome to <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="noopener">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="noopener">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="noopener">GitHub</a>.</p>
<h2 id="quick-start">Quick Start</h2>
<h3 id="create-a-new-post">Create a new post</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="noopener">Writing</a></p>
<h3 id="run-server">Run server</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="noopener">Server</a></p>
<h3 id="generate-static-files">Generate static files</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="noopener">Generating</a></p>
<h3 id="deploy-to-remote-sites">Deploy to remote sites</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>
<h3 id="generate-amp-deploy-together">Generate & Deploy together</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo d -g</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="noopener">Deployment</a></p>
<h3 id="hexo-zi-dong-hua-bu-shu">Hexo 自动化部署</h3>
<ul>
<li>官方自动化部署文档 – Hexo + Travis: <a href="https://hexo.io/docs/github-pages.html" target="_blank" rel="noopener">https://hexo.io/docs/github-pages.html</a></li>
<li>空白页问题的解决方案:<a href="http://magicse7en.github.io/2016/03/27/travis-ci-auto-deploy-hexo-github/" target="_blank" rel="noopener">http://magicse7en.github.io/2016/03/27/travis-ci-auto-deploy-hexo-github/</a></li>
</ul>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://adispring.github.io/2021/04/30/npm-cli-advance-guide/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="wangzengdi">
<meta itemprop="description" content="[email protected]">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="wangzengdi's Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2021/04/30/npm-cli-advance-guide/" class="post-title-link" itemprop="url">npm 命令高级指南</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2021-04-30 11:23:56 / Modified: 11:50:53" itemprop="dateCreated datePublished" datetime="2021-04-30T11:23:56+00:00">2021-04-30</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>本文整理了一些 npm 不常用、但非常有用的命令。主要分为以下几大类:</p>
<ul>
<li>
<p>查看 npm 源(registry) 上的 npm 包信息</p>
<ul>
<li>npm view</li>
</ul>
</li>
<li>
<p>开发 npm 包时,用到的命令</p>
<ul>
<li>npm publish</li>
<li>npm pack</li>
<li>npm link & npm unlink</li>
<li>npm set-script</li>
</ul>
</li>
<li>
<p>查看已安装的 npm 包的本地信息</p>
<ul>
<li>npm ls</li>
<li>npm edit</li>
<li>npm explore</li>
<li>npm explain | npm why</li>
</ul>
</li>
<li>
<p>浏览器查看 npm 包信息</p>
<ul>
<li>npm docs</li>
<li>npm repo</li>
</ul>
</li>
<li>
<p>使用 npm 包开发其他项目时,用到的命令</p>
<ul>
<li>npm outdated</li>
<li>npm update</li>
</ul>
</li>
<li>
<p>其他 npm 命令</p>
<ul>
<li>npm config</li>
<li>npm bin</li>
<li>npm completion</li>
</ul>
</li>
</ul>
<h1 id="cha-kan-npm-yuan-registry-shang-de-npm-bao-xin-xi">查看 npm 源(registry) 上的 npm 包信息</h1>
<ul>
<li>npm view: 最为灵活、最为强大的 查看 npm 包信息的命令;</li>
</ul>
<p>由于 <code>npm view</code> 太灵活,所以需要单独一小节进行讲解。</p>
<h2 id="npm-view">npm view</h2>
<p>查看 npm 源上包的信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">npm view [<@scope>/]<name>[@<version>] [<field>[.<subfield>]...]</span><br><span class="line"></span><br><span class="line">aliases: info, show, v</span><br></pre></td></tr></table></figure>
<h3 id="cha-kan-bao-de-ji-ben-xin-xi">查看包的基本信息</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm view <pkg></span><br></pre></td></tr></table></figure>
<p>示例:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">› npm view ramda</span><br><span class="line"></span><br><span class="line">[email protected] | MIT | deps: none | versions: 52</span><br><span class="line">A practical functional library <span class="keyword">for</span> JavaScript programmers.</span><br><span class="line">https://ramdajs.com/</span><br><span class="line"></span><br><span class="line">dist</span><br><span class="line">.tarball: http://r.npm.sankuai.com/ramda/download/ramda-0.27.1.tgz</span><br><span class="line">.shasum: 66fc2df3ef873874ffc2da6aa8984658abacf5c9</span><br><span class="line"></span><br><span class="line">maintainers:</span><br><span class="line">- aromano <[email protected]></span><br><span class="line">- bradcomp <[email protected]></span><br><span class="line">- ...</span><br><span class="line"></span><br><span class="line">dist-tags:</span><br><span class="line">0.2.0: 0.2.0 es-rc: 0.24.1-es.rc3 latest: 0.27.1</span><br><span class="line"></span><br><span class="line">published 9 months ago by davidchambers <[email protected]></span><br></pre></td></tr></table></figure>
<h3 id="geng-jia-ling-huo-de-cha-kan-bao-de-xiang-xi-xin-xi">更加灵活的查看包的详细信息</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm view <pkg>@<version> <field>[.<subfield>]...</span><br></pre></td></tr></table></figure>
<h4 id="cha-kan-bao-de-yi-lai">查看包的依赖</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">› npm view http-server dependencies</span><br><span class="line">{</span><br><span class="line"> <span class="string">'basic-auth'</span>: <span class="string">'^1.0.3'</span>,</span><br><span class="line"> colors: <span class="string">'^1.4.0'</span>,</span><br><span class="line"> corser: <span class="string">'^2.0.1'</span>,</span><br><span class="line"> ecstatic: <span class="string">'^3.3.2'</span>,</span><br><span class="line"> <span class="string">'http-proxy'</span>: <span class="string">'^1.18.0'</span>,</span><br><span class="line"> minimist: <span class="string">'^1.2.5'</span>,</span><br><span class="line"> opener: <span class="string">'^1.5.1'</span>,</span><br><span class="line"> portfinder: <span class="string">'^1.0.25'</span>,</span><br><span class="line"> <span class="string">'secure-compare'</span>: <span class="string">'3.0.1'</span>,</span><br><span class="line"> union: <span class="string">'~0.5.0'</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="cha-kan-bao-de-zui-xin-ban-ben">查看包的最新版本</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">› npm view ramda version</span><br><span class="line">0.27.1</span><br></pre></td></tr></table></figure>
<h4 id="cha-kan-bao-fa-bu-de-suo-you-ban-ben">查看包发布的所有版本</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">› npm view ramda versions</span><br><span class="line">[</span><br><span class="line"> <span class="string">'0.1.0'</span>, <span class="string">'0.1.1'</span>, <span class="string">'0.1.2'</span>,</span><br><span class="line"> <span class="string">'0.1.4'</span>, <span class="string">'0.1.5'</span>, <span class="string">'0.2.0'</span>,</span><br><span class="line"> <span class="string">'0.2.1'</span>, <span class="string">'0.2.2'</span>, <span class="string">'0.2.3'</span>,</span><br><span class="line"> <span class="string">'0.2.4'</span>, <span class="string">'0.3.0'</span>, <span class="string">'0.4.0'</span>,</span><br><span class="line"> <span class="string">'0.4.1'</span>, <span class="string">'0.4.2'</span>, <span class="string">'0.4.3'</span>,</span><br><span class="line"> <span class="string">'0.5.0'</span>, <span class="string">'0.6.0'</span>, <span class="string">'0.7.0'</span>,</span><br><span class="line"> <span class="string">'0.7.1'</span>, <span class="string">'0.7.2'</span>, <span class="string">'0.8.0'</span>,</span><br><span class="line"> <span class="string">'0.9.0'</span>, <span class="string">'0.9.1'</span>, <span class="string">'0.10.0'</span>,</span><br><span class="line"> <span class="string">'0.11.0'</span>, <span class="string">'0.12.0'</span>, <span class="string">'0.13.0'</span>,</span><br><span class="line"> <span class="string">'0.14.0'</span>, <span class="string">'0.15.0'</span>, <span class="string">'0.15.1'</span>,</span><br><span class="line"> <span class="string">'0.16.0'</span>, <span class="string">'0.17.0'</span>, <span class="string">'0.17.1'</span>,</span><br><span class="line"> <span class="string">'0.18.0'</span>, <span class="string">'0.19.0'</span>, <span class="string">'0.19.1'</span>,</span><br><span class="line"> <span class="string">'0.20.0'</span>, <span class="string">'0.20.1'</span>, <span class="string">'0.21.0'</span>,</span><br><span class="line"> <span class="string">'0.22.0'</span>, <span class="string">'0.22.1'</span>, <span class="string">'0.23.0'</span>,</span><br><span class="line"> <span class="string">'0.24.0'</span>, <span class="string">'0.24.1-es.rc1'</span>, <span class="string">'0.24.1-es.rc2'</span>,</span><br><span class="line"> <span class="string">'0.24.1-es.rc3'</span>, <span class="string">'0.24.1'</span>, <span class="string">'0.25.0'</span>,</span><br><span class="line"> <span class="string">'0.26.0'</span>, <span class="string">'0.26.1'</span>, <span class="string">'0.27.0'</span>,</span><br><span class="line"> <span class="string">'0.27.1'</span></span><br><span class="line">]</span><br></pre></td></tr></table></figure>
<h4 id="cha-kan-zhi-ding-ban-ben-fan-wei-nei-de-bao-de-fa-bu-qing-kuang">查看指定版本范围内的包的发布情况</h4>
<p>查看自 0.25.0 以来,所有版本 ramda 包的信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm view ramda@<span class="string">'>=0.25.0'</span></span><br></pre></td></tr></table></figure>
<h4 id="cha-kan-npm-bao-guan-wang-di-zhi">查看 npm 包官网地址</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm view ramda homepage</span><br></pre></td></tr></table></figure>
<h4 id="cha-kan-npm-bao-cang-ku-di-zhi">查看 npm 包仓库地址</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm view ramda repository.url</span><br></pre></td></tr></table></figure>
<h4 id="tong-guo-shell-jiao-ben-zu-he-chu-ling-huo-de-cha-xun-ming-ling">通过 shell 脚本,组合出灵活的查询命令</h4>
<p>可以通过一些 Shell 脚本轻松查看有关依赖项的信息。例如,要查看有关ronn所依赖的opts版本的所有数据,如下所示:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm view opts@$(npm view ronn dependencies.opts)</span><br></pre></td></tr></table></figure>
<p>更多 <code>npm view</code> 的高级用法,可以查看 <a href="https://docs.npmjs.com/cli/v7/commands/npm-view" target="_blank" rel="noopener">npm view 官方文档</a></p>
<h1 id="kai-fa-npm-bao-she-ji-de-ming-ling">开发 npm 包涉及的命令</h1>
<ul>
<li>
<p>npm publish: 将包发布到 npm 源(registry) 上去;</p>
</li>
<li>
<p>npm pack: 打包;</p>
</li>
<li>
<p>npm link: 将当前 package 文件夹软链到全局 npm 环境中;</p>
</li>
<li>
<p>npm unlink: 断开全局软链时,其实就是 npm uninstall 的别名;</p>
</li>
<li>
<p>npm set-script: 在 package.json 的 <code>"scripts"</code> 字段中设置任务;</p>
</li>
</ul>
<h2 id="npm-publish-fa-bao">npm publish – 发包</h2>
<p>将包发布到 npm 源(registry) 上去。</p>
<h3 id="mo-ni-fa-bao">模拟发包</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm publish --dry-run</span><br></pre></td></tr></table></figure>
<p><code>npm publish --dry-run</code> 只是模拟发包,并不会真正发包。会将发包过程中的所有信息都打印出来,用作发包前进行信息确认。也可以使用 <code>npm pack --dry-run</code></p>
<h3 id="fa-bu-de-bao-zhong-bao-han-de-wen-jian">发布的包中包含的文件</h3>
<p>要查看软件包中将包含的内容,请运行 <code>npx npm-packlist</code>。默认情况下,所有文件都包括在内,但以下情况除外:</p>
<ul>
<li>
<p>始终包含与软件包安装和分发相关的某些文件。例如,<code>package.json</code>,<code>README.md</code>,<code>LICENSE</code> 等。</p>
</li>
<li>
<p>如果 <code>package.json</code> 中有一个 <code>"files"</code> 列表字段,则仅包含 <code>"files"</code> 指定的文件。(如果指定了目录,则将遵循相同的忽略规则,以递归方式遍历目录并包含目录的内容。)</p>
</li>
<li>
<p>如果存在 <code>.gitignore</code> 或 <code>.npmignore</code> 文件,则其中的被忽略文件以及所有子目录都将从软件包中排除。如果两个文件都存在,则将忽略 <code>.gitignore</code>,而仅使用 <code>.npmignore</code>。</p>
<p><code>.npmignore</code> 文件遵循与 <code>.gitignore</code> 文件相同的模式规则</p>
</li>
<li>
<p><strong>需要特别注意的是:如果文件匹配某些模式,则除非明确将其添加到 <code>package.json</code> 的 “files” 列表中,否则将永远不会将其包括在内,或者在 <code>.npmignore</code> 或 <code>.gitignore</code> 文件中使用 <code>!</code> ,来强制包含需要发布的文件</strong>。</p>
<p>例如,npm 发包,默认是会忽略 <code>.npmrc</code> 文件的,如果我确实需要将 <code>.npmrc</code> 包含进发布的包中,则需要使用在 <code>.npmignore</code> 或 <code>.gitignore</code> 中写入规则 <code>!.npmrc</code>,<code>!.npmrc</code> 表示强制包含 <code>.npmrc</code>。</p>
</li>
<li>
<p>符号链接永远不会包含在 npm 软件包中。</p>
</li>
</ul>
<p>有关已发布的软件包中包含的内容以及如何构建该软件包的详细信息,请查看 <a href="https://docs.npmjs.com/cli/v7/using-npm/developers" target="_blank" rel="noopener">开发者须知</a> 。</p>
<h2 id="npm-pack-da-bao">npm pack – 打包</h2>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm pack [[<@scope>/]<pkg>...] [--dry-run]</span><br></pre></td></tr></table></figure>
<p>一般会用到 <code>npm pack --dry-run</code> ,看一下即将发布的包的打包情况。加了 <code>--dry-run</code> 会后,命令不会真正的执行,只是把之间结果打印出来,以供调试使用。</p>
<h2 id="npm-link-amp-npm-unlink-ben-di-kai-fa">npm link & npm unlink - 本地开发</h2>
<p>本地调试利器</p>
<h3 id="npm-link">npm link</h3>
<p>将当前 package 文件夹软链到全局 npm 环境中。开发某个 npm 包时,本地调试非常好用。避免了在开发过程中不断重复发包的困扰。</p>
<p>npm link 分两步:</p>
<ul>
<li>
<p>软链当前的 package;</p>
</li>
<li>
<p>使用软链过的 package;</p>
</li>
</ul>
<p>如下所示:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~/projects/node-redis <span class="comment"># go into the package directory</span></span><br><span class="line">npm link <span class="comment"># creates global link</span></span><br><span class="line"><span class="built_in">cd</span> ~/projects/node-bloggy <span class="comment"># go into some other package directory.</span></span><br><span class="line">npm link redis <span class="comment"># link-install the package</span></span><br></pre></td></tr></table></figure>
<h3 id="npm-unlink">npm unlink</h3>
<p>当本地调试完成,想要断开全局软链时,运行下面命令:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm unlink <pkg> -g</span><br></pre></td></tr></table></figure>
<p><code>npm unlink</code> 会将 <pkg> 从全局的 npm 环境中移除(断开软链)。</pkg></p>
<p>注:<code>npm unlink</code> 其实是 <code>npm uninstall</code> 的别名,所以运行 <code>npm unlink <pkg> -g</code> 等价于 <code>npm uninstall <pkg> -g</code> 。</p>
<h3 id="npm-set-script">npm set-script</h3>
<p>在 package.json 的 <code>"scripts"</code> 字段中设置任务。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm <span class="built_in">set</span>-script [<script>] [<<span class="built_in">command</span>>]</span><br></pre></td></tr></table></figure>
<p>如果开发的 npm 包在安装时,需要动态修改项目中 <code>package.json</code> 文件的 <code>"scripts"</code> ,则可以使用该命令进行设置。</p>
<p>示例:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm <span class="built_in">set</span>-script start <span class="string">"http-server ."</span></span><br></pre></td></tr></table></figure>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"name"</span>: <span class="string">"my-project"</span>,</span><br><span class="line"> <span class="attr">"scripts"</span>: {</span><br><span class="line"> <span class="attr">"start"</span>: <span class="string">"http-server ."</span>,</span><br><span class="line"> <span class="attr">"test"</span>: <span class="string">"some existing value"</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>向 <code>"scripts"</code> 中添加 <code>"start"</code> 脚本。</p>
<h1 id="cha-kan-yi-an-zhuang-de-npm-bao-de-ben-di-xin-xi">查看已安装的 npm 包的本地信息</h1>
<ul>
<li>
<p>npm ls: 列出安装的 packages,或者指定 package 的依赖树;</p>
</li>
<li>
<p>npm edit: 使用默认的编辑器打开当前项目中指定的 npm 包;</p>
</li>
<li>
<p>npm explore: 进入指定的被安装的 npm 包的目录;</p>
</li>
<li>
<p>npm explain | npm why: 解释 packages 被安装的原因。主要是把指定包的依赖链条打印出来;</p>
</li>
</ul>
<h2 id="npm-ls">npm ls</h2>
<p>列出安装的 packages。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm ls [<pkg> -g]</span><br></pre></td></tr></table></figure>
<h3 id="da-yin-chu-dang-qian-xiang-mu-yi-an-zhuang-de-shou-ceng-packages">打印出当前项目已安装的首层 packages</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm ls</span><br></pre></td></tr></table></figure>
<h3 id="suo-you-de-yi-lai-yi-yi-lai-shu-de-xing-shi-da-yin-chu-lai">所有的依赖以依赖树的形式打印出来</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm ls -all</span><br></pre></td></tr></table></figure>
<p>当使用 <code>--all</code> 时,会将所有的依赖以依赖树的形式打印出来。</p>
<h3 id="da-yin-quan-ju-an-zhuang-de-packages">打印全局安装的 packages</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm ls -g</span><br></pre></td></tr></table></figure>
<h3 id="da-yin-zhi-ding-packages-de-an-zhuang-qing-kuang">打印指定 packages 的安装情况</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm ls name@version-range</span><br></pre></td></tr></table></figure>
<p><code>npm ls name@version-range</code> 可以以结构树的形式打印出指定 package 在项目中的安装情况。</p>
<p>也可以使用 <code>npm explain</code> 查看指定的 package 为什么会被安装,作用相当于 <code>npm ls</code> ,只不过展示的顺序是反向的。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm explain name</span><br></pre></td></tr></table></figure>
<h2 id="npm-edit">npm edit</h2>
<p>使用默认的编辑器,直接打开当前项目已经安装的 package 的文件夹。可以省去手动到 node_modules 中查找 package 的麻烦。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm edit <pkg></span><br></pre></td></tr></table></figure>
<p>例如:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm edit prettier</span><br></pre></td></tr></table></figure>
<p>会打开当前项目下的 <code>./node_modules/prettier</code> 目录。</p>
<h3 id="zhi-ding-mo-ren-de-bian-ji-qi-xiu-gai-code-editor-code-bian-liang">指定默认的编辑器,修改 <code>$EDITOR</code> 变量</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="built_in">export</span> EDITOR=<span class="string">"emacsclient -t"</span> >> ~/.zshrc</span><br></pre></td></tr></table></figure>
<h2 id="npm-explore">npm explore</h2>
<p>在命令行中,进入指定的被安装的 package 文件夹中。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm explore <pkg> [ -- <<span class="built_in">command</span>>]</span><br></pre></td></tr></table></figure>
<p>示例:</p>
<ol>
<li>进入当前项目中某 package 的目录</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 进入当前项目中安装的 prettier 目录</span><br><span class="line">npm explore prettier</span><br><span class="line"></span><br><span class="line"><span class="built_in">pwd</span></span><br><span class="line">// project/node_modules/prettier</span><br></pre></td></tr></table></figure>
<ol start="2">
<li>进入全局安装的某 package 目录</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 进入全局安装的 prettier 目录</span><br><span class="line">npm explore prettier -g</span><br><span class="line"></span><br><span class="line"><span class="built_in">pwd</span></span><br><span class="line">// /Users/wangzengdi/.nvm/versions/node/v14.15.4/lib/node_modules/prettier</span><br></pre></td></tr></table></figure>
<h2 id="npm-explain-npm-why">npm explain | npm why</h2>
<p>解释已安装的 packages,被安装的原因。</p>
<p>会将当前指定包的依赖关系打印出来(哪些包依赖的指定的包),可以用于解释为什么一个依赖为什么会被安装多次。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">npm explain <folder | specifier></span><br><span class="line"></span><br><span class="line"><span class="built_in">alias</span>: why</span><br></pre></td></tr></table></figure>
<p>例如:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">› npm explain eslint</span><br><span class="line"></span><br><span class="line">[email protected] dev</span><br><span class="line">node_modules/eslint</span><br><span class="line"> dev eslint@<span class="string">"^7.25.0"</span> from the root project</span><br><span class="line"> peer eslint@<span class="string">">= 4.12.1"</span> from [email protected]</span><br><span class="line"> node_modules/babel-eslint</span><br><span class="line"> dev babel-eslint@<span class="string">"^10.1.0"</span> from the root project</span><br><span class="line"> peer eslint@<span class="string">">=7.0.0"</span> from [email protected]</span><br><span class="line"> node_modules/eslint-config-prettier</span><br><span class="line"> dev eslint-config-prettier@<span class="string">"^8.3.0"</span> from the root project</span><br><span class="line"> ...</span><br></pre></td></tr></table></figure>
<p>表示当前项目在 devDependencies 中安装了 7.25.0 版本的 eslint,安装的位置为 <code>node_modules/eslint</code> 。后面的部分表明是哪些包的依赖,导致了 eslint 的安装。</p>
<h1 id="liu-lan-qi-cha-kan-npm-bao-xin-xi">浏览器查看 npm 包信息</h1>
<ul>
<li>
<p>npm docs | npm home: 在浏览器中打开 npm 包官网;</p>
</li>
<li>
<p>npm repo: 在浏览器中打开 npm 包仓库地址;</p>
</li>
</ul>
<h2 id="npm-docs">npm docs</h2>
<p>在浏览器中打开指定 npm 包的官方网站。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">npm docs [pakname]</span><br><span class="line"></span><br><span class="line">aliases: home</span><br></pre></td></tr></table></figure>
<p>例如</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 会打开 react 官网: https://reactjs.org/</span></span><br><span class="line">npm docs react</span><br><span class="line"></span><br><span class="line"><span class="comment"># 会打开 ramda 官网: https://ramdajs.com/</span></span><br><span class="line">npm docs ramda</span><br></pre></td></tr></table></figure>
<p>npm 的官方网站一般写在 package.json 中的 “homepage” 字段中。</p>
<h2 id="npm-repo">npm repo</h2>
<p>在浏览器中打开指定 npm 包的仓库(一般为 github 仓库)地址。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm repo [<pkgname> [<pkgname> ...]]</span><br></pre></td></tr></table></figure>
<p>例如</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 会打开 ramda github 仓库: https://github.com/ramda/ramda</span></span><br><span class="line">npm repo ramda</span><br></pre></td></tr></table></figure>
<h1 id="shi-yong-npm-bao-kai-fa-qi-ta-xiang-mu-shi-yong-dao-de-ming-ling">使用 npm 包开发其他项目时,用到的命令</h1>
<h2 id="npm-outdated-vs-npm-update">npm outdated vs npm update</h2>
<h3 id="npm-outdated">npm outdated</h3>
<p>查看项目中是否存在过期的 packages,或者指定的 packages 是否过期</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm outdated [<pkg> ...]</span><br></pre></td></tr></table></figure>
<p>举例</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">› npm outdated</span><br><span class="line">Package Current Wanted Latest Location Depended by</span><br><span class="line">semver-regex 3.1.2 3.1.2 4.0.0 node_modules/semver-regex fe.cli</span><br></pre></td></tr></table></figure>
<p>在某一项目下运行 <code>npm outdated</code>,便可以列出当前项目中所有已经过期的依赖。</p>
<p>如上所示,semver-regex 已经过期了,当前版本为 <code>3.1.2</code>,最新版本为 <code>4.0.0</code>。</p>
<p>想要查看 package 的详细信息,可以使用<code>npm view <pkg></code>,如查看 semver-regex: <code>npm view semver-regex</code>。</p>
<h4 id="cha-kan-quan-ju-yi-jing-guo-qi-de-package">查看全局已经过期的 package</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm outdated -g</span><br></pre></td></tr></table></figure>
<h3 id="npm-update-amp-npm-upgrade">npm update & npm upgrade</h3>
<p>更新 packages,npm update 会将 package 更新到当前已发布的 <strong>最新版本</strong>。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">npm update [-g] [<pkg>...]</span><br><span class="line"></span><br><span class="line">aliases: up, upgrade</span><br></pre></td></tr></table></figure>
<p>在上文中,我们已经介绍了使用 <code>npm outdated</code> 查看过期的 packages。本段将介绍如何使用 <code>npm update</code> 更新过期的 packages</p>
<h4 id="geng-xin-dang-qian-xiang-mu-zhong-suo-you-guo-qi-de-xiang-mu">更新当前项目中所有过期的项目</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm update</span><br></pre></td></tr></table></figure>
<h4 id="geng-xin-quan-ju-de-guo-qi-xiang-mu">更新全局的过期项目</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm update -g</span><br></pre></td></tr></table></figure>
<h4 id="geng-xin-zhi-ding-de-packages">更新指定的 packages</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm update pkg1 pkg2 ...</span><br></pre></td></tr></table></figure>
<h1 id="qi-ta-npm-ming-ling">其他 npm 命令</h1>
<ul>
<li>
<p>npm config: npm 配置</p>
</li>
<li>
<p>npm bin: 打印 npm 可执行命令 bin 的文件夹</p>
</li>
<li>
<p>npm completion: npm 补全脚本</p>
</li>
</ul>
<h2 id="npm-config">npm config</h2>
<p>npm 配置。用于列出当前 npm 环境的配置信息,或管理 npm 配置文件,一般是 .npmrc。</p>
<h3 id="lie-chu-dang-qian-de-npm-pei-zhi">列出当前的 npm 配置</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">npm config list</span><br><span class="line"></span><br><span class="line"><span class="comment"># 列出详细配置</span></span><br><span class="line">npm config list -l</span><br></pre></td></tr></table></figure>
<h2 id="npm-bin">npm bin</h2>
<p>打印 npm 可执行命令 bin 的文件夹</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm bin [-g | --global]</span><br></pre></td></tr></table></figure>
<h2 id="npm-completion">npm completion</h2>
<p>npm 补全命令脚本, 可以通过下列命令将命令补全脚本注入到 .bashrc 或 .zshrc 中,这样即可以在终端的任何地方使用。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm completion >> ~/.bashrc</span><br><span class="line">npm completion >> ~/.zshrc</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://adispring.github.io/2018/09/09/Hexo-Init/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="wangzengdi">
<meta itemprop="description" content="[email protected]">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="wangzengdi's Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2018/09/09/Hexo-Init/" class="post-title-link" itemprop="url">Hexo-Init</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2018-09-09 08:54:45" itemprop="dateCreated datePublished" datetime="2018-09-09T08:54:45+00:00">2018-09-09</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2021-04-30 11:50:53" itemprop="dateModified" datetime="2021-04-30T11:50:53+00:00">2021-04-30</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="hexo-cai-keng-zhi-nan">Hexo 踩坑指南</h2>
<h3 id="an-zhuang-zhu-ti">安装主题</h3>
<p>我选用 <a href="https://github.com/theme-next/hexo-theme-next" target="_blank" rel="noopener">next</a> 主题,简洁、素雅</p>
<p>安装指南:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> hexo</span><br><span class="line">$ git <span class="built_in">clone</span> https://github.com/theme-next/hexo-theme-next themes/next</span><br></pre></td></tr></table></figure>
<h3 id="favicon-pei-zhi">favicon 配置</h3>
<p>需要在 <code>themes/next/_config.yml</code> 中对 favicon 进行配置,我的配置如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Site Information Settings</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># To get or check favicons visit: https://realfavicongenerator.net</span></span><br><span class="line"><span class="comment"># Put your favicons into `hexo-site/source/` (recommend) or `hexo-site/themes/next/source/images/` directory.</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Default NexT favicons placed in `hexo-site/themes/next/source/images/` directory.</span></span><br><span class="line"><span class="comment"># And if you want to place your icons in `hexo-site/source/` root directory, you must remove `/images` prefix from pathes.</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># For example, you put your favicons into `hexo-site/source/images` directory.</span></span><br><span class="line"><span class="comment"># Then need to rename & redefine they on any other names, otherwise icons from Next will rewrite your custom icons in Hexo.</span></span><br><span class="line">favicon:</span><br><span class="line"> small: /favicon.ico</span><br><span class="line"> medium: /favicon.ico</span><br><span class="line"> apple_touch_icon: /images/apple-touch-icon-next.ico</span><br><span class="line"> safari_pinned_tab: /logo.svg</span><br><span class="line"> <span class="comment">#android_manifest: /images/manifest.json</span></span><br><span class="line"> <span class="comment">#ms_browserconfig: /images/browserconfig.xml</span></span><br></pre></td></tr></table></figure>
<h3 id="guan-yu-mao-dian-shi-xiao-wen-ti">关于锚点失效问题</h3>
<p>这是 <a href="https://github.com/hexojs/hexo-renderer-markdown-it" target="_blank" rel="noopener">hexo-renderer-markdown-it</a> 的一个 bug,但作者不想修复,认为是其他库的坑,所以我们要参考这个 <a href="https://github.com/hexojs/hexo-renderer-markdown-it/issues/40" target="_blank" rel="noopener">issue</a> ,手动到 node_modules 中修改该库,具体如下:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">'use strict'</span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span> (<span class="params">data, options</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> MdIt = <span class="built_in">require</span>(<span class="string">'markdown-it'</span>);</span><br><span class="line"> <span class="keyword">var</span> cfg = <span class="keyword">this</span>.config.markdown;</span><br><span class="line"> <span class="keyword">var</span> opt = (cfg) ? cfg : <span class="string">'default'</span>;</span><br><span class="line"> <span class="keyword">var</span> parser = (opt === <span class="string">'default'</span> || opt === <span class="string">'commonmark'</span> || opt === <span class="string">'zero'</span>) ?</span><br><span class="line"> <span class="keyword">new</span> MdIt(opt) :</span><br><span class="line"> <span class="keyword">new</span> MdIt(opt.render);</span><br><span class="line"></span><br><span class="line"> parser.use(<span class="built_in">require</span>(<span class="string">'markdown-it-named-headings'</span>)) <span class="comment">// 只需要添加这行代码</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (opt.plugins) {</span><br><span class="line"> parser = opt.plugins.reduce(<span class="function"><span class="keyword">function</span> (<span class="params">parser, pugs</span>) </span>{</span><br><span class="line"> <span class="keyword">return</span> parser.use(<span class="built_in">require</span>(pugs));</span><br><span class="line"> }, parser);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (opt.anchors) {</span><br><span class="line"> parser = parser.use(<span class="built_in">require</span>(<span class="string">'./anchors'</span>), opt.anchors);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> parser.render(data.text);</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<h3 id="zi-dong-hua-xiu-fu-yi-shang-wen-ti-de-jiao-ben">自动化修复以上问题的脚本</h3>
<p>写了一个自动化脚本,git pull 下我的博客备份后,自动安装、修复上述问题。</p>
<p>运行工程目录下的 <code>./hexo-init.sh</code>,内容如下:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"></span><br><span class="line">npm i hexo-cli -g</span><br><span class="line"></span><br><span class="line">yarn</span><br><span class="line"></span><br><span class="line">git <span class="built_in">clone</span> https://github.com/theme-next/hexo-theme-next themes/next</span><br><span class="line"></span><br><span class="line"><span class="comment"># 修复锚点不生效问题</span></span><br><span class="line">cp ./init_source/hexo-renderer-markdown-it/lib/renderer.js ./node_modules/hexo-renderer-markdown-it/lib/renderer.js</span><br><span class="line"></span><br><span class="line"><span class="comment"># 自动配置 favicon</span></span><br><span class="line">cp ./init_source/next/_config.yml ./themes/next/_config.yml</span><br></pre></td></tr></table></figure>
<h3 id="git-pull-xia-lai-de-hexo-gong-cheng-hexo-deploy-hou-jiang-zheng-ge-xiang-mu-du-push-shang-qu-liao">Git pull 下来的 Hexo 工程,hexo deploy 后将整个项目都 push 上去了</h3>
<p>每次 git pull 备份的工程后,需要清理一下 hexo 工程,具体方法如下:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> adispring.github.io</span><br><span class="line">rm -rf .git .deploy_git hexo clean</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
<link itemprop="mainEntityOfPage" href="https://adispring.github.io/2018/09/08/Fantasy-Land-Specification/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="wangzengdi">
<meta itemprop="description" content="[email protected]">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="wangzengdi's Blog">
</span>
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
<a href="/2018/09/08/Fantasy-Land-Specification/" class="post-title-link" itemprop="url">Fantasy-Land-Specification</a>
</h2>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2018-09-08 16:45:36" itemprop="dateCreated datePublished" datetime="2018-09-08T16:45:36+00:00">2018-09-08</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">Edited on</span>
<time title="Modified: 2021-04-30 11:50:53" itemprop="dateModified" datetime="2021-04-30T11:50:53+00:00">2021-04-30</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>(又名 “代数 JavaScript 规范”)</p>
<p><img src="./logo.png" alt="logo"></p>
<p>该项目规定了通用代数数据结构的互操作性:</p>
<ul>
<li><a href="#setoid">Setoid</a></li>
<li><a href="#ord">Ord</a></li>
<li><a href="#semigroupoid">Semigroupoid</a></li>
<li><a href="#category">Category</a></li>
<li><a href="#semigroup">Semigroup</a></li>
<li><a href="#monoid">Monoid</a></li>
<li><a href="#group">Group</a></li>
<li><a href="#filterable">Filterable</a></li>
<li><a href="#functor">Functor</a></li>
<li><a href="#contravariant">Contravariant</a></li>
<li><a href="#apply">Apply</a></li>
<li><a href="#applicative">Applicative</a></li>
<li><a href="#alt">Alt</a></li>
<li><a href="#plus">Plus</a></li>
<li><a href="#alternative">Alternative</a></li>
<li><a href="#foldable">Foldable</a></li>
<li><a href="#traversable">Traversable</a></li>
<li><a href="#chain">Chain</a></li>
<li><a href="#chainrec">ChainRec</a></li>
<li><a href="#monad">Monad</a></li>
<li><a href="#extend">Extend</a></li>
<li><a href="#comonad">Comonad</a></li>
<li><a href="#bifunctor">Bifunctor</a></li>
<li><a href="#profunctor">Profunctor</a></li>
</ul>
<p><img src="./dependencies.png" alt="dependencies"></p>
<h2 id="gai-lan">概览</h2>
<p>代数是遵循一定法则的、具有封闭性的,一系列值及一系列操作的集合。</p>
<p>每个 Fantasy Land 代数是一个单独的规范。一个代数可能依赖于其他必需实现的代数。</p>
<h2 id="zhu-yu">术语</h2>
<ol>
<li>
<p>“值”:任何 JavaScript 值,包括下面定义的结构的任何值。</p>
</li>
<li>
<p>“等价”:对给定值的等价性的恰当定义。这个定义应该保证两个值可以在其对应的抽象的程序中,能够安全地进行交换。例如:</p>
<ul>
<li>当两个列表对应的索引上的值都相等时,它们是等价的。</li>
<li>当两个普通的 JavaScript 对象所有键值对都相等时,它们(作为字典)是等价的。</li>
<li>当两个 promises 生成相等的值时,它们是等价的。</li>
<li>当两个函数给定相同的输入,产生相同的输出时,它们是等价的。</li>
</ul>
</li>
</ol>
<h2 id="lei-xing-qian-ming-fu-hao">类型签名符号</h2>
<p>本文档使用的类型签名符号如下所述:[^1]</p>
<ul>
<li><code>::</code> _<em>“是 xx 的成员”。</em>
<ul>
<li><code>e :: t</code> 读作:“表达式 <code>e</code> 是类型 <code>t</code> 的成员”。</li>
<li><code>true :: Boolean</code> - “<code>true</code> 是类型 <code>Boolean</code> 的成员”。</li>
<li><code>42 :: Integer, Number</code> - “<code>42</code> 是类型 <code>Integer</code> 和 <code>Number</code> 的成员”。</li>
</ul>
</li>
<li><em>新类型可以通过类型构造函数创建。</em>
<ul>
<li>类型构造函数可以接受零或多个类型参数。</li>
<li><code>Array</code> 是一个接受单个参数的类型构造函数。</li>
<li><code>Array String</code> 代表包含字符串的数组的类型。后面每个都是 <code>Array String</code> 类型的:<code>[]</code>,<code>['foo', 'bar', 'baz']</code>。</li>
<li><code>Array (Array String)</code> 代表包含字符串的数组的数组的类型。后面每个都是 <code>Array (Array String)</code> 类型的:<code>[]</code>,<code>[[], []]</code>, <code>[[], ['foo'], ['bar', 'baz']]</code>。</li>
</ul>
</li>
<li><em>小写字母代表类型变量。</em>
<ul>
<li>类型变量可以接受任何类型,除非受到类型约束的限制(参见下面的胖箭头)。</li>
<li><code>-></code> (箭头) <em>函数类型的构造函数</em></li>
<li><code>-></code> 是一个 <em>中缀</em> 构造函数,它接受两个类型参数,左侧参数为输入的类型,右侧参数为输出的类型。</li>
<li><code>-></code> 的输入类型可以通过一组类型创建出来,该函数接受零个或多个参数。其语法是:<code>(<input-types>) -> <output-type></code>,其中 <code><input-types></code> 包含零个或多个 “逗号-空格” (<code>, </code>)分开的类型表示,对于一元函数,圆括号也可以省略。</li>
<li><code>String -> Array String</code> 是一种接受一个 <code>String</code> 并返回一个 <code>Array String</code> 的函数的类型。</li>
<li><code>String -> Array String -> Array String</code> 是一种函数类型,它接受一个 <code>String</code> 并返回一个函数,返回的函数接受一个 <code>Array String</code> 并返回一个 <code>Array String</code>。</li>
<li><code>(String, Array String) -> Array String</code> 是一种函数类型,它接受一个 <code>String</code> 和 <code>Aray String</code> 作为参数,并返回一个 <code>Array String</code> 。</li>
<li><code>() -> Number</code> 是一种不带输入参数,返回 <code>Number</code> 的函数类型。</li>
</ul>
</li>
<li><code>~></code> (波浪形箭头) <em>方法类型的构造函数。</em>
<ul>
<li>当一个函数是一个对象(Object)的属性时,它被称为方法。所有方法都有一个隐含的参数类型 - 它是属性所在对象的类型。</li>
<li><code>a ~> a -> a</code> 是一种对象中方法的类型,它接受 <code>a</code> 类型的参数,并返回一个 <code>a</code> 类型的值。</li>
</ul>
</li>
<li><code>=></code> (胖箭头) 表示对类型变量的约束。
<ul>
<li>在 <code>a ~> a -> a</code>(参见上面的波浪形箭头)中,<code>a</code> 可以为任意类型。半群 <code>a => a ~> a -> a</code> 会添加一个约束,使得类型 <code>a</code> 现在必须满足该半群的类型类。满足类型类意味着,须合法地实现该类型类指定所有函数/方法。</li>
</ul>
</li>
</ul>
<p>例如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">traverse :: Applicative f, Traversable t => t a ~> (TypeRep f, a -> f b) -> f (t b)</span><br><span class="line">'------' '--------------------------' '-' '-------------------' '-----'</span><br><span class="line"> ' ' ' ' '</span><br><span class="line"> ' ' - type constraints ' ' - argument types ' - return type</span><br><span class="line"> ' '</span><br><span class="line"> '- method name ' - method target type</span><br></pre></td></tr></table></figure>
<p>[^1]: 更多相关信息,请参阅 Sanctuary 文档中的 <a href="https://sanctuary.js.org/#types" target="_blank" rel="noopener">Types</a> 部分。</p>
<h2 id="qian-zhui-fang-fa-ming">前缀方法名</h2>
<p>为了使数据类型与 Fantasy Land 兼容,其值必须具有某些属性。这些属性都以 <code>fantasy-land/</code> 为前缀。例如:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MyType#fantasy-land/map :: MyType a ~> (a -> b) -> MyType b</span></span><br><span class="line">MyType.prototype[<span class="string">'fantasy-land/map'</span>] = ...</span><br></pre></td></tr></table></figure>
<p>在本文中,不使用前缀的名称,只是为了减少干扰。</p>
<p>为了方便起见,你可以使用 <code>fantasy-land</code> 包:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> fl = <span class="built_in">require</span>(<span class="string">'fantasy-land'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">// ...</span></span><br><span class="line"></span><br><span class="line">MyType.prototype[fl.map] = ...</span><br><span class="line"></span><br><span class="line"><span class="comment">// ...</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> foo = bar[fl.map](<span class="function"><span class="params">x</span> =></span> x + <span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<h2 id="lei-xing-biao-shi-java-script-zhong-de-gou-zao-han-shu">类型表示 (JavaScript 中的构造函数?)</h2>
<p>某些行为是从类型成员的角度定义的。而另外一些行为不需要类型成员。因此,某些代数需要一个类型来提供值层面上的表示(具有某些属性)。例如,Identity 类型可以提供 <code>Id</code> 作为其类型表示:<code>Id :: TypeRep Identity</code>。</p>
<p>如果一个类型提供了类型表示,那么这个类型的每个成员都必须有一个指向该类型表示的 <code>contructor</code> 属性。</p>
<h2 id="dai-shu">代数</h2>
<h3 id="setoid">Setoid</h3>
<ol>
<li><code>a.equals(a) === true</code> (自反性)</li>
<li><code>a.equals(b) === b.equals(a)</code> (对称性)</li>
<li>如果 <code>a.equals(b)</code> 并且 <code>b.equals(a)</code>,则 <code>a.equals(c)</code> (传递性)</li>
</ol>
<h4 id="code-equals-code-fang-fa"><code>equals</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">equals</span> :: <span class="type">Setoid</span> a => a ~> a -> <span class="type">Boolean</span></span><br></pre></td></tr></table></figure>
<p>具有 Setoid 的值必须提供 <code>equals</code> 方法。<code>equals</code> 方法接受一个参数:</p>
<pre><code>a.equals(b)
</code></pre>
<ol>
<li><code>b</code> 必须是相同 Setoid 的值
<ol>
<li>如果 <code>b</code> 不是相同的 Setoid,则 <code>equals</code> 的行为未指定(建议返回 <code>false</code>)。</li>
<li><code>equals</code> 必须返回一个布尔值(<code>true</code> 或 <code>false</code>)。</li>
</ol>
</li>
</ol>
<h3 id="ord">Ord</h3>
<p>实现 Ord 规范的值还必须实现 <a href="#setoid">Setoid</a> 规范。</p>
<ol>
<li><code>a.lte(b)</code> 或 <code>b.lte(a)</code> (完全性)</li>
<li>如果 <code>a.lte(b)</code> 且 <code>b.lte(a)</code>,则 <code>a.equals(b)</code> (反对称性)</li>
<li>如果 <code>a.lte(b)</code> 且 <code>b.lte(c)</code>,则 <code>a.lte(c)</code> (传递性)</li>
</ol>
<h4 id="code-lte-code-fang-fa"><code>lte</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">lte</span> :: <span class="type">Ord</span> a => a ~> a -> <span class="type">Boolean</span></span><br></pre></td></tr></table></figure>
<p>具有 Ord 的值必须提供 <code>lte</code> 方法。<code>lte</code> 方法接受一个参数:</p>
<pre><code>`a.lte(b)`
</code></pre>
<ol>
<li><code>b</code> 必须是相同 Ord 的值。
<ol>
<li>如果 <code>b</code> 不是相同的 Ord,则 <code>lte</code> 的行为未指定 (建议返回 <code>false</code>)。</li>
</ol>
</li>
<li><code>lte</code> 必须返回布尔值(<code>true</code> 或 <code>false</code>)。</li>
</ol>
<h3 id="semigroupoid">Semigroupoid</h3>
<ol>
<li><code>a.compose(b).compose(c) === a.compose(b.compose(c))</code> (结合性)</li>
</ol>
<h4 id="code-compose-code-fang-fa"><code>compose</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">compose</span> :: <span class="type">Semigroupoid</span> c => c i j ~> c j k -> c i k</span><br></pre></td></tr></table></figure>
<p>具有 Semigoupoid 的值必须提供 <code>compose</code> 组合方法。<code>compose</code> 方法接受一个参数:</p>
<pre><code>a.compose(b)
</code></pre>
<ol>
<li><code>b</code> 必须返回相同 Semigroupoid 规范。
<ol>
<li>如果 <code>b</code> 不是相同的 Semigroupoid,compose 的行为未指定。</li>
</ol>
</li>
<li><code>compose</code> 必须返回相同 Semigroupoid 的值。</li>
</ol>
<h3 id="category">Category</h3>
<p>实现范畴规范的值还必须实现<a href="#semigroupoid">半群</a>规范。</p>
<ol>
<li><code>a.compose(C.id())</code> 等价于 <code>a</code> (右同一性)</li>
<li><code>C.id().compose(a)</code> 等价于 <code>a</code> (左同一性)</li>
</ol>
<h4 id="code-id-code-fang-fa"><code>id</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">id</span> :: <span class="type">Category</span> c => () -> c a a</span><br></pre></td></tr></table></figure>
<p>具有范畴的值必须在其<a href="#type-representatives">类型表示</a>中提供一个 <code>id</code> 函数。</p>
<pre><code>C.id()
</code></pre>
<p>给定值 <code>c</code>,可以通过 <code>contructor</code> 属性来访问其类型表示:</p>
<pre><code>c.constructgor.id()
</code></pre>
<ol>
<li><code>id</code> 必须返回相同范畴的值。</li>
</ol>
<h3 id="semigroup">Semigroup</h3>
<ol>
<li><code>a.concat(b).concat(c)</code> 等价于 <code>a.concat(b.concat(c))</code> (结合性)</li>
</ol>
<h4 id="code-concat-code-fang-fa"><code>concat</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">concat</span> :: <span class="type">Semigroup</span> a => a ~> a -> a</span><br></pre></td></tr></table></figure>
<p>具有 Semigroup 的值必须提供 <code>concat</code> 方法。<code>concat</code> 方法接受一个参数:</p>
<pre><code>s.concat(b)
</code></pre>
<ol>
<li><code>b</code> 必须是相同 Semigroup 的值
<ol>
<li>如果 <code>b</code> 不是相同的 Semigroup,则 <code>concat</code> 的行为未指定。</li>
</ol>
</li>
<li><code>concat</code> 必须返回相同 Semigroup 的值。</li>
</ol>
<h3 id="monoid">Monoid</h3>
<p>实现 Monoid 规范的值还必须实现 <a href="#semigroup">Semigroup</a> 规范</p>
<ol>
<li><code>m.concat(M.empty())</code> 等价于 <code>m</code> (右结合性)</li>
<li><code>M.empty().concat(m)</code> 等价于 <code>m</code> (左结合性)</li>
</ol>
<h4 id="code-empty-code-fang-fa"><code>empty</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">empty</span> :: <span class="type">Monoid</span> m => () -> m</span><br></pre></td></tr></table></figure>
<p>具有 Monoid 的值必须在其类型表示上提供 <code>empty</code> 方法:</p>
<pre><code>M.empty()
</code></pre>
<p>给定值<code> </code>m,可以通过 <code>constructor</code> 属性来访问其类型表示:</p>
<pre><code>m.constructor.empty()
</code></pre>
<ol>
<li><code>empty</code> 必须返回相同 Monoid 的值。</li>
</ol>
<h3 id="group">Group</h3>
<p>实现 Group 规范的值还必须实现 <a href="#monoid">Monoid</a> 规范。</p>
<ol>
<li><code>g.concat(g.invert())</code> 等价于 <code>g.constructor.empty()</code> (右反转性??)</li>
<li><code>g.invert().concat(g)</code> 等价于 <code>g.constructor.empty()</code> (左翻转性??)</li>
</ol>
<h4 id="code-invert-code-fang-fa"><code>invert</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">invert</span> :: <span class="type">Group</span> g => g ~> () -> g</span><br></pre></td></tr></table></figure>
<p>具有 Semigroup 的值必须提供 <code>invert</code> 方法。<code>invert</code> 方法接受零个参数:</p>
<pre><code>g.invert()
</code></pre>
<ol>
<li><code>invert</code> 必须返回相同 Group 的值。</li>
</ol>
<h3 id="filterable">Filterable</h3>
<ol>
<li><code>v.filter(x => p(x) && q(x))</code> 等价于 <code>v.filter(p).filter(q)</code> (分配性)</li>
<li><code>v.filter(x => true)</code> 等价于 <code>v</code> (同一性)</li>
<li><code>v.filter(x -> false)</code> 等价于 <code>w.filter(x => false)</code>,如果 <code>v</code> 和 <code>w</code> 具有相同的 Filterable 值 (湮灭??)</li>
</ol>
<h4 id="code-filter-code-fang-fa"><code>filter</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">filter</span> :: <span class="type">Filterable</span> f => f a ~> (a -> <span class="type">Boolean</span>) -> f a</span><br></pre></td></tr></table></figure>
<p>具有 Filterable 的值必须提供 <code>filter</code> 方法。<code>filter</code> 方法接受一个参数:</p>
<pre><code>v.filter(p)
</code></pre>
<ol>
<li>
<p><code>p</code> 必须是一个函数。</p>
<ol>
<li>如果 <code>p</code> 不是函数,则 <code>filter</code> 的行为未指定。</li>
<li><code>p</code> 必须返回 <code>ture</code> 或 <code>false</code>。如果返回任何其它值,<code>filter</code> 的行为未指定。</li>
</ol>
</li>
<li>
<p><code>filter</code> 必须返回相同 Filterable 的值。</p>
</li>
</ol>
<h3 id="functor">Functor</h3>
<ol>
<li><code>u.map(a => a)</code> 等价于 <code>u</code> (同一性)</li>
<li><code>u.map(x => f(g(x)))</code> 等价于 <code>u.map(g).map(f)</code> (组合性)</li>
</ol>
<h4 id="code-map-code-fang-fa"><code>map</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">map</span> :: <span class="type">Functor</span> f => f a ~> (a -> b) -> f b</span><br></pre></td></tr></table></figure>
<p>具有 Functor 的值必须提供 <code>map</code> 方法。<code>map</code> 方法接受一个参数:</p>
<pre><code>u.map(f)
</code></pre>
<ol>
<li>
<p><code>f</code> 必须是一个函数,</p>
<ol>
<li>如果 <code>f</code> 不是函数,则 <code>map</code> 的行为未指定。</li>
<li><code>f</code> 可以返回任何值。</li>
<li><code>f</code> 返回值的任何部分都不应该被检查(??)。</li>
</ol>
</li>
<li>
<p><code>map</code> 必须返回相同 Functor 的值。</p>
</li>
</ol>
<h3 id="contravariant">Contravariant</h3>
<ol>
<li><code>u.contramap(a => a)</code> 等价于 <code>u</code> (同一性)</li>
<li><code>u.contramap(x => f(g(x)))</code> 等价于 <code>u.contramap(f).contramap(g)</code> (组合性)</li>
</ol>
<h4 id="code-contramap-code-fang-fa"><code>contramap</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">contramap</span> :: <span class="type">Contravariant</span> f => f a ~> (b -> a) -> f b</span><br></pre></td></tr></table></figure>
<p>具有 Contravariant 的值必须提供 <code>contramap</code> 方法。<code>contramap</code> 方法接受一个参数:</p>
<pre><code>u.contramap(f)
</code></pre>
<ol>
<li><code>f</code> 必须是一个函数,
<ol>
<li>如果 <code>f</code> 不是函数,则 <code>contramap</code> 的行为未指定。</li>
<li><code>f</code> 可以返回任何值。</li>
<li><code>f</code> 返回值的任何部分都不应该被检查(??)。</li>
</ol>
</li>
<li><code>contramap</code> 必须返回相同 Contravariant 的值。</li>
</ol>
<h3 id="apply">Apply</h3>
<p>实现 Apply 规范的值还必须实现 <a href="#functor">Functor</a> 规范。</p>
<ol>
<li><code>v.ap(u.ap(a.map(f => g => x => f(g(x)))))</code> 等价于 <code>v.ap(u).ap(a)</code> (组合型),推导过程??</li>
</ol>
<h4 id="code-ap-code-fang-fa"><code>ap</code> 方法</h4>
<figure class="highlight hs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">ap</span> :: <span class="type">Apply</span> f => f a ~> f (a -> b) -> f b</span><br></pre></td></tr></table></figure>
<p>具有 Apply 的值必须提供 <code>ap</code> 方法。<code>ap</code> 方法接受一个参数:</p>
<pre><code>a.ap(b)
</code></pre>
<ol>
<li><code>b</code> 必须是一个函数的 Apply
<ol>
<li>如果 <code>b</code> 不代表函数,则 <code>ap</code> 的行为未指定。</li>
<li><code>b</code> 必须与 a 具有相同的 Apply。</li>
</ol>
</li>
<li><code>a</code> 可以是任意值的 Apply。(??)</li>
<li><code>ap</code> 必须能将 Apply <code>b</code> 内的函数应用于 Apply <code>a</code> 的值上