comparison xml/en/docs/njs/reference.xml @ 2267:c30048802769

Added links to njs reference from njs Compatibility.
author Yaroslav Zhuravlev <yar@nginx.com>
date Mon, 29 Oct 2018 21:34:03 +0300
parents 9644ecb67081
children cd1b26111884
comparison
equal deleted inserted replaced
2266:3fba786a8bd7 2267:c30048802769
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
8 8
9 <article name="Reference" 9 <article name="Reference"
10 link="/en/docs/njs/reference.html" 10 link="/en/docs/njs/reference.html"
11 lang="en" 11 lang="en"
12 rev="11"> 12 rev="13">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 <link doc="index.xml">njs</link> provides objects, methods and properties 17 <link doc="index.xml">njs</link> provides objects, methods and properties
522 >> String.bytesFrom('YnVmZmVy', 'base64') 522 >> String.bytesFrom('YnVmZmVy', 'base64')
523 'buffer' 523 'buffer'
524 </example> 524 </example>
525 </tag-desc> 525 </tag-desc>
526 526
527 <tag-name><literal>String.fromCodePoint(<value>codePoint1</value>[, ...[, 527 <tag-name id="string_fromcodepoint"><literal>String.fromCodePoint(<value>codePoint1</value>[, ...[,
528 <value>codePoint2</value>]])</literal></tag-name> 528 <value>codePoint2</value>]])</literal></tag-name>
529 <tag-desc> 529 <tag-desc>
530 Returns a string from one or more Unicode code points. 530 Returns a string from one or more Unicode code points.
531 <example> 531 <example>
532 >> String.fromCodePoint(97, 98, 99, 100) 532 >> String.fromCodePoint(97, 98, 99, 100)
533 'abcd' 533 'abcd'
534 </example> 534 </example>
535 </tag-desc> 535 </tag-desc>
536 536
537 <tag-name><literal>String.prototype.concat(<value>string1</value>[, ..., 537 <tag-name id="string_concat"><literal>String.prototype.concat(<value>string1</value>[, ...,
538 <value>stringN</value>])</literal></tag-name> 538 <value>stringN</value>])</literal></tag-name>
539 <tag-desc> 539 <tag-desc>
540 Returns a string that contains the concatenation of specified 540 Returns a string that contains the concatenation of specified
541 <literal>strings</literal>. 541 <literal>strings</literal>.
542 <example> 542 <example>
543 >> "a".concat("b", "c") 543 >> "a".concat("b", "c")
544 'abc' 544 'abc'
545 </example> 545 </example>
546 </tag-desc> 546 </tag-desc>
547 547
548 <tag-name><literal>String.prototype.endsWith(<value>searchString</value>[, 548 <tag-name id="string_endswith"><literal>String.prototype.endsWith(<value>searchString</value>[,
549 <value>length</value>])</literal></tag-name> 549 <value>length</value>])</literal></tag-name>
550 <tag-desc> 550 <tag-desc>
551 Returns <literal>true</literal> if a string ends with the characters 551 Returns <literal>true</literal> if a string ends with the characters
552 of a specified string, otherwise <literal>false</literal>. 552 of a specified string, otherwise <literal>false</literal>.
553 The optional <literal>length</literal> parameter is the the length of string. 553 The optional <literal>length</literal> parameter is the the length of string.
558 >> 'abca'.endsWith('abc') 558 >> 'abca'.endsWith('abc')
559 false 559 false
560 </example> 560 </example>
561 </tag-desc> 561 </tag-desc>
562 562
563 <tag-name><literal>String.prototype.fromBytes(<value>start</value>[, 563 <tag-name id="string_frombytes"><literal>String.prototype.fromBytes(<value>start</value>[,
564 <value>end</value>])</literal></tag-name> 564 <value>end</value>])</literal></tag-name>
565 <tag-desc> 565 <tag-desc>
566 (njs specific) Returns a new Unicode string from a byte string 566 (njs specific) Returns a new Unicode string from a byte string
567 where each byte is replaced with a corresponding Unicode code point. 567 where each byte is replaced with a corresponding Unicode code point.
568 </tag-desc> 568 </tag-desc>
569 569
570 <tag-name><literal>String.prototype.fromUTF8(<value>start</value>[, 570 <tag-name id="string_fromutf8"><literal>String.prototype.fromUTF8(<value>start</value>[,
571 <value>end</value>])</literal></tag-name> 571 <value>end</value>])</literal></tag-name>
572 <tag-desc> 572 <tag-desc>
573 (njs specific) Converts a byte string containing a valid UTF8 string 573 (njs specific) Converts a byte string containing a valid UTF8 string
574 into a Unicode string, 574 into a Unicode string,
575 otherwise <literal>null</literal> is returned. 575 otherwise <literal>null</literal> is returned.
576 </tag-desc> 576 </tag-desc>
577 577
578 <tag-name><literal>String.prototype.includes(<value>searchString</value>[, 578 <tag-name id="string_includes"><literal>String.prototype.includes(<value>searchString</value>[,
579 <value>position</value>]))</literal></tag-name> 579 <value>position</value>]))</literal></tag-name>
580 <tag-desc> 580 <tag-desc>
581 Returns <literal>true</literal> if a string is found within another string, 581 Returns <literal>true</literal> if a string is found within another string,
582 otherwise <literal>false</literal>. 582 otherwise <literal>false</literal>.
583 The optional <literal>position</literal> parameter is the position 583 The optional <literal>position</literal> parameter is the position
587 >> 'abc'.includes('bc') 587 >> 'abc'.includes('bc')
588 true 588 true
589 </example> 589 </example>
590 </tag-desc> 590 </tag-desc>
591 591
592 <tag-name><literal>String.prototype.indexOf(<value>searchString</value>[, 592 <tag-name id="string_indexof"><literal>String.prototype.indexOf(<value>searchString</value>[,
593 <value>fromIndex</value>])</literal></tag-name> 593 <value>fromIndex</value>])</literal></tag-name>
594 <tag-desc> 594 <tag-desc>
595 Returns the position of the first occurrence 595 Returns the position of the first occurrence
596 of the <literal>searchString</literal> 596 of the <literal>searchString</literal>
597 The search is started at <literal>fromIndex</literal>. 597 The search is started at <literal>fromIndex</literal>.
607 >> 'abcdef'.indexOf('de', 2) 607 >> 'abcdef'.indexOf('de', 2)
608 3 608 3
609 </example> 609 </example>
610 </tag-desc> 610 </tag-desc>
611 611
612 <tag-name><literal>String.prototype.lastIndexOf(<value>searchString</value>[, 612 <tag-name id="string_lastindexof"><literal>String.prototype.lastIndexOf(<value>searchString</value>[,
613 <value>fromIndex</value>])</literal></tag-name> 613 <value>fromIndex</value>])</literal></tag-name>
614 <tag-desc> 614 <tag-desc>
615 Returns the position of the last occurrence 615 Returns the position of the last occurrence
616 of the <literal>searchString</literal>, 616 of the <literal>searchString</literal>,
617 searching backwards from <literal>fromIndex</literal>. 617 searching backwards from <literal>fromIndex</literal>.
631 >> 'αβγδ'.length 631 >> 'αβγδ'.length
632 4 632 4
633 </example> 633 </example>
634 </tag-desc> 634 </tag-desc>
635 635
636 <tag-name><literal>String.prototype.match([<value>regexp</value>])</literal></tag-name> 636 <tag-name id="string_match"><literal>String.prototype.match([<value>regexp</value>])</literal></tag-name>
637 <tag-desc> 637 <tag-desc>
638 Matches a string against a <literal>regexp</literal>. 638 Matches a string against a <literal>regexp</literal>.
639 <example> 639 <example>
640 >> 'nginx'.match( /ng/i ) 640 >> 'nginx'.match( /ng/i )
641 'ng' 641 'ng'
664 >> '1234'.padStart(8, 'abcd') 664 >> '1234'.padStart(8, 'abcd')
665 'abcd1234' 665 'abcd1234'
666 </example> 666 </example>
667 </tag-desc> 667 </tag-desc>
668 668
669 <tag-name><literal>String.prototype.repeat(<value>number</value>)</literal></tag-name> 669 <tag-name id="string_repeat"><literal>String.prototype.repeat(<value>number</value>)</literal></tag-name>
670 <tag-desc> 670 <tag-desc>
671 Returns a string 671 Returns a string
672 with the specified <literal>number</literal> of copies of the string. 672 with the specified <literal>number</literal> of copies of the string.
673 <example> 673 <example>
674 >> 'abc'.repeat(3) 674 >> 'abc'.repeat(3)
675 'abcabcabc' 675 'abcabcabc'
676 </example> 676 </example>
677 </tag-desc> 677 </tag-desc>
678 678
679 <tag-name><literal>String.prototype.replace([<value>regexp</value>|<value>string</value>[, 679 <tag-name id="string_replace"><literal>String.prototype.replace([<value>regexp</value>|<value>string</value>[,
680 <value>string</value>|<value>function</value>]])</literal></tag-name> 680 <value>string</value>|<value>function</value>]])</literal></tag-name>
681 <tag-desc> 681 <tag-desc>
682 Returns a new string with matches of a pattern 682 Returns a new string with matches of a pattern
683 (<literal>string</literal> or a <literal>regexp</literal>) 683 (<literal>string</literal> or a <literal>regexp</literal>)
684 replaced by a <literal>string</literal> or a <literal>function</literal>. 684 replaced by a <literal>string</literal> or a <literal>function</literal>.
686 >> 'abcdefgh'.replace('d', 1) 686 >> 'abcdefgh'.replace('d', 1)
687 'abc1efgh' 687 'abc1efgh'
688 </example> 688 </example>
689 </tag-desc> 689 </tag-desc>
690 690
691 <tag-name><literal>String.prototype.search([<value>regexp</value>])</literal></tag-name> 691 <tag-name id="string_search"><literal>String.prototype.search([<value>regexp</value>])</literal></tag-name>
692 <tag-desc> 692 <tag-desc>
693 Searches for a string using a <literal>regexp</literal> 693 Searches for a string using a <literal>regexp</literal>
694 <example> 694 <example>
695 >> 'abcdefgh'.search('def') 695 >> 'abcdefgh'.search('def')
696 3 696 3
697 </example> 697 </example>
698 </tag-desc> 698 </tag-desc>
699 699
700 <tag-name><literal>String.prototype.slice(<value>start</value>[, 700 <tag-name id="string_slice"><literal>String.prototype.slice(<value>start</value>[,
701 <value>end</value>])</literal></tag-name> 701 <value>end</value>])</literal></tag-name>
702 <tag-desc> 702 <tag-desc>
703 Returns a new string containing a part of an 703 Returns a new string containing a part of an
704 original string between <literal>start</literal> 704 original string between <literal>start</literal>
705 and <literal>end</literal> or 705 and <literal>end</literal> or
708 >> 'abcdefghijklmno'.slice(NaN, 5) 708 >> 'abcdefghijklmno'.slice(NaN, 5)
709 'abcde' 709 'abcde'
710 </example> 710 </example>
711 </tag-desc> 711 </tag-desc>
712 712
713 <tag-name><literal>String.prototype.startsWith(<value>searchString</value>[, 713 <tag-name id="string_startswith"><literal>String.prototype.startsWith(<value>searchString</value>[,
714 <value>position</value>])</literal></tag-name> 714 <value>position</value>])</literal></tag-name>
715 <tag-desc> 715 <tag-desc>
716 Returns <literal>true</literal> if a string begins with the characters 716 Returns <literal>true</literal> if a string begins with the characters
717 of a specified string, otherwise <literal>false</literal>. 717 of a specified string, otherwise <literal>false</literal>.
718 The optional <literal>position</literal> parameter is the position 718 The optional <literal>position</literal> parameter is the position
724 > 'aabc'.startsWith('abc') 724 > 'aabc'.startsWith('abc')
725 false 725 false
726 </example> 726 </example>
727 </tag-desc> 727 </tag-desc>
728 728
729 <tag-name><literal>String.prototype.substr(<value>start</value>[, 729 <tag-name id="string_substr"><literal>String.prototype.substr(<value>start</value>[,
730 <value>length</value>])</literal></tag-name> 730 <value>length</value>])</literal></tag-name>
731 <tag-desc> 731 <tag-desc>
732 Returns the part of the string of the specified <literal>length</literal> 732 Returns the part of the string of the specified <literal>length</literal>
733 from <literal>start</literal> 733 from <literal>start</literal>
734 or from <literal>start</literal> to the end of the string. 734 or from <literal>start</literal> to the end of the string.
736 >> 'abcdefghijklmno'.substr(3, 5) 736 >> 'abcdefghijklmno'.substr(3, 5)
737 'defgh' 737 'defgh'
738 </example> 738 </example>
739 </tag-desc> 739 </tag-desc>
740 740
741 <tag-name><literal>String.prototype.substring(<value>start</value>[, 741 <tag-name id="string_substring"><literal>String.prototype.substring(<value>start</value>[,
742 <value>end</value>])</literal></tag-name> 742 <value>end</value>])</literal></tag-name>
743 <tag-desc> 743 <tag-desc>
744 Returns the part of the string between 744 Returns the part of the string between
745 <literal>start</literal> and <literal>end</literal> or 745 <literal>start</literal> and <literal>end</literal> or
746 from <literal>start</literal> to the end of the string. 746 from <literal>start</literal> to the end of the string.
756 (njs specific) Serializes a Unicode string to a byte string. 756 (njs specific) Serializes a Unicode string to a byte string.
757 Returns <literal>null</literal> if a character larger than 255 is 757 Returns <literal>null</literal> if a character larger than 255 is
758 found in the string. 758 found in the string.
759 </tag-desc> 759 </tag-desc>
760 760
761 <tag-name><literal>String.prototype.toLowerCase()</literal></tag-name> 761 <tag-name id="string_tolowercase"><literal>String.prototype.toLowerCase()</literal></tag-name>
762 <tag-desc> 762 <tag-desc>
763 Converts a string to lower case. 763 Converts a string to lower case.
764 The method supports only simple Unicode folding. 764 The method supports only simple Unicode folding.
765 <example> 765 <example>
766 >> 'ΑΒΓΔ'.toLowerCase() 766 >> 'ΑΒΓΔ'.toLowerCase()
786 >> 'αβγδ'.toUTF8().toString('base64url') 786 >> 'αβγδ'.toUTF8().toString('base64url')
787 'zrHOss6zzrQ' 787 'zrHOss6zzrQ'
788 </example> 788 </example>
789 </tag-desc> 789 </tag-desc>
790 790
791 <tag-name><literal>String.prototype.toUpperCase()</literal></tag-name> 791 <tag-name id="string_touppercase"><literal>String.prototype.toUpperCase()</literal></tag-name>
792 <tag-desc> 792 <tag-desc>
793 Converts a string to upper case. 793 Converts a string to upper case.
794 The method supports only simple Unicode folding. 794 The method supports only simple Unicode folding.
795 <example> 795 <example>
796 >> 'αβγδ'.toUpperCase() 796 >> 'αβγδ'.toUpperCase()
809 >> 'αβγδ'.length 809 >> 'αβγδ'.length
810 4 810 4
811 </example> 811 </example>
812 </tag-desc> 812 </tag-desc>
813 813
814 <tag-name><literal>String.prototype.trim()</literal></tag-name> 814 <tag-name id="string_trim"><literal>String.prototype.trim()</literal></tag-name>
815 <tag-desc> 815 <tag-desc>
816 Removes whitespaces from both ends of a string. 816 Removes whitespaces from both ends of a string.
817 <example> 817 <example>
818 >> ' abc '.trim() 818 >> ' abc '.trim()
819 'abc' 819 'abc'
820 </example> 820 </example>
821 </tag-desc> 821 </tag-desc>
822 822
823 <tag-name><literal>String.prototype.split(([<value>string</value>|<value>regexp</value>[, 823 <tag-name id="string_split"><literal>String.prototype.split(([<value>string</value>|<value>regexp</value>[,
824 <value>limit</value>]]))</literal></tag-name> 824 <value>limit</value>]]))</literal></tag-name>
825 <tag-desc> 825 <tag-desc>
826 Returns match of a string against a <literal>regexp</literal>. 826 Returns match of a string against a <literal>regexp</literal>.
827 The optional <literal>limit</literal> parameter is an integer that specifies 827 The optional <literal>limit</literal> parameter is an integer that specifies
828 a limit on the number of splits to be found. 828 a limit on the number of splits to be found.
845 >> encodeURI('012αβγδ') 845 >> encodeURI('012αβγδ')
846 '012%CE%B1%CE%B2%CE%B3%CE%B4' 846 '012%CE%B1%CE%B2%CE%B3%CE%B4'
847 </example> 847 </example>
848 </tag-desc> 848 </tag-desc>
849 849
850 <tag-name><literal>encodeURIComponent(<value>encodedURIString</value>)</literal></tag-name> 850 <tag-name id="encodeuricomponent"><literal>encodeURIComponent(<value>encodedURIString</value>)</literal></tag-name>
851 <tag-desc> 851 <tag-desc>
852 Encodes a URI by replacing each instance of certain characters 852 Encodes a URI by replacing each instance of certain characters
853 by one, two, three, or four escape sequences 853 by one, two, three, or four escape sequences
854 representing the UTF-8 encoding of the character. 854 representing the UTF-8 encoding of the character.
855 <example> 855 <example>
856 >> encodeURIComponent('[@?=') 856 >> encodeURIComponent('[@?=')
857 '%5B%40%3F%3D' 857 '%5B%40%3F%3D'
858 </example> 858 </example>
859 </tag-desc> 859 </tag-desc>
860 860
861 <tag-name><literal>decodeURI(<value>encodedURI</value>)</literal></tag-name> 861 <tag-name id="decodeuri"><literal>decodeURI(<value>encodedURI</value>)</literal></tag-name>
862 <tag-desc> 862 <tag-desc>
863 Decodes a previously <link id="encodeuri">encoded</link> URI. 863 Decodes a previously <link id="encodeuri">encoded</link> URI.
864 <example> 864 <example>
865 >> decodeURI('012%CE%B1%CE%B2%CE%B3%CE%B4') 865 >> decodeURI('012%CE%B1%CE%B2%CE%B3%CE%B4')
866 '012αβγδ' 866 '012αβγδ'
867 </example> 867 </example>
868 </tag-desc> 868 </tag-desc>
869 869
870 <tag-name><literal>decodeURIComponent(<value>decodedURIString</value>)</literal></tag-name> 870 <tag-name id="decodeuricomponent"><literal>decodeURIComponent(<value>decodedURIString</value>)</literal></tag-name>
871 <tag-desc> 871 <tag-desc>
872 Decodes an encoded component of a previously encoded URI. 872 Decodes an encoded component of a previously encoded URI.
873 <example> 873 <example>
874 >> decodeURIComponent('%5B%40%3F%3D') 874 >> decodeURIComponent('%5B%40%3F%3D')
875 '[@?=' 875 '[@?='
959 </para> 959 </para>
960 960
961 <para> 961 <para>
962 <list type="tag"> 962 <list type="tag">
963 963
964 <tag-name><literal>crypto.createHash(<value>algorithm</value>)</literal></tag-name> 964 <tag-name id="crypto_createhash"><literal>crypto.createHash(<value>algorithm</value>)</literal></tag-name>
965 <tag-desc> 965 <tag-desc>
966 Creates and returns a <link id="crypto_hash">Hash</link> object 966 Creates and returns a <link id="crypto_hash">Hash</link> object
967 that can be used to generate hash digests 967 that can be used to generate hash digests
968 using the given <value>algorithm</value>. 968 using the given <value>algorithm</value>.
969 The algorighm can be 969 The algorighm can be
970 <literal>md5</literal>, 970 <literal>md5</literal>,
971 <literal>sha1</literal>, and 971 <literal>sha1</literal>, and
972 <literal>sha256</literal>. 972 <literal>sha256</literal>.
973 </tag-desc> 973 </tag-desc>
974 974
975 <tag-name><literal>crypto.createHmac(<value>algorithm</value>, 975 <tag-name id="crypto_createhmac"><literal>crypto.createHmac(<value>algorithm</value>,
976 <value>secret key</value>)</literal></tag-name> 976 <value>secret key</value>)</literal></tag-name>
977 <tag-desc> 977 <tag-desc>
978 Creates and returns an <link id="crypto_hmac">HMAC</link> object 978 Creates and returns an <link id="crypto_hmac">HMAC</link> object
979 that uses the given <value>algorithm</value> and <value>secret key</value>. 979 that uses the given <value>algorithm</value> and <value>secret key</value>.
980 The algorighm can be 980 The algorighm can be