Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop-uniapp
commit
f2118d5c8a
53
App.vue
53
App.vue
|
@ -5,9 +5,16 @@
|
|||
*/
|
||||
import { mapMutations } from "vuex";
|
||||
import APPUpdate from "@/plugins/APPUpdate";
|
||||
import { getClipboardData } from "@/js_sdk/h5-copy/h5-copy.js";
|
||||
import config from "@/config/config";
|
||||
// 悬浮球
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
config,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(["login"]),
|
||||
},
|
||||
|
@ -21,6 +28,13 @@ export default {
|
|||
// #endif
|
||||
},
|
||||
|
||||
onShow() {
|
||||
// #ifndef H5
|
||||
|
||||
this.getClipboard();
|
||||
// #endif
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 开屏广告
|
||||
launch() {
|
||||
|
@ -59,16 +73,49 @@ export default {
|
|||
});
|
||||
}
|
||||
},
|
||||
// 获取h5跳转app的链接并跳转
|
||||
|
||||
/**
|
||||
* 获取粘贴板数据
|
||||
*/
|
||||
async getClipboard() {
|
||||
let res = await getClipboardData();
|
||||
/**
|
||||
* 解析粘贴板数据
|
||||
*/
|
||||
if (res.indexOf(config.shareLink) != -1) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "检测到一个分享链接是否跳转?",
|
||||
confirmText: "跳转",
|
||||
success: function (callback) {
|
||||
if (callback.confirm) {
|
||||
const path = res.split(config.shareLink)[1];
|
||||
if (path.indexOf("tabbar") != -1) {
|
||||
uni.switchTab({
|
||||
url: path,
|
||||
});
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: path,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* h5中打开app获取跳转app的链接并跳转
|
||||
*/
|
||||
checkArguments() {
|
||||
// #ifdef APP-PLUS
|
||||
setTimeout(() => {
|
||||
const args = plus.runtime.arguments;
|
||||
if (args) {
|
||||
const argsStr = decodeURIComponent(args);
|
||||
console.log(argsStr);
|
||||
const path = argsStr.split("//")[1];
|
||||
if (path.indexOf("tabbar")) {
|
||||
if (path.indexOf("tabbar") != -1) {
|
||||
uni.switchTab({
|
||||
url: `/${path}`,
|
||||
});
|
||||
|
|
|
@ -0,0 +1,661 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
|
@ -35,7 +35,7 @@ export function getRegionsById(id = 0) {
|
|||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* 文件上传地址
|
||||
* @type {string}
|
||||
*/
|
||||
export const upload =api.common+'/upload/file';
|
||||
|
|
|
@ -68,7 +68,7 @@ export function smsLogin(params, clientType) {
|
|||
* 刷新token
|
||||
*/
|
||||
export function refreshTokenFn(refresh_token) {
|
||||
console.log(refresh_token)
|
||||
|
||||
return http.request({
|
||||
url: `/members/refresh/${refresh_token}`,
|
||||
method: "GET",
|
||||
|
|
|
@ -72,19 +72,6 @@ export function receiveCoupons(couponId) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前会员积分
|
||||
* @returns {*}
|
||||
*/
|
||||
|
||||
export function getPoints() {
|
||||
return http.request({
|
||||
url: 'members/points/current',
|
||||
method: Method.GET,
|
||||
needToken: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分明细数据
|
||||
* @param params
|
||||
|
@ -99,19 +86,6 @@ export function getPointsData(params) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分明细数据 按月分组
|
||||
* @param params
|
||||
* @returns {AxiosPromise}
|
||||
*/
|
||||
export function getPointsDataDetail(params) {
|
||||
return http.request({
|
||||
url: 'members/points/total',
|
||||
method: Method.GET,
|
||||
needToken: true,
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的评论列表
|
||||
|
|
|
@ -66,9 +66,10 @@ export function getLogisticsMessages(params) {
|
|||
|
||||
|
||||
/**
|
||||
* 获取版本更新信息
|
||||
* TODO 获取版本更新信息 暂无此功能。后续会优化更新
|
||||
* @param params
|
||||
* @returns {AxiosPromise}
|
||||
*
|
||||
*/
|
||||
export function getAppVersionList(params) {
|
||||
params = params || {};
|
||||
|
|
|
@ -55,7 +55,6 @@ export default {
|
|||
// #endif
|
||||
|
||||
downLoad() {
|
||||
console.log(this.imgUrl);
|
||||
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: this.imgUrl,
|
||||
|
|
|
@ -167,8 +167,6 @@ export default {
|
|||
}
|
||||
|
||||
if (this.tabbars.length < this.pickersize) {
|
||||
console.log(item.id);
|
||||
|
||||
let data = await getRegionsById(item.id);
|
||||
|
||||
if (data.data.result.length == 0) {
|
||||
|
|
|
@ -112,7 +112,6 @@ export default {
|
|||
};
|
||||
},
|
||||
mounted() {
|
||||
console.log("this.isFocusVal", this.isFocusVal);
|
||||
this.isFocus = this.isFocusVal;
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</u-popup>
|
||||
</template>
|
||||
<script>
|
||||
import h5Copy from "@/js_sdk/h5-copy/h5-copy.js";
|
||||
import { h5Copy } from "@/js_sdk/h5-copy/h5-copy.js";
|
||||
import configs from "@/config/config";
|
||||
import mpShare from "uview-ui/libs/mixin/mpShare.js";
|
||||
|
||||
|
@ -57,13 +57,7 @@ export default {
|
|||
},
|
||||
// 图片缩略图、 商品名称 、 type(goods,shop,pintuan) 拼团商品分享以及店铺分享
|
||||
|
||||
props: [
|
||||
"thumbnail",
|
||||
"goodsName",
|
||||
"type",
|
||||
"goodsId",
|
||||
"link",
|
||||
],
|
||||
props: ["thumbnail", "goodsName", "type", "goodsId", "link"],
|
||||
// #ifdef MP-WEIXIN
|
||||
onShareAppMessage(res) {
|
||||
return {
|
||||
|
@ -79,7 +73,7 @@ export default {
|
|||
// #ifdef H5
|
||||
copyLink() {
|
||||
let content =
|
||||
this.configs.downloadLink +
|
||||
this.configs.shareLink +
|
||||
getCurrentPages()[getCurrentPages().length - 1].__page__.fullPath;
|
||||
|
||||
if (content === null || content === undefined) {
|
||||
|
@ -104,7 +98,6 @@ export default {
|
|||
if (val.type <= 1) {
|
||||
let shareTitle;
|
||||
|
||||
|
||||
if (this.type == "goods") {
|
||||
shareTitle = `我发现了一个${this.goodsName}商品快来跟我一起看看吧`;
|
||||
} else if (this.type == "shops") {
|
||||
|
@ -112,7 +105,6 @@ export default {
|
|||
} else if (this.type == "pintuan") {
|
||||
shareTitle = `我拼了一个${this.goodsName}快来跟我一起抢购吧!`;
|
||||
}
|
||||
|
||||
|
||||
let scene; // "WXSenceTimeline 朋友圈 WXSceneSession 微信好友"
|
||||
val.type == 1
|
||||
|
@ -127,7 +119,6 @@ export default {
|
|||
summary: this.goodsName,
|
||||
title: shareTitle,
|
||||
success: function (res) {
|
||||
// console.log("success:" + JSON.stringify(res));
|
||||
uni.showToast({
|
||||
title: "分享成功!",
|
||||
duration: 2000,
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
const name = 'lilishop'
|
||||
const name = "lilishop";
|
||||
export default {
|
||||
name: name,
|
||||
schemeLink: `${name}://`, //唤起app地址
|
||||
schemeLink: `${name}://`, //唤起app地址
|
||||
downloadLink: "https://pickmall.cn/download-page/index.html", //下载地址
|
||||
shareLink: "https://m-b2b2c.pickmall.cn", //分享地址
|
||||
appid: "wx6f10f29075dc1b0b", //小程序唯一凭证,即 AppID,可在「微信公众平台 - 设置 - 开发设置」页中获得。(需要已经成为开发者,且帐号没有异常状态)
|
||||
appSecret :"6dfbe0c72380dce5d49d65b3c91059b1" //可在 manifest.json 查看
|
||||
appSecret: "6dfbe0c72380dce5d49d65b3c91059b1", //可在 manifest.json 查看
|
||||
aMapKey: "d649892b3937a5ad20b76dacb2bcb5bd", //在高德中申请web端key
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export default function h5Copy(content) {
|
||||
export function h5Copy(content) {
|
||||
|
||||
if (!document.queryCommandSupported('copy')) {
|
||||
// 不支持
|
||||
|
@ -15,4 +15,28 @@ export default function h5Copy(content) {
|
|||
textarea.remove()
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取系统剪贴板内容
|
||||
*/
|
||||
export function getClipboardData() {
|
||||
return new Promise((success, fail) => {
|
||||
// #ifndef H5
|
||||
uni.getClipboardData({
|
||||
success: ({ data }) => success(data),
|
||||
fail
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
try {
|
||||
navigator.clipboard.readText().then(success).catch(fail)
|
||||
} catch (error) {
|
||||
fail(error)
|
||||
}
|
||||
// #endif
|
||||
})
|
||||
}
|
|
@ -18,7 +18,6 @@ class LiLiWXPay {
|
|||
// 调用支付
|
||||
initiatePay(paymentMethod, paymentClient, submitData).then((res) => {
|
||||
let response = res.data.result;
|
||||
console.log(res.data.result);
|
||||
uni.hideLoading();
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
# History
|
||||
----
|
||||
|
||||
## 1.11.3 / 2019-06-28
|
||||
|
||||
- support suppressWarning option when validate
|
||||
|
||||
## 1.11.1 / 2019-04-22
|
||||
|
||||
- support message as function
|
||||
|
||||
## 1.11.0 / 2019-03-22
|
||||
|
||||
- support promise usage(asyncValidator)
|
||||
|
||||
## 1.10.1 / 2018-12-18
|
||||
|
||||
- support override warning
|
||||
|
||||
## 1.10.0 / 2018-10-17
|
||||
|
||||
- revert promise
|
||||
|
||||
## 1.9.0 / 2018-10-10
|
||||
|
||||
- .validate returns promise
|
||||
|
||||
## 1.8.0 / 2017-08-16
|
||||
|
||||
- validator support return promise.
|
||||
|
||||
## 1.7.0 / 2017-06/09
|
||||
|
||||
- add es
|
||||
- support string patter
|
||||
|
||||
## 1.6.0 / 2016-03-30
|
||||
|
||||
- support defaultField
|
||||
|
||||
## 1.5.0 / 2016-02-02
|
||||
|
||||
- support deep merge with default messages
|
||||
- support rule message of any type(exp: jsx)
|
||||
|
||||
## 1.4.0 / 2015-01-12
|
||||
|
||||
- fix first option.
|
||||
- add firstFields option.
|
||||
- see tests/validator.spec.js
|
|
@ -1,9 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-present yiminghe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,440 +0,0 @@
|
|||
# async-validator
|
||||
---
|
||||
|
||||
Validate form asynchronous. A variation of https://github.com/freeformsystems/async-validate
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
[![gemnasium deps][gemnasium-image]][gemnasium-url]
|
||||
[![node version][node-image]][node-url]
|
||||
[![npm download][download-image]][download-url]
|
||||
|
||||
[npm-image]: http://img.shields.io/npm/v/async-validator.svg?style=flat-square
|
||||
[npm-url]: http://npmjs.org/package/async-validator
|
||||
[travis-image]: https://img.shields.io/travis/yiminghe/async-validator.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/yiminghe/async-validator
|
||||
[coveralls-image]: https://img.shields.io/coveralls/yiminghe/async-validator.svg?style=flat-square
|
||||
[coveralls-url]: https://coveralls.io/r/yiminghe/async-validator?branch=master
|
||||
[gemnasium-image]: http://img.shields.io/gemnasium/yiminghe/async-validator.svg?style=flat-square
|
||||
[gemnasium-url]: https://gemnasium.com/yiminghe/async-validator
|
||||
[node-image]: https://img.shields.io/badge/node.js-%3E=4.0.0-green.svg?style=flat-square
|
||||
[node-url]: http://nodejs.org/download/
|
||||
[download-image]: https://img.shields.io/npm/dm/async-validator.svg?style=flat-square
|
||||
[download-url]: https://npmjs.org/package/async-validator
|
||||
|
||||
|
||||
## API
|
||||
|
||||
The following is modified from earlier version of [async-validate](https://github.com/freeformsystems/async-validate).
|
||||
|
||||
### Usage
|
||||
|
||||
Basic usage involves defining a descriptor, assigning it to a schema and passing the object to be validated and a callback function to the `validate` method of the schema:
|
||||
|
||||
```javascript
|
||||
var schema = require('async-validator');
|
||||
var descriptor = {
|
||||
name: {
|
||||
type: "string",
|
||||
required: true,
|
||||
validator: (rule, value) => value === 'muji',
|
||||
},
|
||||
};
|
||||
var validator = new schema(descriptor);
|
||||
validator.validate({name: "muji"}, (errors, fields) => {
|
||||
if(errors) {
|
||||
// validation failed, errors is an array of all errors
|
||||
// fields is an object keyed by field name with an array of
|
||||
// errors per field
|
||||
return handleErrors(errors, fields);
|
||||
}
|
||||
// validation passed
|
||||
});
|
||||
|
||||
// PROMISE USAGE
|
||||
validator.validate({
|
||||
name: "muji",
|
||||
asyncValidator: (rule, value) => axios.post('/nameValidator', { name: value }),
|
||||
}, (errors, fields) => {
|
||||
if(errors) {
|
||||
// validation failed, errors is an array of all errors
|
||||
// fields is an object keyed by field name with an array of
|
||||
// errors per field
|
||||
return handleErrors(errors, fields);
|
||||
}
|
||||
// validation passed
|
||||
})
|
||||
.then(() => {
|
||||
// validation passed
|
||||
})
|
||||
.catch(({ errors, fields }) => {
|
||||
return handleErrors(errors, fields);
|
||||
})
|
||||
```
|
||||
|
||||
### Validate
|
||||
|
||||
```javascript
|
||||
function(source, [options], callback): Promise
|
||||
```
|
||||
|
||||
* `source`: The object to validate (required).
|
||||
* `options`: An object describing processing options for the validation (optional).
|
||||
* `callback`: A callback function to invoke when validation completes (required).
|
||||
|
||||
The method will return a Promise object like:
|
||||
* `then()`,validation passed
|
||||
* `catch({ errors, fields })`,validation failed, errors is an array of all errors, fields is an object keyed by field name with an array of
|
||||
|
||||
### Options
|
||||
|
||||
* `suppressWarning`: Boolean, whether to suppress internal warning about invalid value.
|
||||
|
||||
* `first`: Boolean, Invoke `callback` when the first validation rule generates an error,
|
||||
no more validation rules are processed.
|
||||
If your validation involves multiple asynchronous calls (for example, database queries) and you only need the first error use this option.
|
||||
|
||||
* `firstFields`: Boolean|String[], Invoke `callback` when the first validation rule of the specified field generates an error,
|
||||
no more validation rules of the same field are processed. `true` means all fields.
|
||||
|
||||
### Rules
|
||||
|
||||
Rules may be functions that perform validation.
|
||||
|
||||
```javascript
|
||||
function(rule, value, callback, source, options)
|
||||
```
|
||||
|
||||
* `rule`: The validation rule in the source descriptor that corresponds to the field name being validated. It is always assigned a `field` property with the name of the field being validated.
|
||||
* `value`: The value of the source object property being validated.
|
||||
* `callback`: A callback function to invoke once validation is complete. It expects to be passed an array of `Error` instances to indicate validation failure. If the check is synchronous, you can directly return a ` false ` or ` Error ` or ` Error Array `.
|
||||
* `source`: The source object that was passed to the `validate` method.
|
||||
* `options`: Additional options.
|
||||
* `options.messages`: The object containing validation error messages, will be deep merged with defaultMessages.
|
||||
|
||||
The options passed to `validate` or `asyncValidate` are passed on to the validation functions so that you may reference transient data (such as model references) in validation functions. However, some option names are reserved; if you use these properties of the options object they are overwritten. The reserved properties are `messages`, `exception` and `error`.
|
||||
|
||||
```javascript
|
||||
var schema = require('async-validator');
|
||||
var descriptor = {
|
||||
name(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
if(!/^[a-z0-9]+$/.test(value)) {
|
||||
errors.push(
|
||||
new Error(
|
||||
util.format("%s must be lowercase alphanumeric characters",
|
||||
rule.field)));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
var validator = new schema(descriptor);
|
||||
validator.validate({name: "Firstname"}, (errors, fields) => {
|
||||
if(errors) {
|
||||
return handleErrors(errors, fields);
|
||||
}
|
||||
// validation passed
|
||||
});
|
||||
```
|
||||
|
||||
It is often useful to test against multiple validation rules for a single field, to do so make the rule an array of objects, for example:
|
||||
|
||||
```javascript
|
||||
var descriptor = {
|
||||
email: [
|
||||
{type: "string", required: true, pattern: schema.pattern.email},
|
||||
{validator(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
// test if email address already exists in a database
|
||||
// and add a validation error to the errors array if it does
|
||||
return errors;
|
||||
}}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Type
|
||||
|
||||
Indicates the `type` of validator to use. Recognised type values are:
|
||||
|
||||
* `string`: Must be of type `string`. `This is the default type.`
|
||||
* `number`: Must be of type `number`.
|
||||
* `boolean`: Must be of type `boolean`.
|
||||
* `method`: Must be of type `function`.
|
||||
* `regexp`: Must be an instance of `RegExp` or a string that does not generate an exception when creating a new `RegExp`.
|
||||
* `integer`: Must be of type `number` and an integer.
|
||||
* `float`: Must be of type `number` and a floating point number.
|
||||
* `array`: Must be an array as determined by `Array.isArray`.
|
||||
* `object`: Must be of type `object` and not `Array.isArray`.
|
||||
* `enum`: Value must exist in the `enum`.
|
||||
* `date`: Value must be valid as determined by `Date`
|
||||
* `url`: Must be of type `url`.
|
||||
* `hex`: Must be of type `hex`.
|
||||
* `email`: Must be of type `email`.
|
||||
|
||||
#### Required
|
||||
|
||||
The `required` rule property indicates that the field must exist on the source object being validated.
|
||||
|
||||
#### Pattern
|
||||
|
||||
The `pattern` rule property indicates a regular expression that the value must match to pass validation.
|
||||
|
||||
#### Range
|
||||
|
||||
A range is defined using the `min` and `max` properties. For `string` and `array` types comparison is performed against the `length`, for `number` types the number must not be less than `min` nor greater than `max`.
|
||||
|
||||
#### Length
|
||||
|
||||
To validate an exact length of a field specify the `len` property. For `string` and `array` types comparison is performed on the `length` property, for the `number` type this property indicates an exact match for the `number`, ie, it may only be strictly equal to `len`.
|
||||
|
||||
If the `len` property is combined with the `min` and `max` range properties, `len` takes precedence.
|
||||
|
||||
#### Enumerable
|
||||
|
||||
To validate a value from a list of possible values use the `enum` type with a `enum` property listing the valid values for the field, for example:
|
||||
|
||||
```javascript
|
||||
var descriptor = {
|
||||
role: {type: "enum", enum: ['admin', 'user', 'guest']}
|
||||
}
|
||||
```
|
||||
|
||||
#### Whitespace
|
||||
|
||||
It is typical to treat required fields that only contain whitespace as errors. To add an additional test for a string that consists solely of whitespace add a `whitespace` property to a rule with a value of `true`. The rule must be a `string` type.
|
||||
|
||||
You may wish to sanitize user input instead of testing for whitespace, see [transform](#transform) for an example that would allow you to strip whitespace.
|
||||
|
||||
|
||||
#### Deep Rules
|
||||
|
||||
If you need to validate deep object properties you may do so for validation rules that are of the `object` or `array` type by assigning nested rules to a `fields` property of the rule.
|
||||
|
||||
```javascript
|
||||
var descriptor = {
|
||||
address: {
|
||||
type: "object", required: true,
|
||||
fields: {
|
||||
street: {type: "string", required: true},
|
||||
city: {type: "string", required: true},
|
||||
zip: {type: "string", required: true, len: 8, message: "invalid zip"}
|
||||
}
|
||||
},
|
||||
name: {type: "string", required: true}
|
||||
}
|
||||
var validator = new schema(descriptor);
|
||||
validator.validate({ address: {} }, (errors, fields) => {
|
||||
// errors for address.street, address.city, address.zip
|
||||
});
|
||||
```
|
||||
|
||||
Note that if you do not specify the `required` property on the parent rule it is perfectly valid for the field not to be declared on the source object and the deep validation rules will not be executed as there is nothing to validate against.
|
||||
|
||||
Deep rule validation creates a schema for the nested rules so you can also specify the `options` passed to the `schema.validate()` method.
|
||||
|
||||
```javascript
|
||||
var descriptor = {
|
||||
address: {
|
||||
type: "object", required: true, options: {single: true, first: true},
|
||||
fields: {
|
||||
street: {type: "string", required: true},
|
||||
city: {type: "string", required: true},
|
||||
zip: {type: "string", required: true, len: 8, message: "invalid zip"}
|
||||
}
|
||||
},
|
||||
name: {type: "string", required: true}
|
||||
}
|
||||
var validator = new schema(descriptor);
|
||||
|
||||
validator.validate({ address: {} })
|
||||
.catch(({ errors, fields }) => {
|
||||
// now only errors for street and name
|
||||
});
|
||||
```
|
||||
|
||||
The parent rule is also validated so if you have a set of rules such as:
|
||||
|
||||
```javascript
|
||||
var descriptor = {
|
||||
roles: {
|
||||
type: "array", required: true, len: 3,
|
||||
fields: {
|
||||
0: {type: "string", required: true},
|
||||
1: {type: "string", required: true},
|
||||
2: {type: "string", required: true}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
And supply a source object of `{roles: ["admin", "user"]}` then two errors will be created. One for the array length mismatch and one for the missing required array entry at index 2.
|
||||
|
||||
#### defaultField
|
||||
|
||||
The `defaultField` property can be used with the `array` or `object` type for validating all values of the container.
|
||||
It may be an `object` or `array` containing validation rules. For example:
|
||||
|
||||
```javascript
|
||||
var descriptor = {
|
||||
urls: {
|
||||
type: "array", required: true,
|
||||
defaultField: {type: "url"}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note that `defaultField` is expanded to `fields`, see [deep rules](#deep-rules).
|
||||
|
||||
#### Transform
|
||||
|
||||
Sometimes it is necessary to transform a value before validation, possibly to coerce the value or to sanitize it in some way. To do this add a `transform` function to the validation rule. The property is transformed prior to validation and re-assigned to the source object to mutate the value of the property in place.
|
||||
|
||||
```javascript
|
||||
var schema = require('async-validator');
|
||||
var sanitize = require('validator').sanitize;
|
||||
var descriptor = {
|
||||
name: {
|
||||
type: "string",
|
||||
required: true, pattern: /^[a-z]+$/,
|
||||
transform(value) {
|
||||
return sanitize(value).trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
var validator = new schema(descriptor);
|
||||
var source = {name: " user "};
|
||||
validator.validate(source)
|
||||
.then(() => assert.equal(source.name, "user"));
|
||||
```
|
||||
|
||||
Without the `transform` function validation would fail due to the pattern not matching as the input contains leading and trailing whitespace, but by adding the transform function validation passes and the field value is sanitized at the same time.
|
||||
|
||||
|
||||
### Messages
|
||||
|
||||
Depending upon your application requirements, you may need i18n support or you may prefer different validation error messages.
|
||||
|
||||
The easiest way to achieve this is to assign a `message` to a rule:
|
||||
|
||||
```javascript
|
||||
{name:{type: "string", required: true, message: "Name is required"}}
|
||||
```
|
||||
|
||||
Message can be any type, such as jsx format.
|
||||
|
||||
```javascript
|
||||
{name:{type: "string", required: true, message: <b>Name is required</b>}}
|
||||
```
|
||||
|
||||
Message can also be a function, e.g. if you use vue-i18n:
|
||||
```javascript
|
||||
{name:{type: "string", required: true, message: () => this.$t( 'name is required' )}}
|
||||
```
|
||||
|
||||
Potentially you may require the same schema validation rules for different languages, in which case duplicating the schema rules for each language does not make sense.
|
||||
|
||||
In this scenario you could just provide your own messages for the language and assign it to the schema:
|
||||
|
||||
```javascript
|
||||
var schema = require('async-validator');
|
||||
var cn = {
|
||||
required: '%s 必填',
|
||||
};
|
||||
var descriptor = {name:{type: "string", required: true}};
|
||||
var validator = new schema(descriptor);
|
||||
// deep merge with defaultMessages
|
||||
validator.messages(cn);
|
||||
...
|
||||
```
|
||||
|
||||
If you are defining your own validation functions it is better practice to assign the message strings to a messages object and then access the messages via the `options.messages` property within the validation function.
|
||||
|
||||
### asyncValidator
|
||||
|
||||
You can customize the asynchronous validation function for the specified field:
|
||||
|
||||
```js
|
||||
const fields = {
|
||||
asyncField:{
|
||||
asyncValidator(rule,value,callback){
|
||||
ajax({
|
||||
url:'xx',
|
||||
value:value
|
||||
}).then(function(data){
|
||||
callback();
|
||||
},function(error){
|
||||
callback(new Error(error))
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
promiseField:{
|
||||
asyncValidator(rule, value){
|
||||
return ajax({
|
||||
url:'xx',
|
||||
value:value
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### validator
|
||||
|
||||
you can custom validate function for specified field:
|
||||
|
||||
```js
|
||||
const fields = {
|
||||
field:{
|
||||
validator(rule,value,callback){
|
||||
return value === 'test';
|
||||
},
|
||||
message: 'Value is not equal to "test".',
|
||||
},
|
||||
|
||||
field2:{
|
||||
validator(rule,value,callback){
|
||||
return new Error(`'${value} is not equal to "test".'`);
|
||||
},
|
||||
},
|
||||
|
||||
arrField:{
|
||||
validator(rule, value){
|
||||
return [
|
||||
new Error('Message 1'),
|
||||
new Error('Message 2'),
|
||||
];
|
||||
}
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## FAQ
|
||||
|
||||
### How to avoid warning
|
||||
|
||||
```js
|
||||
var Schema = require('async-validator');
|
||||
Schema.warning = function(){};
|
||||
```
|
||||
|
||||
## Test Case
|
||||
|
||||
```
|
||||
npm test
|
||||
npm run chrome-test
|
||||
```
|
||||
|
||||
## Coverage
|
||||
|
||||
```
|
||||
npm run coverage
|
||||
```
|
||||
|
||||
open coverage/ dir
|
||||
|
||||
## License
|
||||
|
||||
Everything is [MIT](http://en.wikipedia.org/wiki/MIT_License).
|
|
@ -1,298 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _util = require('./util');
|
||||
|
||||
var _validator = require('./validator/');
|
||||
|
||||
var _validator2 = _interopRequireDefault(_validator);
|
||||
|
||||
var _messages2 = require('./messages');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Encapsulates a validation schema.
|
||||
*
|
||||
* @param descriptor An object declaring validation rules
|
||||
* for this schema.
|
||||
*/
|
||||
function Schema(descriptor) {
|
||||
this.rules = null;
|
||||
this._messages = _messages2.messages;
|
||||
this.define(descriptor);
|
||||
}
|
||||
|
||||
Schema.prototype = {
|
||||
messages: function messages(_messages) {
|
||||
if (_messages) {
|
||||
this._messages = (0, _util.deepMerge)((0, _messages2.newMessages)(), _messages);
|
||||
}
|
||||
return this._messages;
|
||||
},
|
||||
define: function define(rules) {
|
||||
if (!rules) {
|
||||
throw new Error('Cannot configure a schema with no rules');
|
||||
}
|
||||
if ((typeof rules === 'undefined' ? 'undefined' : _typeof(rules)) !== 'object' || Array.isArray(rules)) {
|
||||
throw new Error('Rules must be an object');
|
||||
}
|
||||
this.rules = {};
|
||||
var z = void 0;
|
||||
var item = void 0;
|
||||
for (z in rules) {
|
||||
if (rules.hasOwnProperty(z)) {
|
||||
item = rules[z];
|
||||
this.rules[z] = Array.isArray(item) ? item : [item];
|
||||
}
|
||||
}
|
||||
},
|
||||
validate: function validate(source_) {
|
||||
var _this = this;
|
||||
|
||||
var o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var oc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
|
||||
|
||||
var source = source_;
|
||||
var options = o;
|
||||
var callback = oc;
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
if (!this.rules || Object.keys(this.rules).length === 0) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function complete(results) {
|
||||
var i = void 0;
|
||||
var errors = [];
|
||||
var fields = {};
|
||||
|
||||
function add(e) {
|
||||
if (Array.isArray(e)) {
|
||||
var _errors;
|
||||
|
||||
errors = (_errors = errors).concat.apply(_errors, e);
|
||||
} else {
|
||||
errors.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < results.length; i++) {
|
||||
add(results[i]);
|
||||
}
|
||||
if (!errors.length) {
|
||||
errors = null;
|
||||
fields = null;
|
||||
} else {
|
||||
fields = (0, _util.convertFieldsError)(errors);
|
||||
}
|
||||
callback(errors, fields);
|
||||
}
|
||||
|
||||
if (options.messages) {
|
||||
var messages = this.messages();
|
||||
if (messages === _messages2.messages) {
|
||||
messages = (0, _messages2.newMessages)();
|
||||
}
|
||||
(0, _util.deepMerge)(messages, options.messages);
|
||||
options.messages = messages;
|
||||
} else {
|
||||
options.messages = this.messages();
|
||||
}
|
||||
var arr = void 0;
|
||||
var value = void 0;
|
||||
var series = {};
|
||||
var keys = options.keys || Object.keys(this.rules);
|
||||
keys.forEach(function (z) {
|
||||
arr = _this.rules[z];
|
||||
value = source[z];
|
||||
arr.forEach(function (r) {
|
||||
var rule = r;
|
||||
if (typeof rule.transform === 'function') {
|
||||
if (source === source_) {
|
||||
source = _extends({}, source);
|
||||
}
|
||||
value = source[z] = rule.transform(value);
|
||||
}
|
||||
if (typeof rule === 'function') {
|
||||
rule = {
|
||||
validator: rule
|
||||
};
|
||||
} else {
|
||||
rule = _extends({}, rule);
|
||||
}
|
||||
rule.validator = _this.getValidationMethod(rule);
|
||||
rule.field = z;
|
||||
rule.fullField = rule.fullField || z;
|
||||
rule.type = _this.getType(rule);
|
||||
if (!rule.validator) {
|
||||
return;
|
||||
}
|
||||
series[z] = series[z] || [];
|
||||
series[z].push({
|
||||
rule: rule,
|
||||
value: value,
|
||||
source: source,
|
||||
field: z
|
||||
});
|
||||
});
|
||||
});
|
||||
var errorFields = {};
|
||||
return (0, _util.asyncMap)(series, options, function (data, doIt) {
|
||||
var rule = data.rule;
|
||||
var deep = (rule.type === 'object' || rule.type === 'array') && (_typeof(rule.fields) === 'object' || _typeof(rule.defaultField) === 'object');
|
||||
deep = deep && (rule.required || !rule.required && data.value);
|
||||
rule.field = data.field;
|
||||
|
||||
function addFullfield(key, schema) {
|
||||
return _extends({}, schema, {
|
||||
fullField: rule.fullField + '.' + key
|
||||
});
|
||||
}
|
||||
|
||||
function cb() {
|
||||
var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
||||
|
||||
var errors = e;
|
||||
if (!Array.isArray(errors)) {
|
||||
errors = [errors];
|
||||
}
|
||||
if (!options.suppressWarning && errors.length) {
|
||||
Schema.warning('async-validator:', errors);
|
||||
}
|
||||
if (errors.length && rule.message) {
|
||||
errors = [].concat(rule.message);
|
||||
}
|
||||
|
||||
errors = errors.map((0, _util.complementError)(rule));
|
||||
|
||||
if (options.first && errors.length) {
|
||||
errorFields[rule.field] = 1;
|
||||
return doIt(errors);
|
||||
}
|
||||
if (!deep) {
|
||||
doIt(errors);
|
||||
} else {
|
||||
// if rule is required but the target object
|
||||
// does not exist fail at the rule level and don't
|
||||
// go deeper
|
||||
if (rule.required && !data.value) {
|
||||
if (rule.message) {
|
||||
errors = [].concat(rule.message).map((0, _util.complementError)(rule));
|
||||
} else if (options.error) {
|
||||
errors = [options.error(rule, (0, _util.format)(options.messages.required, rule.field))];
|
||||
} else {
|
||||
errors = [];
|
||||
}
|
||||
return doIt(errors);
|
||||
}
|
||||
|
||||
var fieldsSchema = {};
|
||||
if (rule.defaultField) {
|
||||
for (var k in data.value) {
|
||||
if (data.value.hasOwnProperty(k)) {
|
||||
fieldsSchema[k] = rule.defaultField;
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldsSchema = _extends({}, fieldsSchema, data.rule.fields);
|
||||
for (var f in fieldsSchema) {
|
||||
if (fieldsSchema.hasOwnProperty(f)) {
|
||||
var fieldSchema = Array.isArray(fieldsSchema[f]) ? fieldsSchema[f] : [fieldsSchema[f]];
|
||||
fieldsSchema[f] = fieldSchema.map(addFullfield.bind(null, f));
|
||||
}
|
||||
}
|
||||
var schema = new Schema(fieldsSchema);
|
||||
schema.messages(options.messages);
|
||||
if (data.rule.options) {
|
||||
data.rule.options.messages = options.messages;
|
||||
data.rule.options.error = options.error;
|
||||
}
|
||||
schema.validate(data.value, data.rule.options || options, function (errs) {
|
||||
var finalErrors = [];
|
||||
if (errors && errors.length) {
|
||||
finalErrors.push.apply(finalErrors, errors);
|
||||
}
|
||||
if (errs && errs.length) {
|
||||
finalErrors.push.apply(finalErrors, errs);
|
||||
}
|
||||
doIt(finalErrors.length ? finalErrors : null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var res = void 0;
|
||||
if (rule.asyncValidator) {
|
||||
res = rule.asyncValidator(rule, data.value, cb, data.source, options);
|
||||
} else if (rule.validator) {
|
||||
res = rule.validator(rule, data.value, cb, data.source, options);
|
||||
if (res === true) {
|
||||
cb();
|
||||
} else if (res === false) {
|
||||
cb(rule.message || rule.field + ' fails');
|
||||
} else if (res instanceof Array) {
|
||||
cb(res);
|
||||
} else if (res instanceof Error) {
|
||||
cb(res.message);
|
||||
}
|
||||
}
|
||||
if (res && res.then) {
|
||||
res.then(function () {
|
||||
return cb();
|
||||
}, function (e) {
|
||||
return cb(e);
|
||||
});
|
||||
}
|
||||
}, function (results) {
|
||||
complete(results);
|
||||
});
|
||||
},
|
||||
getType: function getType(rule) {
|
||||
if (rule.type === undefined && rule.pattern instanceof RegExp) {
|
||||
rule.type = 'pattern';
|
||||
}
|
||||
if (typeof rule.validator !== 'function' && rule.type && !_validator2['default'].hasOwnProperty(rule.type)) {
|
||||
throw new Error((0, _util.format)('Unknown rule type %s', rule.type));
|
||||
}
|
||||
return rule.type || 'string';
|
||||
},
|
||||
getValidationMethod: function getValidationMethod(rule) {
|
||||
if (typeof rule.validator === 'function') {
|
||||
return rule.validator;
|
||||
}
|
||||
var keys = Object.keys(rule);
|
||||
var messageIndex = keys.indexOf('message');
|
||||
if (messageIndex !== -1) {
|
||||
keys.splice(messageIndex, 1);
|
||||
}
|
||||
if (keys.length === 1 && keys[0] === 'required') {
|
||||
return _validator2['default'].required;
|
||||
}
|
||||
return _validator2['default'][this.getType(rule)] || false;
|
||||
}
|
||||
};
|
||||
|
||||
Schema.register = function register(type, validator) {
|
||||
if (typeof validator !== 'function') {
|
||||
throw new Error('Cannot register a validator by type, validator is not a function');
|
||||
}
|
||||
_validator2['default'][type] = validator;
|
||||
};
|
||||
|
||||
Schema.warning = _util.warning;
|
||||
|
||||
Schema.messages = _messages2.messages;
|
||||
|
||||
exports['default'] = Schema;
|
|
@ -1,62 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.newMessages = newMessages;
|
||||
function newMessages() {
|
||||
return {
|
||||
'default': 'Validation error on field %s',
|
||||
required: '%s is required',
|
||||
'enum': '%s must be one of %s',
|
||||
whitespace: '%s cannot be empty',
|
||||
date: {
|
||||
format: '%s date %s is invalid for format %s',
|
||||
parse: '%s date could not be parsed, %s is invalid ',
|
||||
invalid: '%s date %s is invalid'
|
||||
},
|
||||
types: {
|
||||
string: '%s is not a %s',
|
||||
method: '%s is not a %s (function)',
|
||||
array: '%s is not an %s',
|
||||
object: '%s is not an %s',
|
||||
number: '%s is not a %s',
|
||||
date: '%s is not a %s',
|
||||
boolean: '%s is not a %s',
|
||||
integer: '%s is not an %s',
|
||||
float: '%s is not a %s',
|
||||
regexp: '%s is not a valid %s',
|
||||
email: '%s is not a valid %s',
|
||||
url: '%s is not a valid %s',
|
||||
hex: '%s is not a valid %s'
|
||||
},
|
||||
string: {
|
||||
len: '%s must be exactly %s characters',
|
||||
min: '%s must be at least %s characters',
|
||||
max: '%s cannot be longer than %s characters',
|
||||
range: '%s must be between %s and %s characters'
|
||||
},
|
||||
number: {
|
||||
len: '%s must equal %s',
|
||||
min: '%s cannot be less than %s',
|
||||
max: '%s cannot be greater than %s',
|
||||
range: '%s must be between %s and %s'
|
||||
},
|
||||
array: {
|
||||
len: '%s must be exactly %s in length',
|
||||
min: '%s cannot be less than %s in length',
|
||||
max: '%s cannot be greater than %s in length',
|
||||
range: '%s must be between %s and %s in length'
|
||||
},
|
||||
pattern: {
|
||||
mismatch: '%s value %s does not match pattern %s'
|
||||
},
|
||||
clone: function clone() {
|
||||
var cloned = JSON.parse(JSON.stringify(this));
|
||||
cloned.clone = this.clone;
|
||||
return cloned;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var messages = exports.messages = newMessages();
|
|
@ -1,33 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
var ENUM = 'enum';
|
||||
|
||||
/**
|
||||
* Rule for validating a value exists in an enumerable list.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function enumerable(rule, value, source, errors, options) {
|
||||
rule[ENUM] = Array.isArray(rule[ENUM]) ? rule[ENUM] : [];
|
||||
if (rule[ENUM].indexOf(value) === -1) {
|
||||
errors.push(util.format(options.messages[ENUM], rule.fullField, rule[ENUM].join(', ')));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = enumerable;
|
|
@ -1,40 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _required = require('./required');
|
||||
|
||||
var _required2 = _interopRequireDefault(_required);
|
||||
|
||||
var _whitespace = require('./whitespace');
|
||||
|
||||
var _whitespace2 = _interopRequireDefault(_whitespace);
|
||||
|
||||
var _type = require('./type');
|
||||
|
||||
var _type2 = _interopRequireDefault(_type);
|
||||
|
||||
var _range = require('./range');
|
||||
|
||||
var _range2 = _interopRequireDefault(_range);
|
||||
|
||||
var _enum = require('./enum');
|
||||
|
||||
var _enum2 = _interopRequireDefault(_enum);
|
||||
|
||||
var _pattern = require('./pattern');
|
||||
|
||||
var _pattern2 = _interopRequireDefault(_pattern);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
exports['default'] = {
|
||||
required: _required2['default'],
|
||||
whitespace: _whitespace2['default'],
|
||||
type: _type2['default'],
|
||||
range: _range2['default'],
|
||||
'enum': _enum2['default'],
|
||||
pattern: _pattern2['default']
|
||||
};
|
|
@ -1,43 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating a regular expression pattern.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function pattern(rule, value, source, errors, options) {
|
||||
if (rule.pattern) {
|
||||
if (rule.pattern instanceof RegExp) {
|
||||
// if a RegExp instance is passed, reset `lastIndex` in case its `global`
|
||||
// flag is accidentally set to `true`, which in a validation scenario
|
||||
// is not necessary and the result might be misleading
|
||||
rule.pattern.lastIndex = 0;
|
||||
if (!rule.pattern.test(value)) {
|
||||
errors.push(util.format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
||||
}
|
||||
} else if (typeof rule.pattern === 'string') {
|
||||
var _pattern = new RegExp(rule.pattern);
|
||||
if (!_pattern.test(value)) {
|
||||
errors.push(util.format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = pattern;
|
|
@ -1,68 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating minimum and maximum allowed values.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function range(rule, value, source, errors, options) {
|
||||
var len = typeof rule.len === 'number';
|
||||
var min = typeof rule.min === 'number';
|
||||
var max = typeof rule.max === 'number';
|
||||
// 正则匹配码点范围从U+010000一直到U+10FFFF的文字(补充平面Supplementary Plane)
|
||||
var spRegexp = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
var val = value;
|
||||
var key = null;
|
||||
var num = typeof value === 'number';
|
||||
var str = typeof value === 'string';
|
||||
var arr = Array.isArray(value);
|
||||
if (num) {
|
||||
key = 'number';
|
||||
} else if (str) {
|
||||
key = 'string';
|
||||
} else if (arr) {
|
||||
key = 'array';
|
||||
}
|
||||
// if the value is not of a supported type for range validation
|
||||
// the validation rule rule should use the
|
||||
// type property to also test for a particular type
|
||||
if (!key) {
|
||||
return false;
|
||||
}
|
||||
if (arr) {
|
||||
val = value.length;
|
||||
}
|
||||
if (str) {
|
||||
// 处理码点大于U+010000的文字length属性不准确的bug,如"𠮷𠮷𠮷".lenght !== 3
|
||||
val = value.replace(spRegexp, '_').length;
|
||||
}
|
||||
if (len) {
|
||||
if (val !== rule.len) {
|
||||
errors.push(util.format(options.messages[key].len, rule.fullField, rule.len));
|
||||
}
|
||||
} else if (min && !max && val < rule.min) {
|
||||
errors.push(util.format(options.messages[key].min, rule.fullField, rule.min));
|
||||
} else if (max && !min && val > rule.max) {
|
||||
errors.push(util.format(options.messages[key].max, rule.fullField, rule.max));
|
||||
} else if (min && max && (val < rule.min || val > rule.max)) {
|
||||
errors.push(util.format(options.messages[key].range, rule.fullField, rule.min, rule.max));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = range;
|
|
@ -1,30 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating required fields.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function required(rule, value, source, errors, options, type) {
|
||||
if (rule.required && (!source.hasOwnProperty(rule.field) || util.isEmptyValue(value, type || rule.type))) {
|
||||
errors.push(util.format(options.messages.required, rule.fullField));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = required;
|
|
@ -1,104 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
var _required = require('./required');
|
||||
|
||||
var _required2 = _interopRequireDefault(_required);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/* eslint max-len:0 */
|
||||
|
||||
var pattern = {
|
||||
// http://emailregex.com/
|
||||
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
||||
url: new RegExp('^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$', 'i'),
|
||||
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
|
||||
};
|
||||
|
||||
var types = {
|
||||
integer: function integer(value) {
|
||||
return types.number(value) && parseInt(value, 10) === value;
|
||||
},
|
||||
float: function float(value) {
|
||||
return types.number(value) && !types.integer(value);
|
||||
},
|
||||
array: function array(value) {
|
||||
return Array.isArray(value);
|
||||
},
|
||||
regexp: function regexp(value) {
|
||||
if (value instanceof RegExp) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
return !!new RegExp(value);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
date: function date(value) {
|
||||
return typeof value.getTime === 'function' && typeof value.getMonth === 'function' && typeof value.getYear === 'function';
|
||||
},
|
||||
number: function number(value) {
|
||||
if (isNaN(value)) {
|
||||
return false;
|
||||
}
|
||||
return typeof value === 'number';
|
||||
},
|
||||
object: function object(value) {
|
||||
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && !types.array(value);
|
||||
},
|
||||
method: function method(value) {
|
||||
return typeof value === 'function';
|
||||
},
|
||||
email: function email(value) {
|
||||
return typeof value === 'string' && !!value.match(pattern.email) && value.length < 255;
|
||||
},
|
||||
url: function url(value) {
|
||||
return typeof value === 'string' && !!value.match(pattern.url);
|
||||
},
|
||||
hex: function hex(value) {
|
||||
return typeof value === 'string' && !!value.match(pattern.hex);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Rule for validating the type of a value.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function type(rule, value, source, errors, options) {
|
||||
if (rule.required && value === undefined) {
|
||||
(0, _required2['default'])(rule, value, source, errors, options);
|
||||
return;
|
||||
}
|
||||
var custom = ['integer', 'float', 'array', 'regexp', 'object', 'method', 'email', 'number', 'date', 'url', 'hex'];
|
||||
var ruleType = rule.type;
|
||||
if (custom.indexOf(ruleType) > -1) {
|
||||
if (!types[ruleType](value)) {
|
||||
errors.push(util.format(options.messages.types[ruleType], rule.fullField, rule.type));
|
||||
}
|
||||
// straight typeof check
|
||||
} else if (ruleType && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== rule.type) {
|
||||
errors.push(util.format(options.messages.types[ruleType], rule.fullField, rule.type));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = type;
|
|
@ -1,30 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating whitespace.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function whitespace(rule, value, source, errors, options) {
|
||||
if (/^\s+$/.test(value) || value === '') {
|
||||
errors.push(util.format(options.messages.whitespace, rule.fullField));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = whitespace;
|
|
@ -1,223 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
exports.convertFieldsError = convertFieldsError;
|
||||
exports.format = format;
|
||||
exports.isEmptyValue = isEmptyValue;
|
||||
exports.isEmptyObject = isEmptyObject;
|
||||
exports.asyncMap = asyncMap;
|
||||
exports.complementError = complementError;
|
||||
exports.deepMerge = deepMerge;
|
||||
/* eslint no-console:0 */
|
||||
|
||||
var formatRegExp = /%[sdj%]/g;
|
||||
|
||||
var warning = exports.warning = function warning() {};
|
||||
|
||||
// don't print warning message when in production env or node runtime
|
||||
if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
exports.warning = warning = function warning(type, errors) {
|
||||
if (typeof console !== 'undefined' && console.warn) {
|
||||
if (errors.every(function (e) {
|
||||
return typeof e === 'string';
|
||||
})) {
|
||||
console.warn(type, errors);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function convertFieldsError(errors) {
|
||||
if (!errors || !errors.length) return null;
|
||||
var fields = {};
|
||||
errors.forEach(function (error) {
|
||||
var field = error.field;
|
||||
fields[field] = fields[field] || [];
|
||||
fields[field].push(error);
|
||||
});
|
||||
return fields;
|
||||
}
|
||||
|
||||
function format() {
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
var i = 1;
|
||||
var f = args[0];
|
||||
var len = args.length;
|
||||
if (typeof f === 'function') {
|
||||
return f.apply(null, args.slice(1));
|
||||
}
|
||||
if (typeof f === 'string') {
|
||||
var str = String(f).replace(formatRegExp, function (x) {
|
||||
if (x === '%%') {
|
||||
return '%';
|
||||
}
|
||||
if (i >= len) {
|
||||
return x;
|
||||
}
|
||||
switch (x) {
|
||||
case '%s':
|
||||
return String(args[i++]);
|
||||
case '%d':
|
||||
return Number(args[i++]);
|
||||
case '%j':
|
||||
try {
|
||||
return JSON.stringify(args[i++]);
|
||||
} catch (_) {
|
||||
return '[Circular]';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return x;
|
||||
}
|
||||
});
|
||||
for (var arg = args[i]; i < len; arg = args[++i]) {
|
||||
str += ' ' + arg;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
function isNativeStringType(type) {
|
||||
return type === 'string' || type === 'url' || type === 'hex' || type === 'email' || type === 'pattern';
|
||||
}
|
||||
|
||||
function isEmptyValue(value, type) {
|
||||
if (value === undefined || value === null) {
|
||||
return true;
|
||||
}
|
||||
if (type === 'array' && Array.isArray(value) && !value.length) {
|
||||
return true;
|
||||
}
|
||||
if (isNativeStringType(type) && typeof value === 'string' && !value) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isEmptyObject(obj) {
|
||||
return Object.keys(obj).length === 0;
|
||||
}
|
||||
|
||||
function asyncParallelArray(arr, func, callback) {
|
||||
var results = [];
|
||||
var total = 0;
|
||||
var arrLength = arr.length;
|
||||
|
||||
function count(errors) {
|
||||
results.push.apply(results, errors);
|
||||
total++;
|
||||
if (total === arrLength) {
|
||||
callback(results);
|
||||
}
|
||||
}
|
||||
|
||||
arr.forEach(function (a) {
|
||||
func(a, count);
|
||||
});
|
||||
}
|
||||
|
||||
function asyncSerialArray(arr, func, callback) {
|
||||
var index = 0;
|
||||
var arrLength = arr.length;
|
||||
|
||||
function next(errors) {
|
||||
if (errors && errors.length) {
|
||||
callback(errors);
|
||||
return;
|
||||
}
|
||||
var original = index;
|
||||
index = index + 1;
|
||||
if (original < arrLength) {
|
||||
func(arr[original], next);
|
||||
} else {
|
||||
callback([]);
|
||||
}
|
||||
}
|
||||
|
||||
next([]);
|
||||
}
|
||||
|
||||
function flattenObjArr(objArr) {
|
||||
var ret = [];
|
||||
Object.keys(objArr).forEach(function (k) {
|
||||
ret.push.apply(ret, objArr[k]);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
function asyncMap(objArr, option, func, callback) {
|
||||
if (option.first) {
|
||||
var flattenArr = flattenObjArr(objArr);
|
||||
return asyncSerialArray(flattenArr, func, callback);
|
||||
}
|
||||
var firstFields = option.firstFields || [];
|
||||
if (firstFields === true) {
|
||||
firstFields = Object.keys(objArr);
|
||||
}
|
||||
var objArrKeys = Object.keys(objArr);
|
||||
var objArrLength = objArrKeys.length;
|
||||
var total = 0;
|
||||
var results = [];
|
||||
var pending = new Promise(function (resolve, reject) {
|
||||
var next = function next(errors) {
|
||||
results.push.apply(results, errors);
|
||||
total++;
|
||||
if (total === objArrLength) {
|
||||
callback(results);
|
||||
return results.length ? reject({ errors: results, fields: convertFieldsError(results) }) : resolve();
|
||||
}
|
||||
};
|
||||
objArrKeys.forEach(function (key) {
|
||||
var arr = objArr[key];
|
||||
if (firstFields.indexOf(key) !== -1) {
|
||||
asyncSerialArray(arr, func, next);
|
||||
} else {
|
||||
asyncParallelArray(arr, func, next);
|
||||
}
|
||||
});
|
||||
});
|
||||
pending['catch'](function (e) {
|
||||
return e;
|
||||
});
|
||||
return pending;
|
||||
}
|
||||
|
||||
function complementError(rule) {
|
||||
return function (oe) {
|
||||
if (oe && oe.message) {
|
||||
oe.field = oe.field || rule.fullField;
|
||||
return oe;
|
||||
}
|
||||
return {
|
||||
message: typeof oe === 'function' ? oe() : oe,
|
||||
field: oe.field || rule.fullField
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function deepMerge(target, source) {
|
||||
if (source) {
|
||||
for (var s in source) {
|
||||
if (source.hasOwnProperty(s)) {
|
||||
var value = source[s];
|
||||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && _typeof(target[s]) === 'object') {
|
||||
target[s] = _extends({}, target[s], value);
|
||||
} else {
|
||||
target[s] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates an array.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function array(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value, 'array') && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options, 'array');
|
||||
if (!(0, _util.isEmptyValue)(value, 'array')) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = array;
|
|
@ -1,40 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a boolean.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function boolean(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = boolean;
|
|
@ -1,43 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function date(rule, value, callback, source, options) {
|
||||
// console.log('integer rule called %j', rule);
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
// console.log('validate on %s value', value);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (!(0, _util.isEmptyValue)(value)) {
|
||||
var dateObject = void 0;
|
||||
|
||||
if (typeof value === 'number') {
|
||||
dateObject = new Date(value);
|
||||
} else {
|
||||
dateObject = value;
|
||||
}
|
||||
|
||||
_rule2['default'].type(rule, dateObject, source, errors, options);
|
||||
if (dateObject) {
|
||||
_rule2['default'].range(rule, dateObject.getTime(), source, errors, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = date;
|
|
@ -1,42 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
var ENUM = 'enum';
|
||||
|
||||
/**
|
||||
* Validates an enumerable list.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function enumerable(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value) {
|
||||
_rule2['default'][ENUM](rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = enumerable;
|
|
@ -1,41 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a number is a floating point number.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function floatFn(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = floatFn;
|
|
@ -1,82 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _string = require('./string');
|
||||
|
||||
var _string2 = _interopRequireDefault(_string);
|
||||
|
||||
var _method = require('./method');
|
||||
|
||||
var _method2 = _interopRequireDefault(_method);
|
||||
|
||||
var _number = require('./number');
|
||||
|
||||
var _number2 = _interopRequireDefault(_number);
|
||||
|
||||
var _boolean = require('./boolean');
|
||||
|
||||
var _boolean2 = _interopRequireDefault(_boolean);
|
||||
|
||||
var _regexp = require('./regexp');
|
||||
|
||||
var _regexp2 = _interopRequireDefault(_regexp);
|
||||
|
||||
var _integer = require('./integer');
|
||||
|
||||
var _integer2 = _interopRequireDefault(_integer);
|
||||
|
||||
var _float = require('./float');
|
||||
|
||||
var _float2 = _interopRequireDefault(_float);
|
||||
|
||||
var _array = require('./array');
|
||||
|
||||
var _array2 = _interopRequireDefault(_array);
|
||||
|
||||
var _object = require('./object');
|
||||
|
||||
var _object2 = _interopRequireDefault(_object);
|
||||
|
||||
var _enum = require('./enum');
|
||||
|
||||
var _enum2 = _interopRequireDefault(_enum);
|
||||
|
||||
var _pattern = require('./pattern');
|
||||
|
||||
var _pattern2 = _interopRequireDefault(_pattern);
|
||||
|
||||
var _date = require('./date');
|
||||
|
||||
var _date2 = _interopRequireDefault(_date);
|
||||
|
||||
var _required = require('./required');
|
||||
|
||||
var _required2 = _interopRequireDefault(_required);
|
||||
|
||||
var _type = require('./type');
|
||||
|
||||
var _type2 = _interopRequireDefault(_type);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
exports['default'] = {
|
||||
string: _string2['default'],
|
||||
method: _method2['default'],
|
||||
number: _number2['default'],
|
||||
boolean: _boolean2['default'],
|
||||
regexp: _regexp2['default'],
|
||||
integer: _integer2['default'],
|
||||
float: _float2['default'],
|
||||
array: _array2['default'],
|
||||
object: _object2['default'],
|
||||
'enum': _enum2['default'],
|
||||
pattern: _pattern2['default'],
|
||||
date: _date2['default'],
|
||||
url: _type2['default'],
|
||||
hex: _type2['default'],
|
||||
email: _type2['default'],
|
||||
required: _required2['default']
|
||||
};
|
|
@ -1,41 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a number is an integer.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function integer(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = integer;
|
|
@ -1,40 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a function.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function method(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = method;
|
|
@ -1,44 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a number.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function number(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if (value === '') {
|
||||
value = undefined;
|
||||
}
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = number;
|
|
@ -1,40 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates an object.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function object(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = object;
|
|
@ -1,43 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a regular expression pattern.
|
||||
*
|
||||
* Performs validation when a rule only contains
|
||||
* a pattern property but is not declared as a string type.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function pattern(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value, 'string') && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (!(0, _util.isEmptyValue)(value, 'string')) {
|
||||
_rule2['default'].pattern(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = pattern;
|
|
@ -1,40 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates the regular expression type.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function regexp(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (!(0, _util.isEmptyValue)(value)) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = regexp;
|
|
@ -1,22 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function required(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var type = Array.isArray(value) ? 'array' : typeof value === 'undefined' ? 'undefined' : _typeof(value);
|
||||
_rule2['default'].required(rule, value, source, errors, options, type);
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = required;
|
|
@ -1,45 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Performs validation for string types.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function string(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value, 'string') && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options, 'string');
|
||||
if (!(0, _util.isEmptyValue)(value, 'string')) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
_rule2['default'].pattern(rule, value, source, errors, options);
|
||||
if (rule.whitespace === true) {
|
||||
_rule2['default'].whitespace(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = string;
|
|
@ -1,31 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function type(rule, value, callback, source, options) {
|
||||
var ruleType = rule.type;
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value, ruleType) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options, ruleType);
|
||||
if (!(0, _util.isEmptyValue)(value, ruleType)) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = type;
|
|
@ -1,297 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _util = require('./util');
|
||||
|
||||
var _validator = require('./validator/');
|
||||
|
||||
var _validator2 = _interopRequireDefault(_validator);
|
||||
|
||||
var _messages2 = require('./messages');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Encapsulates a validation schema.
|
||||
*
|
||||
* @param descriptor An object declaring validation rules
|
||||
* for this schema.
|
||||
*/
|
||||
function Schema(descriptor) {
|
||||
this.rules = null;
|
||||
this._messages = _messages2.messages;
|
||||
this.define(descriptor);
|
||||
}
|
||||
|
||||
Schema.prototype = {
|
||||
messages: function messages(_messages) {
|
||||
if (_messages) {
|
||||
this._messages = (0, _util.deepMerge)((0, _messages2.newMessages)(), _messages);
|
||||
}
|
||||
return this._messages;
|
||||
},
|
||||
define: function define(rules) {
|
||||
if (!rules) {
|
||||
throw new Error('Cannot configure a schema with no rules');
|
||||
}
|
||||
if ((typeof rules === 'undefined' ? 'undefined' : _typeof(rules)) !== 'object' || Array.isArray(rules)) {
|
||||
throw new Error('Rules must be an object');
|
||||
}
|
||||
this.rules = {};
|
||||
var z = void 0;
|
||||
var item = void 0;
|
||||
for (z in rules) {
|
||||
if (rules.hasOwnProperty(z)) {
|
||||
item = rules[z];
|
||||
this.rules[z] = Array.isArray(item) ? item : [item];
|
||||
}
|
||||
}
|
||||
},
|
||||
validate: function validate(source_) {
|
||||
var _this = this;
|
||||
|
||||
var o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var oc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
|
||||
|
||||
var source = source_;
|
||||
var options = o;
|
||||
var callback = oc;
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
if (!this.rules || Object.keys(this.rules).length === 0) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function complete(results) {
|
||||
var i = void 0;
|
||||
var errors = [];
|
||||
var fields = {};
|
||||
|
||||
function add(e) {
|
||||
if (Array.isArray(e)) {
|
||||
var _errors;
|
||||
|
||||
errors = (_errors = errors).concat.apply(_errors, e);
|
||||
} else {
|
||||
errors.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < results.length; i++) {
|
||||
add(results[i]);
|
||||
}
|
||||
if (!errors.length) {
|
||||
errors = null;
|
||||
fields = null;
|
||||
} else {
|
||||
fields = (0, _util.convertFieldsError)(errors);
|
||||
}
|
||||
callback(errors, fields);
|
||||
}
|
||||
|
||||
if (options.messages) {
|
||||
var messages = this.messages();
|
||||
if (messages === _messages2.messages) {
|
||||
messages = (0, _messages2.newMessages)();
|
||||
}
|
||||
(0, _util.deepMerge)(messages, options.messages);
|
||||
options.messages = messages;
|
||||
} else {
|
||||
options.messages = this.messages();
|
||||
}
|
||||
var arr = void 0;
|
||||
var value = void 0;
|
||||
var series = {};
|
||||
var keys = options.keys || Object.keys(this.rules);
|
||||
keys.forEach(function (z) {
|
||||
arr = _this.rules[z];
|
||||
value = source[z];
|
||||
arr.forEach(function (r) {
|
||||
var rule = r;
|
||||
if (typeof rule.transform === 'function') {
|
||||
if (source === source_) {
|
||||
source = _extends({}, source);
|
||||
}
|
||||
value = source[z] = rule.transform(value);
|
||||
}
|
||||
if (typeof rule === 'function') {
|
||||
rule = {
|
||||
validator: rule
|
||||
};
|
||||
} else {
|
||||
rule = _extends({}, rule);
|
||||
}
|
||||
rule.validator = _this.getValidationMethod(rule);
|
||||
rule.field = z;
|
||||
rule.fullField = rule.fullField || z;
|
||||
rule.type = _this.getType(rule);
|
||||
if (!rule.validator) {
|
||||
return;
|
||||
}
|
||||
series[z] = series[z] || [];
|
||||
series[z].push({
|
||||
rule: rule,
|
||||
value: value,
|
||||
source: source,
|
||||
field: z
|
||||
});
|
||||
});
|
||||
});
|
||||
var errorFields = {};
|
||||
return (0, _util.asyncMap)(series, options, function (data, doIt) {
|
||||
var rule = data.rule;
|
||||
var deep = (rule.type === 'object' || rule.type === 'array') && (_typeof(rule.fields) === 'object' || _typeof(rule.defaultField) === 'object');
|
||||
deep = deep && (rule.required || !rule.required && data.value);
|
||||
rule.field = data.field;
|
||||
|
||||
function addFullfield(key, schema) {
|
||||
return _extends({}, schema, {
|
||||
fullField: rule.fullField + '.' + key
|
||||
});
|
||||
}
|
||||
|
||||
function cb() {
|
||||
var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
||||
|
||||
var errors = e;
|
||||
if (!Array.isArray(errors)) {
|
||||
errors = [errors];
|
||||
}
|
||||
if (!options.suppressWarning && errors.length) {
|
||||
Schema.warning('async-validator:', errors);
|
||||
}
|
||||
if (errors.length && rule.message) {
|
||||
errors = [].concat(rule.message);
|
||||
}
|
||||
|
||||
errors = errors.map((0, _util.complementError)(rule));
|
||||
|
||||
if (options.first && errors.length) {
|
||||
errorFields[rule.field] = 1;
|
||||
return doIt(errors);
|
||||
}
|
||||
if (!deep) {
|
||||
doIt(errors);
|
||||
} else {
|
||||
// if rule is required but the target object
|
||||
// does not exist fail at the rule level and don't
|
||||
// go deeper
|
||||
if (rule.required && !data.value) {
|
||||
if (rule.message) {
|
||||
errors = [].concat(rule.message).map((0, _util.complementError)(rule));
|
||||
} else if (options.error) {
|
||||
errors = [options.error(rule, (0, _util.format)(options.messages.required, rule.field))];
|
||||
} else {
|
||||
errors = [];
|
||||
}
|
||||
return doIt(errors);
|
||||
}
|
||||
|
||||
var fieldsSchema = {};
|
||||
if (rule.defaultField) {
|
||||
for (var k in data.value) {
|
||||
if (data.value.hasOwnProperty(k)) {
|
||||
fieldsSchema[k] = rule.defaultField;
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldsSchema = _extends({}, fieldsSchema, data.rule.fields);
|
||||
for (var f in fieldsSchema) {
|
||||
if (fieldsSchema.hasOwnProperty(f)) {
|
||||
var fieldSchema = Array.isArray(fieldsSchema[f]) ? fieldsSchema[f] : [fieldsSchema[f]];
|
||||
fieldsSchema[f] = fieldSchema.map(addFullfield.bind(null, f));
|
||||
}
|
||||
}
|
||||
var schema = new Schema(fieldsSchema);
|
||||
schema.messages(options.messages);
|
||||
if (data.rule.options) {
|
||||
data.rule.options.messages = options.messages;
|
||||
data.rule.options.error = options.error;
|
||||
}
|
||||
schema.validate(data.value, data.rule.options || options, function (errs) {
|
||||
var finalErrors = [];
|
||||
if (errors && errors.length) {
|
||||
finalErrors.push.apply(finalErrors, errors);
|
||||
}
|
||||
if (errs && errs.length) {
|
||||
finalErrors.push.apply(finalErrors, errs);
|
||||
}
|
||||
doIt(finalErrors.length ? finalErrors : null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var res = void 0;
|
||||
if (rule.asyncValidator) {
|
||||
res = rule.asyncValidator(rule, data.value, cb, data.source, options);
|
||||
} else if (rule.validator) {
|
||||
res = rule.validator(rule, data.value, cb, data.source, options);
|
||||
if (res === true) {
|
||||
cb();
|
||||
} else if (res === false) {
|
||||
cb(rule.message || rule.field + ' fails');
|
||||
} else if (res instanceof Array) {
|
||||
cb(res);
|
||||
} else if (res instanceof Error) {
|
||||
cb(res.message);
|
||||
}
|
||||
}
|
||||
if (res && res.then) {
|
||||
res.then(function () {
|
||||
return cb();
|
||||
}, function (e) {
|
||||
return cb(e);
|
||||
});
|
||||
}
|
||||
}, function (results) {
|
||||
complete(results);
|
||||
});
|
||||
},
|
||||
getType: function getType(rule) {
|
||||
if (rule.type === undefined && rule.pattern instanceof RegExp) {
|
||||
rule.type = 'pattern';
|
||||
}
|
||||
if (typeof rule.validator !== 'function' && rule.type && !_validator2['default'].hasOwnProperty(rule.type)) {
|
||||
throw new Error((0, _util.format)('Unknown rule type %s', rule.type));
|
||||
}
|
||||
return rule.type || 'string';
|
||||
},
|
||||
getValidationMethod: function getValidationMethod(rule) {
|
||||
if (typeof rule.validator === 'function') {
|
||||
return rule.validator;
|
||||
}
|
||||
var keys = Object.keys(rule);
|
||||
var messageIndex = keys.indexOf('message');
|
||||
if (messageIndex !== -1) {
|
||||
keys.splice(messageIndex, 1);
|
||||
}
|
||||
if (keys.length === 1 && keys[0] === 'required') {
|
||||
return _validator2['default'].required;
|
||||
}
|
||||
return _validator2['default'][this.getType(rule)] || false;
|
||||
}
|
||||
};
|
||||
|
||||
Schema.register = function register(type, validator) {
|
||||
if (typeof validator !== 'function') {
|
||||
throw new Error('Cannot register a validator by type, validator is not a function');
|
||||
}
|
||||
_validator2['default'][type] = validator;
|
||||
};
|
||||
|
||||
Schema.warning = _util.warning;
|
||||
|
||||
Schema.messages = _messages2.messages;
|
||||
|
||||
exports['default'] = Schema;
|
||||
module.exports = exports['default'];
|
|
@ -1,60 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.newMessages = newMessages;
|
||||
function newMessages() {
|
||||
return {
|
||||
'default': 'Validation error on field %s',
|
||||
required: '%s is required',
|
||||
'enum': '%s must be one of %s',
|
||||
whitespace: '%s cannot be empty',
|
||||
date: {
|
||||
format: '%s date %s is invalid for format %s',
|
||||
parse: '%s date could not be parsed, %s is invalid ',
|
||||
invalid: '%s date %s is invalid'
|
||||
},
|
||||
types: {
|
||||
string: '%s is not a %s',
|
||||
method: '%s is not a %s (function)',
|
||||
array: '%s is not an %s',
|
||||
object: '%s is not an %s',
|
||||
number: '%s is not a %s',
|
||||
date: '%s is not a %s',
|
||||
boolean: '%s is not a %s',
|
||||
integer: '%s is not an %s',
|
||||
float: '%s is not a %s',
|
||||
regexp: '%s is not a valid %s',
|
||||
email: '%s is not a valid %s',
|
||||
url: '%s is not a valid %s',
|
||||
hex: '%s is not a valid %s'
|
||||
},
|
||||
string: {
|
||||
len: '%s must be exactly %s characters',
|
||||
min: '%s must be at least %s characters',
|
||||
max: '%s cannot be longer than %s characters',
|
||||
range: '%s must be between %s and %s characters'
|
||||
},
|
||||
number: {
|
||||
len: '%s must equal %s',
|
||||
min: '%s cannot be less than %s',
|
||||
max: '%s cannot be greater than %s',
|
||||
range: '%s must be between %s and %s'
|
||||
},
|
||||
array: {
|
||||
len: '%s must be exactly %s in length',
|
||||
min: '%s cannot be less than %s in length',
|
||||
max: '%s cannot be greater than %s in length',
|
||||
range: '%s must be between %s and %s in length'
|
||||
},
|
||||
pattern: {
|
||||
mismatch: '%s value %s does not match pattern %s'
|
||||
},
|
||||
clone: function clone() {
|
||||
var cloned = JSON.parse(JSON.stringify(this));
|
||||
cloned.clone = this.clone;
|
||||
return cloned;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var messages = exports.messages = newMessages();
|
|
@ -1,32 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
var ENUM = 'enum';
|
||||
|
||||
/**
|
||||
* Rule for validating a value exists in an enumerable list.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function enumerable(rule, value, source, errors, options) {
|
||||
rule[ENUM] = Array.isArray(rule[ENUM]) ? rule[ENUM] : [];
|
||||
if (rule[ENUM].indexOf(value) === -1) {
|
||||
errors.push(util.format(options.messages[ENUM], rule.fullField, rule[ENUM].join(', ')));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = enumerable;
|
||||
module.exports = exports['default'];
|
|
@ -1,39 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _required = require('./required');
|
||||
|
||||
var _required2 = _interopRequireDefault(_required);
|
||||
|
||||
var _whitespace = require('./whitespace');
|
||||
|
||||
var _whitespace2 = _interopRequireDefault(_whitespace);
|
||||
|
||||
var _type = require('./type');
|
||||
|
||||
var _type2 = _interopRequireDefault(_type);
|
||||
|
||||
var _range = require('./range');
|
||||
|
||||
var _range2 = _interopRequireDefault(_range);
|
||||
|
||||
var _enum = require('./enum');
|
||||
|
||||
var _enum2 = _interopRequireDefault(_enum);
|
||||
|
||||
var _pattern = require('./pattern');
|
||||
|
||||
var _pattern2 = _interopRequireDefault(_pattern);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
exports['default'] = {
|
||||
required: _required2['default'],
|
||||
whitespace: _whitespace2['default'],
|
||||
type: _type2['default'],
|
||||
range: _range2['default'],
|
||||
'enum': _enum2['default'],
|
||||
pattern: _pattern2['default']
|
||||
};
|
||||
module.exports = exports['default'];
|
|
@ -1,42 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating a regular expression pattern.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function pattern(rule, value, source, errors, options) {
|
||||
if (rule.pattern) {
|
||||
if (rule.pattern instanceof RegExp) {
|
||||
// if a RegExp instance is passed, reset `lastIndex` in case its `global`
|
||||
// flag is accidentally set to `true`, which in a validation scenario
|
||||
// is not necessary and the result might be misleading
|
||||
rule.pattern.lastIndex = 0;
|
||||
if (!rule.pattern.test(value)) {
|
||||
errors.push(util.format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
||||
}
|
||||
} else if (typeof rule.pattern === 'string') {
|
||||
var _pattern = new RegExp(rule.pattern);
|
||||
if (!_pattern.test(value)) {
|
||||
errors.push(util.format(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = pattern;
|
||||
module.exports = exports['default'];
|
|
@ -1,67 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating minimum and maximum allowed values.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function range(rule, value, source, errors, options) {
|
||||
var len = typeof rule.len === 'number';
|
||||
var min = typeof rule.min === 'number';
|
||||
var max = typeof rule.max === 'number';
|
||||
// 正则匹配码点范围从U+010000一直到U+10FFFF的文字(补充平面Supplementary Plane)
|
||||
var spRegexp = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
var val = value;
|
||||
var key = null;
|
||||
var num = typeof value === 'number';
|
||||
var str = typeof value === 'string';
|
||||
var arr = Array.isArray(value);
|
||||
if (num) {
|
||||
key = 'number';
|
||||
} else if (str) {
|
||||
key = 'string';
|
||||
} else if (arr) {
|
||||
key = 'array';
|
||||
}
|
||||
// if the value is not of a supported type for range validation
|
||||
// the validation rule rule should use the
|
||||
// type property to also test for a particular type
|
||||
if (!key) {
|
||||
return false;
|
||||
}
|
||||
if (arr) {
|
||||
val = value.length;
|
||||
}
|
||||
if (str) {
|
||||
// 处理码点大于U+010000的文字length属性不准确的bug,如"𠮷𠮷𠮷".lenght !== 3
|
||||
val = value.replace(spRegexp, '_').length;
|
||||
}
|
||||
if (len) {
|
||||
if (val !== rule.len) {
|
||||
errors.push(util.format(options.messages[key].len, rule.fullField, rule.len));
|
||||
}
|
||||
} else if (min && !max && val < rule.min) {
|
||||
errors.push(util.format(options.messages[key].min, rule.fullField, rule.min));
|
||||
} else if (max && !min && val > rule.max) {
|
||||
errors.push(util.format(options.messages[key].max, rule.fullField, rule.max));
|
||||
} else if (min && max && (val < rule.min || val > rule.max)) {
|
||||
errors.push(util.format(options.messages[key].range, rule.fullField, rule.min, rule.max));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = range;
|
||||
module.exports = exports['default'];
|
|
@ -1,29 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating required fields.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function required(rule, value, source, errors, options, type) {
|
||||
if (rule.required && (!source.hasOwnProperty(rule.field) || util.isEmptyValue(value, type || rule.type))) {
|
||||
errors.push(util.format(options.messages.required, rule.fullField));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = required;
|
||||
module.exports = exports['default'];
|
|
@ -1,103 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
var _required = require('./required');
|
||||
|
||||
var _required2 = _interopRequireDefault(_required);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/* eslint max-len:0 */
|
||||
|
||||
var pattern = {
|
||||
// http://emailregex.com/
|
||||
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
||||
url: new RegExp('^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$', 'i'),
|
||||
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
|
||||
};
|
||||
|
||||
var types = {
|
||||
integer: function integer(value) {
|
||||
return types.number(value) && parseInt(value, 10) === value;
|
||||
},
|
||||
float: function float(value) {
|
||||
return types.number(value) && !types.integer(value);
|
||||
},
|
||||
array: function array(value) {
|
||||
return Array.isArray(value);
|
||||
},
|
||||
regexp: function regexp(value) {
|
||||
if (value instanceof RegExp) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
return !!new RegExp(value);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
date: function date(value) {
|
||||
return typeof value.getTime === 'function' && typeof value.getMonth === 'function' && typeof value.getYear === 'function';
|
||||
},
|
||||
number: function number(value) {
|
||||
if (isNaN(value)) {
|
||||
return false;
|
||||
}
|
||||
return typeof value === 'number';
|
||||
},
|
||||
object: function object(value) {
|
||||
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && !types.array(value);
|
||||
},
|
||||
method: function method(value) {
|
||||
return typeof value === 'function';
|
||||
},
|
||||
email: function email(value) {
|
||||
return typeof value === 'string' && !!value.match(pattern.email) && value.length < 255;
|
||||
},
|
||||
url: function url(value) {
|
||||
return typeof value === 'string' && !!value.match(pattern.url);
|
||||
},
|
||||
hex: function hex(value) {
|
||||
return typeof value === 'string' && !!value.match(pattern.hex);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Rule for validating the type of a value.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function type(rule, value, source, errors, options) {
|
||||
if (rule.required && value === undefined) {
|
||||
(0, _required2['default'])(rule, value, source, errors, options);
|
||||
return;
|
||||
}
|
||||
var custom = ['integer', 'float', 'array', 'regexp', 'object', 'method', 'email', 'number', 'date', 'url', 'hex'];
|
||||
var ruleType = rule.type;
|
||||
if (custom.indexOf(ruleType) > -1) {
|
||||
if (!types[ruleType](value)) {
|
||||
errors.push(util.format(options.messages.types[ruleType], rule.fullField, rule.type));
|
||||
}
|
||||
// straight typeof check
|
||||
} else if (ruleType && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== rule.type) {
|
||||
errors.push(util.format(options.messages.types[ruleType], rule.fullField, rule.type));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = type;
|
||||
module.exports = exports['default'];
|
|
@ -1,29 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var util = _interopRequireWildcard(_util);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||
|
||||
/**
|
||||
* Rule for validating whitespace.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param source The source object being validated.
|
||||
* @param errors An array of errors that this rule may add
|
||||
* validation errors to.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function whitespace(rule, value, source, errors, options) {
|
||||
if (/^\s+$/.test(value) || value === '') {
|
||||
errors.push(util.format(options.messages.whitespace, rule.fullField));
|
||||
}
|
||||
}
|
||||
|
||||
exports['default'] = whitespace;
|
||||
module.exports = exports['default'];
|
|
@ -1,221 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
exports.convertFieldsError = convertFieldsError;
|
||||
exports.format = format;
|
||||
exports.isEmptyValue = isEmptyValue;
|
||||
exports.isEmptyObject = isEmptyObject;
|
||||
exports.asyncMap = asyncMap;
|
||||
exports.complementError = complementError;
|
||||
exports.deepMerge = deepMerge;
|
||||
/* eslint no-console:0 */
|
||||
|
||||
var formatRegExp = /%[sdj%]/g;
|
||||
|
||||
var warning = exports.warning = function warning() {};
|
||||
|
||||
// don't print warning message when in production env or node runtime
|
||||
if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
exports.warning = warning = function warning(type, errors) {
|
||||
if (typeof console !== 'undefined' && console.warn) {
|
||||
if (errors.every(function (e) {
|
||||
return typeof e === 'string';
|
||||
})) {
|
||||
console.warn(type, errors);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function convertFieldsError(errors) {
|
||||
if (!errors || !errors.length) return null;
|
||||
var fields = {};
|
||||
errors.forEach(function (error) {
|
||||
var field = error.field;
|
||||
fields[field] = fields[field] || [];
|
||||
fields[field].push(error);
|
||||
});
|
||||
return fields;
|
||||
}
|
||||
|
||||
function format() {
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
var i = 1;
|
||||
var f = args[0];
|
||||
var len = args.length;
|
||||
if (typeof f === 'function') {
|
||||
return f.apply(null, args.slice(1));
|
||||
}
|
||||
if (typeof f === 'string') {
|
||||
var str = String(f).replace(formatRegExp, function (x) {
|
||||
if (x === '%%') {
|
||||
return '%';
|
||||
}
|
||||
if (i >= len) {
|
||||
return x;
|
||||
}
|
||||
switch (x) {
|
||||
case '%s':
|
||||
return String(args[i++]);
|
||||
case '%d':
|
||||
return Number(args[i++]);
|
||||
case '%j':
|
||||
try {
|
||||
return JSON.stringify(args[i++]);
|
||||
} catch (_) {
|
||||
return '[Circular]';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return x;
|
||||
}
|
||||
});
|
||||
for (var arg = args[i]; i < len; arg = args[++i]) {
|
||||
str += ' ' + arg;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
function isNativeStringType(type) {
|
||||
return type === 'string' || type === 'url' || type === 'hex' || type === 'email' || type === 'pattern';
|
||||
}
|
||||
|
||||
function isEmptyValue(value, type) {
|
||||
if (value === undefined || value === null) {
|
||||
return true;
|
||||
}
|
||||
if (type === 'array' && Array.isArray(value) && !value.length) {
|
||||
return true;
|
||||
}
|
||||
if (isNativeStringType(type) && typeof value === 'string' && !value) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isEmptyObject(obj) {
|
||||
return Object.keys(obj).length === 0;
|
||||
}
|
||||
|
||||
function asyncParallelArray(arr, func, callback) {
|
||||
var results = [];
|
||||
var total = 0;
|
||||
var arrLength = arr.length;
|
||||
|
||||
function count(errors) {
|
||||
results.push.apply(results, errors);
|
||||
total++;
|
||||
if (total === arrLength) {
|
||||
callback(results);
|
||||
}
|
||||
}
|
||||
|
||||
arr.forEach(function (a) {
|
||||
func(a, count);
|
||||
});
|
||||
}
|
||||
|
||||
function asyncSerialArray(arr, func, callback) {
|
||||
var index = 0;
|
||||
var arrLength = arr.length;
|
||||
|
||||
function next(errors) {
|
||||
if (errors && errors.length) {
|
||||
callback(errors);
|
||||
return;
|
||||
}
|
||||
var original = index;
|
||||
index = index + 1;
|
||||
if (original < arrLength) {
|
||||
func(arr[original], next);
|
||||
} else {
|
||||
callback([]);
|
||||
}
|
||||
}
|
||||
|
||||
next([]);
|
||||
}
|
||||
|
||||
function flattenObjArr(objArr) {
|
||||
var ret = [];
|
||||
Object.keys(objArr).forEach(function (k) {
|
||||
ret.push.apply(ret, objArr[k]);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
function asyncMap(objArr, option, func, callback) {
|
||||
if (option.first) {
|
||||
var flattenArr = flattenObjArr(objArr);
|
||||
return asyncSerialArray(flattenArr, func, callback);
|
||||
}
|
||||
var firstFields = option.firstFields || [];
|
||||
if (firstFields === true) {
|
||||
firstFields = Object.keys(objArr);
|
||||
}
|
||||
var objArrKeys = Object.keys(objArr);
|
||||
var objArrLength = objArrKeys.length;
|
||||
var total = 0;
|
||||
var results = [];
|
||||
var pending = new Promise(function (resolve, reject) {
|
||||
var next = function next(errors) {
|
||||
results.push.apply(results, errors);
|
||||
total++;
|
||||
if (total === objArrLength) {
|
||||
callback(results);
|
||||
return results.length ? reject({ errors: results, fields: convertFieldsError(results) }) : resolve();
|
||||
}
|
||||
};
|
||||
objArrKeys.forEach(function (key) {
|
||||
var arr = objArr[key];
|
||||
if (firstFields.indexOf(key) !== -1) {
|
||||
asyncSerialArray(arr, func, next);
|
||||
} else {
|
||||
asyncParallelArray(arr, func, next);
|
||||
}
|
||||
});
|
||||
});
|
||||
pending['catch'](function (e) {
|
||||
return e;
|
||||
});
|
||||
return pending;
|
||||
}
|
||||
|
||||
function complementError(rule) {
|
||||
return function (oe) {
|
||||
if (oe && oe.message) {
|
||||
oe.field = oe.field || rule.fullField;
|
||||
return oe;
|
||||
}
|
||||
return {
|
||||
message: typeof oe === 'function' ? oe() : oe,
|
||||
field: oe.field || rule.fullField
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function deepMerge(target, source) {
|
||||
if (source) {
|
||||
for (var s in source) {
|
||||
if (source.hasOwnProperty(s)) {
|
||||
var value = source[s];
|
||||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && _typeof(target[s]) === 'object') {
|
||||
target[s] = _extends({}, target[s], value);
|
||||
} else {
|
||||
target[s] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates an array.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function array(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value, 'array') && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options, 'array');
|
||||
if (!(0, _util.isEmptyValue)(value, 'array')) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = array;
|
||||
module.exports = exports['default'];
|
|
@ -1,39 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a boolean.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function boolean(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = boolean;
|
||||
module.exports = exports['default'];
|
|
@ -1,42 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function date(rule, value, callback, source, options) {
|
||||
// console.log('integer rule called %j', rule);
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
// console.log('validate on %s value', value);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (!(0, _util.isEmptyValue)(value)) {
|
||||
var dateObject = void 0;
|
||||
|
||||
if (typeof value === 'number') {
|
||||
dateObject = new Date(value);
|
||||
} else {
|
||||
dateObject = value;
|
||||
}
|
||||
|
||||
_rule2['default'].type(rule, dateObject, source, errors, options);
|
||||
if (dateObject) {
|
||||
_rule2['default'].range(rule, dateObject.getTime(), source, errors, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = date;
|
||||
module.exports = exports['default'];
|
|
@ -1,41 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
var ENUM = 'enum';
|
||||
|
||||
/**
|
||||
* Validates an enumerable list.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function enumerable(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value) {
|
||||
_rule2['default'][ENUM](rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = enumerable;
|
||||
module.exports = exports['default'];
|
|
@ -1,40 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a number is a floating point number.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function floatFn(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = floatFn;
|
||||
module.exports = exports['default'];
|
|
@ -1,81 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _string = require('./string');
|
||||
|
||||
var _string2 = _interopRequireDefault(_string);
|
||||
|
||||
var _method = require('./method');
|
||||
|
||||
var _method2 = _interopRequireDefault(_method);
|
||||
|
||||
var _number = require('./number');
|
||||
|
||||
var _number2 = _interopRequireDefault(_number);
|
||||
|
||||
var _boolean = require('./boolean');
|
||||
|
||||
var _boolean2 = _interopRequireDefault(_boolean);
|
||||
|
||||
var _regexp = require('./regexp');
|
||||
|
||||
var _regexp2 = _interopRequireDefault(_regexp);
|
||||
|
||||
var _integer = require('./integer');
|
||||
|
||||
var _integer2 = _interopRequireDefault(_integer);
|
||||
|
||||
var _float = require('./float');
|
||||
|
||||
var _float2 = _interopRequireDefault(_float);
|
||||
|
||||
var _array = require('./array');
|
||||
|
||||
var _array2 = _interopRequireDefault(_array);
|
||||
|
||||
var _object = require('./object');
|
||||
|
||||
var _object2 = _interopRequireDefault(_object);
|
||||
|
||||
var _enum = require('./enum');
|
||||
|
||||
var _enum2 = _interopRequireDefault(_enum);
|
||||
|
||||
var _pattern = require('./pattern');
|
||||
|
||||
var _pattern2 = _interopRequireDefault(_pattern);
|
||||
|
||||
var _date = require('./date');
|
||||
|
||||
var _date2 = _interopRequireDefault(_date);
|
||||
|
||||
var _required = require('./required');
|
||||
|
||||
var _required2 = _interopRequireDefault(_required);
|
||||
|
||||
var _type = require('./type');
|
||||
|
||||
var _type2 = _interopRequireDefault(_type);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
exports['default'] = {
|
||||
string: _string2['default'],
|
||||
method: _method2['default'],
|
||||
number: _number2['default'],
|
||||
boolean: _boolean2['default'],
|
||||
regexp: _regexp2['default'],
|
||||
integer: _integer2['default'],
|
||||
float: _float2['default'],
|
||||
array: _array2['default'],
|
||||
object: _object2['default'],
|
||||
'enum': _enum2['default'],
|
||||
pattern: _pattern2['default'],
|
||||
date: _date2['default'],
|
||||
url: _type2['default'],
|
||||
hex: _type2['default'],
|
||||
email: _type2['default'],
|
||||
required: _required2['default']
|
||||
};
|
||||
module.exports = exports['default'];
|
|
@ -1,40 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a number is an integer.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function integer(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = integer;
|
||||
module.exports = exports['default'];
|
|
@ -1,39 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a function.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function method(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = method;
|
||||
module.exports = exports['default'];
|
|
@ -1,43 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a number.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function number(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if (value === '') {
|
||||
value = undefined;
|
||||
}
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = number;
|
||||
module.exports = exports['default'];
|
|
@ -1,39 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates an object.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function object(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (value !== undefined) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = object;
|
||||
module.exports = exports['default'];
|
|
@ -1,42 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates a regular expression pattern.
|
||||
*
|
||||
* Performs validation when a rule only contains
|
||||
* a pattern property but is not declared as a string type.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function pattern(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value, 'string') && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (!(0, _util.isEmptyValue)(value, 'string')) {
|
||||
_rule2['default'].pattern(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = pattern;
|
||||
module.exports = exports['default'];
|
|
@ -1,39 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Validates the regular expression type.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function regexp(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options);
|
||||
if (!(0, _util.isEmptyValue)(value)) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = regexp;
|
||||
module.exports = exports['default'];
|
|
@ -1,21 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function required(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var type = Array.isArray(value) ? 'array' : typeof value === 'undefined' ? 'undefined' : _typeof(value);
|
||||
_rule2['default'].required(rule, value, source, errors, options, type);
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = required;
|
||||
module.exports = exports['default'];
|
|
@ -1,44 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
/**
|
||||
* Performs validation for string types.
|
||||
*
|
||||
* @param rule The validation rule.
|
||||
* @param value The value of the field on the source object.
|
||||
* @param callback The callback function.
|
||||
* @param source The source object being validated.
|
||||
* @param options The validation options.
|
||||
* @param options.messages The validation messages.
|
||||
*/
|
||||
function string(rule, value, callback, source, options) {
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value, 'string') && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options, 'string');
|
||||
if (!(0, _util.isEmptyValue)(value, 'string')) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
_rule2['default'].range(rule, value, source, errors, options);
|
||||
_rule2['default'].pattern(rule, value, source, errors, options);
|
||||
if (rule.whitespace === true) {
|
||||
_rule2['default'].whitespace(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = string;
|
||||
module.exports = exports['default'];
|
|
@ -1,30 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _rule = require('../rule/');
|
||||
|
||||
var _rule2 = _interopRequireDefault(_rule);
|
||||
|
||||
var _util = require('../util');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
|
||||
function type(rule, value, callback, source, options) {
|
||||
var ruleType = rule.type;
|
||||
var errors = [];
|
||||
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
||||
if (validate) {
|
||||
if ((0, _util.isEmptyValue)(value, ruleType) && !rule.required) {
|
||||
return callback();
|
||||
}
|
||||
_rule2['default'].required(rule, value, source, errors, options, ruleType);
|
||||
if (!(0, _util.isEmptyValue)(value, ruleType)) {
|
||||
_rule2['default'].type(rule, value, source, errors, options);
|
||||
}
|
||||
}
|
||||
callback(errors);
|
||||
}
|
||||
|
||||
exports['default'] = type;
|
||||
module.exports = exports['default'];
|
|
@ -1,83 +0,0 @@
|
|||
{
|
||||
"_from": "async-validator@^1.7.1",
|
||||
"_id": "async-validator@1.12.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-57EETfCPFiB7M4QscvQzWSGNsmtkjjzZv318SK1CBlstk+hycV72ocjriMOOM48HjvmoAoJGpJNjC7Z76RlnZA==",
|
||||
"_location": "/async-validator",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "async-validator@^1.7.1",
|
||||
"name": "async-validator",
|
||||
"escapedName": "async-validator",
|
||||
"rawSpec": "^1.7.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.7.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/uview"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/async-validator/-/async-validator-1.12.2.tgz",
|
||||
"_shasum": "beae671e7174d2938b7b4b69d2fb7e722b7fd72c",
|
||||
"_spec": "async-validator@^1.7.1",
|
||||
"_where": "/Users/ran/Desktop/宏业汇成/lili-shop-uniapp/node_modules/uview",
|
||||
"author": {
|
||||
"name": "yiminghe@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/yiminghe/async-validator/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"config": {
|
||||
"port": 8010
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "validate form asynchronous",
|
||||
"devDependencies": {
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"coveralls": "^2.13.1",
|
||||
"jest": "^23.6.0",
|
||||
"pre-commit": "1.x",
|
||||
"rc-tools": "7.x"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"es"
|
||||
],
|
||||
"homepage": "http://github.com/yiminghe/async-validator",
|
||||
"jest": {
|
||||
"collectCoverageFrom": [
|
||||
"src/*"
|
||||
],
|
||||
"transform": {
|
||||
"\\.jsx?$": "./node_modules/rc-tools/scripts/jestPreprocessor.js"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"validator",
|
||||
"validate",
|
||||
"async"
|
||||
],
|
||||
"licenses": "MIT",
|
||||
"main": "./lib/index",
|
||||
"module": "./es/index",
|
||||
"name": "async-validator",
|
||||
"pre-commit": [
|
||||
"lint"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/yiminghe/async-validator.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rc-tools run build",
|
||||
"coverage": "jest --coverage && cat ./coverage/lcov.info | coveralls",
|
||||
"gh-pages": "rc-tools run gh-pages",
|
||||
"lint": "rc-tools run lint",
|
||||
"pub": "rc-tools run pub",
|
||||
"start": "rc-tools run server",
|
||||
"test": "jest"
|
||||
},
|
||||
"version": "1.12.2"
|
||||
}
|
|
@ -1,706 +0,0 @@
|
|||
## Changelog
|
||||
##### 2.6.11 [LEGACY] - 2019.12.09
|
||||
- Returned usage of `node -e` in `postinstall` scripts for better cross-platform compatibility, [#582](https://github.com/zloirock/core-js/issues/582)
|
||||
- Improved CI detection in the `postinstall` script, [#707](https://github.com/zloirock/core-js/issues/707)
|
||||
|
||||
##### 2.6.10 [LEGACY] - 2019.10.13
|
||||
- Show similar `postinstall` messages only once per `npm i`, [#597](https://github.com/zloirock/core-js/issues/597)
|
||||
|
||||
##### 2.6.9 [LEGACY] - 2019.05.27
|
||||
- Some fixes and improvements of the `postinstall` script like support `npm` color config ([#556](https://github.com/zloirock/core-js/issues/556)) or adding support of `ADBLOCK` env variable
|
||||
|
||||
##### 2.6.8 [LEGACY] - 2019.05.22
|
||||
- Added a workaround of a strange `npx` bug on `postinstall`, [#551](https://github.com/zloirock/core-js/issues/551)
|
||||
|
||||
##### 2.6.7 [LEGACY] - 2019.05.21
|
||||
- Added one more workaround of alternative not completely correct `Symbol` polyfills, [#550](https://github.com/zloirock/core-js/issues/550), [#554](https://github.com/zloirock/core-js/issues/554)
|
||||
|
||||
##### 2.6.6 [LEGACY] - 2019.05.20
|
||||
- Fixed IE8- non-enumerable properties support in `Object.{ assign, entries, values }`, [#541](https://github.com/zloirock/core-js/issues/541)
|
||||
- Fixed support of primitives in `Object.getOwnPropertySymbols` in Chrome 38 / 39, [#539](https://github.com/zloirock/core-js/issues/539)
|
||||
- Show a message on `postinstall`
|
||||
|
||||
##### 2.6.5 - 2019.02.15
|
||||
- Fixed buggy `String#padStart` and `String#padEnd` mobile Safari implementations, [#414](https://github.com/zloirock/core-js/issues/414).
|
||||
|
||||
##### 2.6.4 - 2019.02.07
|
||||
- Added a workaround against crushing an old IE11.0.9600.16384 build, [#485](https://github.com/zloirock/core-js/issues/485).
|
||||
|
||||
##### 2.6.3 - 2019.01.22
|
||||
- Added a workaround for `babel-minify` bug, [#479](https://github.com/zloirock/core-js/issues/479)
|
||||
|
||||
##### 2.6.2 - 2019.01.10
|
||||
- Fixed handling of `$` in `String#replace`, [#471](https://github.com/zloirock/core-js/issues/471)
|
||||
|
||||
##### 2.6.1 - 2018.12.18
|
||||
- Fixed an issue with minified version, [#463](https://github.com/zloirock/core-js/issues/463)
|
||||
|
||||
##### 2.6.0 - 2018.12.05
|
||||
- Add direct .exec calling to `RegExp#{@@replace, @@split, @@match, @@search}`. Also, added fixes for `RegExp#exec` method. [#411](https://github.com/zloirock/core-js/issues/411), [#428](https://github.com/zloirock/core-js/issues/428), [#434](https://github.com/zloirock/core-js/issues/434), [#435](https://github.com/zloirock/core-js/issues/435), [#453](https://github.com/zloirock/core-js/issues/453), [#458](https://github.com/zloirock/core-js/issues/458), thanks [**@nicolo-ribaudo**](https://github.com/nicolo-ribaudo).
|
||||
|
||||
##### 2.5.7 - 2018.05.26
|
||||
- Get rid of reserved variable name `final`, related [#400](https://github.com/zloirock/core-js/issues/400)
|
||||
|
||||
##### 2.5.6 - 2018.05.07
|
||||
- Forced replace native `Promise` in V8 6.6 (Node 10 and Chrome 66) because of [a bug with resolving custom thenables](https://bugs.chromium.org/p/chromium/issues/detail?id=830565)
|
||||
- Added a workaround for usage buggy native LG WebOS 2 `Promise` in microtask implementation, [#396](https://github.com/zloirock/core-js/issues/396)
|
||||
- Added modern version internal debugging information about used versions
|
||||
|
||||
##### 2.5.5 - 2018.04.08
|
||||
- Fix some edge cases of `Reflect.set`, [#392](https://github.com/zloirock/core-js/issues/392) and [#393](https://github.com/zloirock/core-js/issues/393)
|
||||
|
||||
##### 2.5.4 - 2018.03.27
|
||||
- Fixed one case of deoptimization built-in iterators in V8, related [#377](https://github.com/zloirock/core-js/issues/377)
|
||||
- Fixed some cases of iterators feature detection, [#368](https://github.com/zloirock/core-js/issues/368)
|
||||
- Fixed manually entered NodeJS domains issue in `Promise`, [#367](https://github.com/zloirock/core-js/issues/367)
|
||||
- Fixed `Number.{parseInt, parseFloat}` entry points
|
||||
- Fixed `__(define|lookup)[GS]etter__` import in the `library` version
|
||||
|
||||
##### 2.5.3 - 2017.12.12
|
||||
- Fixed calling `onunhandledrejectionhandler` multiple times for one `Promise` chain, [#318](https://github.com/zloirock/core-js/issues/318)
|
||||
- Forced replacement of `String#{padStart, padEnd}` in Safari 10 because of [a bug](https://bugs.webkit.org/show_bug.cgi?id=161944), [#280](https://github.com/zloirock/core-js/issues/280)
|
||||
- Fixed `Array#@@iterator` in a very rare version of `WebKit`, [#236](https://github.com/zloirock/core-js/issues/236) and [#237](https://github.com/zloirock/core-js/issues/237)
|
||||
- One more [#345](https://github.com/zloirock/core-js/issues/345)-related fix
|
||||
|
||||
##### 2.5.2 - 2017.12.09
|
||||
- `MutationObserver` no longer used for microtask implementation in iOS Safari because of bug with scrolling, [#339](https://github.com/zloirock/core-js/issues/339)
|
||||
- Fixed `JSON.stringify(undefined, replacer)` case in the wrapper from the `Symbol` polyfill, [#345](https://github.com/zloirock/core-js/issues/345)
|
||||
- `Array()` calls changed to `new Array()` for V8 optimisation
|
||||
|
||||
##### 2.5.1 - 2017.09.01
|
||||
- Updated `Promise#finally` per [tc39/proposal-promise-finally#37](https://github.com/tc39/proposal-promise-finally/issues/37)
|
||||
- Optimized usage of some internal helpers for reducing size of `shim` version
|
||||
- Fixed some entry points for virtual methods
|
||||
|
||||
##### 2.5.0 - 2017.08.05
|
||||
- Added `Promise#finally` [stage 3 proposal](https://github.com/tc39/proposal-promise-finally), [#225](https://github.com/zloirock/core-js/issues/225)
|
||||
- Added `Promise.try` [stage 1 proposal](https://github.com/tc39/proposal-promise-try)
|
||||
- Added `Array#flatten` and `Array#flatMap` [stage 1 proposal](https://tc39.github.io/proposal-flatMap)
|
||||
- Added `.of` and `.from` methods on collection constructors [stage 1 proposal](https://github.com/tc39/proposal-setmap-offrom):
|
||||
- `Map.of`
|
||||
- `Set.of`
|
||||
- `WeakSet.of`
|
||||
- `WeakMap.of`
|
||||
- `Map.from`
|
||||
- `Set.from`
|
||||
- `WeakSet.from`
|
||||
- `WeakMap.from`
|
||||
- Added `Math` extensions [stage 1 proposal](https://github.com/rwaldron/proposal-math-extensions), [#226](https://github.com/zloirock/core-js/issues/226):
|
||||
- `Math.clamp`
|
||||
- `Math.DEG_PER_RAD`
|
||||
- `Math.degrees`
|
||||
- `Math.fscale`
|
||||
- `Math.RAD_PER_DEG`
|
||||
- `Math.radians`
|
||||
- `Math.scale`
|
||||
- Added `Math.signbit` [stage 1 proposal](http://jfbastien.github.io/papers/Math.signbit.html)
|
||||
- Updated `global` [stage 3 proposal](https://github.com/tc39/proposal-global) - added `global` global object, `System.global` deprecated
|
||||
- Updated `Object.getOwnPropertyDescriptors` to the [final version](https://tc39.github.io/ecma262/2017/#sec-object.getownpropertydescriptors) - it should not create properties if descriptors are `undefined`
|
||||
- Updated the list of iterable DOM collections, [#249](https://github.com/zloirock/core-js/issues/249), added:
|
||||
- `CSSStyleDeclaration#@@iterator`
|
||||
- `CSSValueList#@@iterator`
|
||||
- `ClientRectList#@@iterator`
|
||||
- `DOMRectList#@@iterator`
|
||||
- `DOMStringList#@@iterator`
|
||||
- `DataTransferItemList#@@iterator`
|
||||
- `FileList#@@iterator`
|
||||
- `HTMLAllCollection#@@iterator`
|
||||
- `HTMLCollection#@@iterator`
|
||||
- `HTMLFormElement#@@iterator`
|
||||
- `HTMLSelectElement#@@iterator`
|
||||
- `MimeTypeArray#@@iterator`
|
||||
- `NamedNodeMap#@@iterator`
|
||||
- `PaintRequestList#@@iterator`
|
||||
- `Plugin#@@iterator`
|
||||
- `PluginArray#@@iterator`
|
||||
- `SVGLengthList#@@iterator`
|
||||
- `SVGNumberList#@@iterator`
|
||||
- `SVGPathSegList#@@iterator`
|
||||
- `SVGPointList#@@iterator`
|
||||
- `SVGStringList#@@iterator`
|
||||
- `SVGTransformList#@@iterator`
|
||||
- `SourceBufferList#@@iterator`
|
||||
- `TextTrackCueList#@@iterator`
|
||||
- `TextTrackList#@@iterator`
|
||||
- `TouchList#@@iterator`
|
||||
- Updated stages of proposals:
|
||||
- [`Object.getOwnPropertyDescriptors`](https://github.com/tc39/proposal-object-getownpropertydescriptors) to [stage 4 (ES2017)](https://tc39.github.io/ecma262/2017/#sec-object.getownpropertydescriptors)
|
||||
- [String padding](https://github.com/tc39/proposal-string-pad-start-end) to [stage 4 (ES2017)](https://tc39.github.io/ecma262/2017/#sec-string.prototype.padend)
|
||||
- [`global`](https://github.com/tc39/proposal-global) to [stage 3](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-09/sept-28.md#revisit-systemglobal--global)
|
||||
- [String trimming](https://github.com/tc39/proposal-string-left-right-trim) to [stage 2](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-07/jul-27.md#10iic-trimstarttrimend)
|
||||
- Updated typed arrays to the modern (ES2016+) arguments validation,
|
||||
[#293](https://github.com/zloirock/core-js/pull/293)
|
||||
- Fixed `%TypedArray%.from` Safari bug, [#285](https://github.com/zloirock/core-js/issues/285)
|
||||
- Fixed compatibility with old version of Prototype.js, [#278](https://github.com/zloirock/core-js/issues/278), [#289](https://github.com/zloirock/core-js/issues/289)
|
||||
- `Function#name` no longer cache the result for correct behaviour with inherited constructors, [#296](https://github.com/zloirock/core-js/issues/296)
|
||||
- Added errors on incorrect context of collection methods, [#272](https://github.com/zloirock/core-js/issues/272)
|
||||
- Fixed conversion typed array constructors to string, fix [#300](https://github.com/zloirock/core-js/issues/300)
|
||||
- Fixed `Set#size` with debugger ReactNative for Android, [#297](https://github.com/zloirock/core-js/issues/297)
|
||||
- Fixed an issue with Electron-based debugger, [#230](https://github.com/zloirock/core-js/issues/230)
|
||||
- Fixed compatibility with incomplete third-party `WeakMap` polyfills, [#252](https://github.com/zloirock/core-js/pull/252)
|
||||
- Added a fallback for `Date#toJSON` in engines without native `Date#toISOString`, [#220](https://github.com/zloirock/core-js/issues/220)
|
||||
- Added support for Sphere Dispatch API, [#286](https://github.com/zloirock/core-js/pull/286)
|
||||
- Seriously changed the coding style and the [ESLint config](https://github.com/zloirock/core-js/blob/master/.eslintrc.js)
|
||||
- Updated many dev dependencies (`webpack`, `uglify`, etc)
|
||||
- Some other minor fixes and optimizations
|
||||
|
||||
##### 2.4.1 - 2016.07.18
|
||||
- Fixed `script` tag for some parsers, [#204](https://github.com/zloirock/core-js/issues/204), [#216](https://github.com/zloirock/core-js/issues/216)
|
||||
- Removed some unused variables, [#217](https://github.com/zloirock/core-js/issues/217), [#218](https://github.com/zloirock/core-js/issues/218)
|
||||
- Fixed MS Edge `Reflect.construct` and `Reflect.apply` - they should not allow primitive as `argumentsList` argument
|
||||
|
||||
##### 1.2.7 [LEGACY] - 2016.07.18
|
||||
- Some fixes for issues like [#159](https://github.com/zloirock/core-js/issues/159), [#186](https://github.com/zloirock/core-js/issues/186), [#194](https://github.com/zloirock/core-js/issues/194), [#207](https://github.com/zloirock/core-js/issues/207)
|
||||
|
||||
##### 2.4.0 - 2016.05.08
|
||||
- Added `Observable`, [stage 1 proposal](https://github.com/zenparsing/es-observable)
|
||||
- Fixed behavior `Object.{getOwnPropertySymbols, getOwnPropertyDescriptor}` and `Object#propertyIsEnumerable` on `Object.prototype`
|
||||
- `Reflect.construct` and `Reflect.apply` should throw an error if `argumentsList` argument is not an object, [#194](https://github.com/zloirock/core-js/issues/194)
|
||||
|
||||
##### 2.3.0 - 2016.04.24
|
||||
- Added `asap` for enqueuing microtasks, [stage 0 proposal](https://github.com/rwaldron/tc39-notes/blob/master/es6/2014-09/sept-25.md#510-globalasap-for-enqueuing-a-microtask)
|
||||
- Added well-known symbol `Symbol.asyncIterator` for [stage 2 async iteration proposal](https://github.com/tc39/proposal-async-iteration)
|
||||
- Added well-known symbol `Symbol.observable` for [stage 1 observables proposal](https://github.com/zenparsing/es-observable)
|
||||
- `String#{padStart, padEnd}` returns original string if filler is empty string, [TC39 meeting notes](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-03/march-29.md#stringprototypepadstartpadend)
|
||||
- `Object.values` and `Object.entries` moved to stage 4 from 3, [TC39 meeting notes](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-03/march-29.md#objectvalues--objectentries)
|
||||
- `System.global` moved to stage 2 from 1, [TC39 meeting notes](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-03/march-29.md#systemglobal)
|
||||
- `Map#toJSON` and `Set#toJSON` rejected and will be removed from the next major release, [TC39 meeting notes](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-03/march-31.md#mapprototypetojsonsetprototypetojson)
|
||||
- `Error.isError` withdrawn and will be removed from the next major release, [TC39 meeting notes](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-03/march-29.md#erroriserror)
|
||||
- Added fallback for `Function#name` on non-extensible functions and functions with broken `toString` conversion, [#193](https://github.com/zloirock/core-js/issues/193)
|
||||
|
||||
##### 2.2.2 - 2016.04.06
|
||||
- Added conversion `-0` to `+0` to `Array#{indexOf, lastIndexOf}`, [ES2016 fix](https://github.com/tc39/ecma262/pull/316)
|
||||
- Added fixes for some `Math` methods in Tor Browser
|
||||
- `Array.{from, of}` no longer calls prototype setters
|
||||
- Added workaround over Chrome DevTools strange behavior, [#186](https://github.com/zloirock/core-js/issues/186)
|
||||
|
||||
##### 2.2.1 - 2016.03.19
|
||||
- Fixed `Object.getOwnPropertyNames(window)` `2.1+` versions bug, [#181](https://github.com/zloirock/core-js/issues/181)
|
||||
|
||||
##### 2.2.0 - 2016.03.15
|
||||
- Added `String#matchAll`, [proposal](https://github.com/tc39/String.prototype.matchAll)
|
||||
- Added `Object#__(define|lookup)[GS]etter__`, [annex B ES2017](https://github.com/tc39/ecma262/pull/381)
|
||||
- Added `@@toPrimitive` methods to `Date` and `Symbol`
|
||||
- Fixed `%TypedArray%#slice` in Edge ~ 13 (throws with `@@species` and wrapped / inherited constructor)
|
||||
- Some other minor fixes
|
||||
|
||||
##### 2.1.5 - 2016.03.12
|
||||
- Improved support NodeJS domains in `Promise#then`, [#180](https://github.com/zloirock/core-js/issues/180)
|
||||
- Added fallback for `Date#toJSON` bug in Qt Script, [#173](https://github.com/zloirock/core-js/issues/173#issuecomment-193972502)
|
||||
|
||||
##### 2.1.4 - 2016.03.08
|
||||
- Added fallback for `Symbol` polyfill in Qt Script, [#173](https://github.com/zloirock/core-js/issues/173)
|
||||
- Added one more fallback for IE11 `Script Access Denied` error with iframes, [#165](https://github.com/zloirock/core-js/issues/165)
|
||||
|
||||
##### 2.1.3 - 2016.02.29
|
||||
- Added fallback for [`es6-promise` package bug](https://github.com/stefanpenner/es6-promise/issues/169), [#176](https://github.com/zloirock/core-js/issues/176)
|
||||
|
||||
##### 2.1.2 - 2016.02.29
|
||||
- Some minor `Promise` fixes:
|
||||
- Browsers `rejectionhandled` event better HTML spec complaint
|
||||
- Errors in unhandled rejection handlers should not cause any problems
|
||||
- Fixed typo in feature detection
|
||||
|
||||
##### 2.1.1 - 2016.02.22
|
||||
- Some `Promise` improvements:
|
||||
- Feature detection:
|
||||
- **Added detection unhandled rejection tracking support - now it's available everywhere**, [#140](https://github.com/zloirock/core-js/issues/140)
|
||||
- Added detection `@@species` pattern support for completely correct subclassing
|
||||
- Removed usage `Object.setPrototypeOf` from feature detection and noisy console message about it in FF
|
||||
- `Promise.all` fixed for some very specific cases
|
||||
|
||||
##### 2.1.0 - 2016.02.09
|
||||
- **API**:
|
||||
- ES5 polyfills are split and logic, used in other polyfills, moved to internal modules
|
||||
- **All entry point works in ES3 environment like IE8- without `core-js/(library/)es5`**
|
||||
- **Added all missed single entry points for ES5 polyfills**
|
||||
- Separated ES5 polyfills moved to the ES6 namespace. Why?
|
||||
- Mainly, for prevent duplication features in different namespaces - logic of most required ES5 polyfills changed in ES6+:
|
||||
- Already added changes for: `Object` statics - should accept primitives, new whitespaces lists in `String#trim`, `parse(Int|float)`, `RegExp#toString` logic, `String#split`, etc
|
||||
- Should be changed in the future: `@@species` and `ToLength` logic in `Array` methods, `Date` parsing, `Function#bind`, etc
|
||||
- Should not be changed only several features like `Array.isArray` and `Date.now`
|
||||
- Some ES5 polyfills required for modern engines
|
||||
- All old entry points should work fine, but in the next major release API can be changed
|
||||
- `Object.getOwnPropertyDescriptors` moved to the stage 3, [January TC39 meeting](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-01/2016-01-28.md#objectgetownpropertydescriptors-to-stage-3-jordan-harband-low-priority-but-super-quick)
|
||||
- Added `umd` option for [custom build process](https://github.com/zloirock/core-js#custom-build-from-external-scripts), [#169](https://github.com/zloirock/core-js/issues/169)
|
||||
- Returned entry points for `Array` statics, removed in `2.0`, for compatibility with `babel` `6` and for future fixes
|
||||
- **Deprecated**:
|
||||
- `Reflect.enumerate` deprecated and will be removed from the next major release, [January TC39 meeting](https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-01/2016-01-28.md#5xix-revisit-proxy-enumerate---revisit-decision-to-exhaust-iterator)
|
||||
- **New Features**:
|
||||
- Added [`Reflect` metadata API](https://github.com/jonathandturner/decorators/blob/master/specs/metadata.md) as a pre-strawman feature, [#152](https://github.com/zloirock/core-js/issues/152):
|
||||
- `Reflect.defineMetadata`
|
||||
- `Reflect.deleteMetadata`
|
||||
- `Reflect.getMetadata`
|
||||
- `Reflect.getMetadataKeys`
|
||||
- `Reflect.getOwnMetadata`
|
||||
- `Reflect.getOwnMetadataKeys`
|
||||
- `Reflect.hasMetadata`
|
||||
- `Reflect.hasOwnMetadata`
|
||||
- `Reflect.metadata`
|
||||
- Implementation / fixes `Date#toJSON`
|
||||
- Fixes for `parseInt` and `Number.parseInt`
|
||||
- Fixes for `parseFloat` and `Number.parseFloat`
|
||||
- Fixes for `RegExp#toString`
|
||||
- Fixes for `Array#sort`
|
||||
- Fixes for `Number#toFixed`
|
||||
- Fixes for `Number#toPrecision`
|
||||
- Additional fixes for `String#split` (`RegExp#@@split`)
|
||||
- **Improvements**:
|
||||
- Correct subclassing wrapped collections, `Number` and `RegExp` constructors with native class syntax
|
||||
- Correct support `SharedArrayBuffer` and buffers from other realms in typed arrays wrappers
|
||||
- Additional validations for `Object.{defineProperty, getOwnPropertyDescriptor}` and `Reflect.defineProperty`
|
||||
- **Bug Fixes**:
|
||||
- Fixed some cases `Array#lastIndexOf` with negative second argument
|
||||
|
||||
##### 2.0.3 - 2016.01.11
|
||||
- Added fallback for V8 ~ Chrome 49 `Promise` subclassing bug causes unhandled rejection on feature detection, [#159](https://github.com/zloirock/core-js/issues/159)
|
||||
- Added fix for very specific environments with global `window === null`
|
||||
|
||||
##### 2.0.2 - 2016.01.04
|
||||
- Temporarily removed `length` validation from `Uint8Array` constructor wrapper. Reason - [bug in `ws` module](https://github.com/websockets/ws/pull/645) (-> `socket.io`) which passes to `Buffer` constructor -> `Uint8Array` float and uses [the `V8` bug](https://code.google.com/p/v8/issues/detail?id=4552) for conversion to int (by the spec should be thrown an error). [It creates problems for many people.](https://github.com/karma-runner/karma/issues/1768) I hope, it will be returned after fixing this bug in `V8`.
|
||||
|
||||
##### 2.0.1 - 2015.12.31
|
||||
- Forced usage `Promise.resolve` polyfill in the `library` version for correct work with wrapper
|
||||
- `Object.assign` should be defined in the strict mode -> throw an error on extension non-extensible objects, [#154](https://github.com/zloirock/core-js/issues/154)
|
||||
|
||||
##### 2.0.0 - 2015.12.24
|
||||
- Added implementations and fixes [Typed Arrays](https://github.com/zloirock/core-js#ecmascript-6-typed-arrays)-related features
|
||||
- `ArrayBuffer`, `ArrayBuffer.isView`, `ArrayBuffer#slice`
|
||||
- `DataView` with all getter / setter methods
|
||||
- `Int8Array`, `Uint8Array`, `Uint8ClampedArray`, `Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`, `Float32Array` and `Float64Array` constructors
|
||||
- `%TypedArray%.{for, of}`, `%TypedArray%#{copyWithin, every, fill, filter, find, findIndex, forEach, indexOf, includes, join, lastIndexOf, map, reduce, reduceRight, reverse, set, slice, some, sort, subarray, values, keys, entries, @@iterator, ...}`
|
||||
- Added [`System.global`](https://github.com/zloirock/core-js#ecmascript-7-proposals), [proposal](https://github.com/tc39/proposal-global), [November TC39 meeting](https://github.com/rwaldron/tc39-notes/tree/master/es7/2015-11/nov-19.md#systemglobal-jhd)
|
||||
- Added [`Error.isError`](https://github.com/zloirock/core-js#ecmascript-7-proposals), [proposal](https://github.com/ljharb/proposal-is-error), [November TC39 meeting](https://github.com/rwaldron/tc39-notes/tree/master/es7/2015-11/nov-19.md#jhd-erroriserror)
|
||||
- Added [`Math.{iaddh, isubh, imulh, umulh}`](https://github.com/zloirock/core-js#ecmascript-7-proposals), [proposal](https://gist.github.com/BrendanEich/4294d5c212a6d2254703)
|
||||
- `RegExp.escape` moved from the `es7` to the non-standard `core` namespace, [July TC39 meeting](https://github.com/rwaldron/tc39-notes/blob/master/es7/2015-07/july-28.md#62-regexpescape) - too slow, but it's condition of stability, [#116](https://github.com/zloirock/core-js/issues/116)
|
||||
- [`Promise`](https://github.com/zloirock/core-js#ecmascript-6-promise)
|
||||
- Some performance optimisations
|
||||
- Added basic support [`rejectionHandled` event / `onrejectionhandled` handler](https://github.com/zloirock/core-js#unhandled-rejection-tracking) to the polyfill
|
||||
- Removed usage `@@species` from `Promise.{all, race}`, [November TC39 meeting](https://github.com/rwaldron/tc39-notes/tree/master/es7/2015-11/nov-18.md#conclusionresolution-2)
|
||||
- Some improvements [collections polyfills](https://github.com/zloirock/core-js#ecmascript-6-collections)
|
||||
- `O(1)` and preventing possible leaks with frozen keys, [#134](https://github.com/zloirock/core-js/issues/134)
|
||||
- Correct observable state object keys
|
||||
- Renamed `String#{padLeft, padRight}` -> [`String#{padStart, padEnd}`](https://github.com/zloirock/core-js#ecmascript-7-proposals), [proposal](https://github.com/tc39/proposal-string-pad-start-end), [November TC39 meeting](https://github.com/rwaldron/tc39-notes/tree/master/es7/2015-11/nov-17.md#conclusionresolution-2) (they want to rename it on each meeting?O_o), [#132](https://github.com/zloirock/core-js/issues/132)
|
||||
- Added [`String#{trimStart, trimEnd}` as aliases for `String#{trimLeft, trimRight}`](https://github.com/zloirock/core-js#ecmascript-7-proposals), [proposal](https://github.com/sebmarkbage/ecmascript-string-left-right-trim), [November TC39 meeting](https://github.com/rwaldron/tc39-notes/tree/master/es7/2015-11/nov-17.md#conclusionresolution-2)
|
||||
- Added [annex B HTML methods](https://github.com/zloirock/core-js#ecmascript-6-string) - ugly, but also [the part of the spec](http://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.anchor)
|
||||
- Added little fix for [`Date#toString`](https://github.com/zloirock/core-js#ecmascript-6-date) - `new Date(NaN).toString()` [should be `'Invalid Date'`](http://www.ecma-international.org/ecma-262/6.0/#sec-todatestring)
|
||||
- Added [`{keys, values, entries, @@iterator}` methods to DOM collections](https://github.com/zloirock/core-js#iterable-dom-collections) which should have [iterable interface](https://heycam.github.io/webidl/#idl-iterable) or should be [inherited from `Array`](https://heycam.github.io/webidl/#LegacyArrayClass) - `NodeList`, `DOMTokenList`, `MediaList`, `StyleSheetList`, `CSSRuleList`.
|
||||
- Removed Mozilla `Array` generics - [deprecated and will be removed from FF](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Array_generic_methods), [looks like strawman is dead](http://wiki.ecmascript.org/doku.php?id=strawman:array_statics), available [alternative shim](https://github.com/plusdude/array-generics)
|
||||
- Removed `core.log` module
|
||||
- CommonJS API
|
||||
- Added entry points for [virtual methods](https://github.com/zloirock/core-js#commonjs-and-prototype-methods-without-global-namespace-pollution)
|
||||
- Added entry points for [stages proposals](https://github.com/zloirock/core-js#ecmascript-7-proposals)
|
||||
- Some other minor changes
|
||||
- [Custom build from external scripts](https://github.com/zloirock/core-js#custom-build-from-external-scripts) moved to the separate package for preventing problems with dependencies
|
||||
- Changed `$` prefix for internal modules file names because Team Foundation Server does not support it, [#129](https://github.com/zloirock/core-js/issues/129)
|
||||
- Additional fix for `SameValueZero` in V8 ~ Chromium 39-42 collections
|
||||
- Additional fix for FF27 `Array` iterator
|
||||
- Removed usage shortcuts for `arguments` object - old WebKit bug, [#150](https://github.com/zloirock/core-js/issues/150)
|
||||
- `{Map, Set}#forEach` non-generic, [#144](https://github.com/zloirock/core-js/issues/144)
|
||||
- Many other improvements
|
||||
|
||||
##### 1.2.6 - 2015.11.09
|
||||
* Reject with `TypeError` on attempt resolve promise itself
|
||||
* Correct behavior with broken `Promise` subclass constructors / methods
|
||||
* Added `Promise`-based fallback for microtask
|
||||
* Fixed V8 and FF `Array#{values, @@iterator}.name`
|
||||
* Fixed IE7- `[1, 2].join(undefined) -> '1,2'`
|
||||
* Some other fixes / improvements / optimizations
|
||||
|
||||
##### 1.2.5 - 2015.11.02
|
||||
* Some more `Number` constructor fixes:
|
||||
* Fixed V8 ~ Node 0.8 bug: `Number('+0x1')` should be `NaN`
|
||||
* Fixed `Number(' 0b1\n')` case, should be `1`
|
||||
* Fixed `Number()` case, should be `0`
|
||||
|
||||
##### 1.2.4 - 2015.11.01
|
||||
* Fixed `Number('0b12') -> NaN` case in the shim
|
||||
* Fixed V8 ~ Chromium 40- bug - `Weak(Map|Set)#{delete, get, has}` should not throw errors [#124](https://github.com/zloirock/core-js/issues/124)
|
||||
* Some other fixes and optimizations
|
||||
|
||||
##### 1.2.3 - 2015.10.23
|
||||
* Fixed some problems related old V8 bug `Object('a').propertyIsEnumerable(0) // => false`, for example, `Object.assign({}, 'qwe')` from the last release
|
||||
* Fixed `.name` property and `Function#toString` conversion some polyfilled methods
|
||||
* Fixed `Math.imul` arity in Safari 8-
|
||||
|
||||
##### 1.2.2 - 2015.10.18
|
||||
* Improved optimisations for V8
|
||||
* Fixed build process from external packages, [#120](https://github.com/zloirock/core-js/pull/120)
|
||||
* One more `Object.{assign, values, entries}` fix for [**very** specific case](https://github.com/ljharb/proposal-object-values-entries/issues/5)
|
||||
|
||||
##### 1.2.1 - 2015.10.02
|
||||
* Replaced fix `JSON.stringify` + `Symbol` behavior from `.toJSON` method to wrapping `JSON.stringify` - little more correct, [compat-table/642](https://github.com/kangax/compat-table/pull/642)
|
||||
* Fixed typo which broke tasks scheduler in WebWorkers in old FF, [#114](https://github.com/zloirock/core-js/pull/114)
|
||||
|
||||
##### 1.2.0 - 2015.09.27
|
||||
* Added browser [`Promise` rejection hook](#unhandled-rejection-tracking), [#106](https://github.com/zloirock/core-js/issues/106)
|
||||
* Added correct [`IsRegExp`](http://www.ecma-international.org/ecma-262/6.0/#sec-isregexp) logic to [`String#{includes, startsWith, endsWith}`](https://github.com/zloirock/core-js/#ecmascript-6-string) and [`RegExp` constructor](https://github.com/zloirock/core-js/#ecmascript-6-regexp), `@@match` case, [example](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match#Disabling_the_isRegExp_check)
|
||||
* Updated [`String#leftPad`](https://github.com/zloirock/core-js/#ecmascript-7-proposals) [with proposal](https://github.com/ljharb/proposal-string-pad-left-right/issues/6): string filler truncated from the right side
|
||||
* Replaced V8 [`Object.assign`](https://github.com/zloirock/core-js/#ecmascript-6-object) - its properties order not only [incorrect](https://github.com/sindresorhus/object-assign/issues/22), it is non-deterministic and it causes some problems
|
||||
* Fixed behavior with deleted in getters properties for `Object.{`[`assign`](https://github.com/zloirock/core-js/#ecmascript-6-object)`, `[`entries, values`](https://github.com/zloirock/core-js/#ecmascript-7-proposals)`}`, [example](http://goo.gl/iQE01c)
|
||||
* Fixed [`Math.sinh`](https://github.com/zloirock/core-js/#ecmascript-6-math) with very small numbers in V8 near Chromium 38
|
||||
* Some other fixes and optimizations
|
||||
|
||||
##### 1.1.4 - 2015.09.05
|
||||
* Fixed support symbols in FF34-35 [`Object.assign`](https://github.com/zloirock/core-js/#ecmascript-6-object)
|
||||
* Fixed [collections iterators](https://github.com/zloirock/core-js/#ecmascript-6-iterators) in FF25-26
|
||||
* Fixed non-generic WebKit [`Array.of`](https://github.com/zloirock/core-js/#ecmascript-6-array)
|
||||
* Some other fixes and optimizations
|
||||
|
||||
##### 1.1.3 - 2015.08.29
|
||||
* Fixed support Node.js domains in [`Promise`](https://github.com/zloirock/core-js/#ecmascript-6-promise), [#103](https://github.com/zloirock/core-js/issues/103)
|
||||
|
||||
##### 1.1.2 - 2015.08.28
|
||||
* Added `toJSON` method to [`Symbol`](https://github.com/zloirock/core-js/#ecmascript-6-symbol) polyfill and to MS Edge implementation for expected `JSON.stringify` result w/o patching this method
|
||||
* Replaced [`Reflect.construct`](https://github.com/zloirock/core-js/#ecmascript-6-reflect) implementations w/o correct support third argument
|
||||
* Fixed `global` detection with changed `document.domain` in ~IE8, [#100](https://github.com/zloirock/core-js/issues/100)
|
||||
|
||||
##### 1.1.1 - 2015.08.20
|
||||
* Added more correct microtask implementation for [`Promise`](#ecmascript-6-promise)
|
||||
|
||||
##### 1.1.0 - 2015.08.17
|
||||
* Updated [string padding](https://github.com/zloirock/core-js/#ecmascript-7-proposals) to [actual proposal](https://github.com/ljharb/proposal-string-pad-left-right) - renamed, minor internal changes:
|
||||
* `String#lpad` -> `String#padLeft`
|
||||
* `String#rpad` -> `String#padRight`
|
||||
* Added [string trim functions](#ecmascript-7-proposals) - [proposal](https://github.com/sebmarkbage/ecmascript-string-left-right-trim), defacto standard - required only for IE11- and fixed for some old engines:
|
||||
* `String#trimLeft`
|
||||
* `String#trimRight`
|
||||
* [`String#trim`](https://github.com/zloirock/core-js/#ecmascript-6-string) fixed for some engines by es6 spec and moved from `es5` to single `es6` module
|
||||
* Splitted [`es6.object.statics-accept-primitives`](https://github.com/zloirock/core-js/#ecmascript-6-object)
|
||||
* Caps for `freeze`-family `Object` methods moved from `es5` to `es6` namespace and joined with [es6 wrappers](https://github.com/zloirock/core-js/#ecmascript-6-object)
|
||||
* `es5` [namespace](https://github.com/zloirock/core-js/#commonjs) also includes modules, moved to `es6` namespace - you can use it as before
|
||||
* Increased `MessageChannel` priority in `$.task`, [#95](https://github.com/zloirock/core-js/issues/95)
|
||||
* Does not get `global.Symbol` on each getting iterator, if you wanna use alternative `Symbol` shim - add it before `core-js`
|
||||
* [`Reflect.construct`](https://github.com/zloirock/core-js/#ecmascript-6-reflect) optimized and fixed for some cases
|
||||
* Simplified [`Reflect.enumerate`](https://github.com/zloirock/core-js/#ecmascript-6-reflect), see [this question](https://esdiscuss.org/topic/question-about-enumerate-and-property-decision-timing)
|
||||
* Some corrections in [`Math.acosh`](https://github.com/zloirock/core-js/#ecmascript-6-math)
|
||||
* Fixed [`Math.imul`](https://github.com/zloirock/core-js/#ecmascript-6-math) for old WebKit
|
||||
* Some fixes in string / RegExp [well-known symbols](https://github.com/zloirock/core-js/#ecmascript-6-regexp) logic
|
||||
* Some other fixes and optimizations
|
||||
|
||||
##### 1.0.1 - 2015.07.31
|
||||
* Some fixes for final MS Edge, replaced broken native `Reflect.defineProperty`
|
||||
* Some minor fixes and optimizations
|
||||
* Changed compression `client/*.min.js` options for safe `Function#name` and `Function#length`, should be fixed [#92](https://github.com/zloirock/core-js/issues/92)
|
||||
|
||||
##### 1.0.0 - 2015.07.22
|
||||
* Added logic for [well-known symbols](https://github.com/zloirock/core-js/#ecmascript-6-regexp):
|
||||
* `Symbol.match`
|
||||
* `Symbol.replace`
|
||||
* `Symbol.split`
|
||||
* `Symbol.search`
|
||||
* Actualized and optimized work with iterables:
|
||||
* Optimized [`Map`, `Set`, `WeakMap`, `WeakSet` constructors](https://github.com/zloirock/core-js/#ecmascript-6-collections), [`Promise.all`, `Promise.race`](https://github.com/zloirock/core-js/#ecmascript-6-promise) for default `Array Iterator`
|
||||
* Optimized [`Array.from`](https://github.com/zloirock/core-js/#ecmascript-6-array) for default `Array Iterator`
|
||||
* Added [`core.getIteratorMethod`](https://github.com/zloirock/core-js/#ecmascript-6-iterators) helper
|
||||
* Uses enumerable properties in shimmed instances - collections, iterators, etc for optimize performance
|
||||
* Added support native constructors to [`Reflect.construct`](https://github.com/zloirock/core-js/#ecmascript-6-reflect) with 2 arguments
|
||||
* Added support native constructors to [`Function#bind`](https://github.com/zloirock/core-js/#ecmascript-5) shim with `new`
|
||||
* Removed obsolete `.clear` methods native [`Weak`-collections](https://github.com/zloirock/core-js/#ecmascript-6-collections)
|
||||
* Maximum modularity, reduced minimal custom build size, separated into submodules:
|
||||
* [`es6.reflect`](https://github.com/zloirock/core-js/#ecmascript-6-reflect)
|
||||
* [`es6.regexp`](https://github.com/zloirock/core-js/#ecmascript-6-regexp)
|
||||
* [`es6.math`](https://github.com/zloirock/core-js/#ecmascript-6-math)
|
||||
* [`es6.number`](https://github.com/zloirock/core-js/#ecmascript-6-number)
|
||||
* [`es7.object.to-array`](https://github.com/zloirock/core-js/#ecmascript-7-proposals)
|
||||
* [`core.object`](https://github.com/zloirock/core-js/#object)
|
||||
* [`core.string`](https://github.com/zloirock/core-js/#escaping-strings)
|
||||
* [`core.iter-helpers`](https://github.com/zloirock/core-js/#ecmascript-6-iterators)
|
||||
* Internal modules (`$`, `$.iter`, etc)
|
||||
* Many other optimizations
|
||||
* Final cleaning non-standard features
|
||||
* Moved `$for` to [separate library](https://github.com/zloirock/forof). This work for syntax - `for-of` loop and comprehensions
|
||||
* Moved `Date#{format, formatUTC}` to [separate library](https://github.com/zloirock/dtf). Standard way for this - `ECMA-402`
|
||||
* Removed `Math` methods from `Number.prototype`. Slight sugar for simple `Math` methods calling
|
||||
* Removed `{Array#, Array, Dict}.turn`
|
||||
* Removed `core.global`
|
||||
* Uses `ToNumber` instead of `ToLength` in [`Number Iterator`](https://github.com/zloirock/core-js/#number-iterator), `Array.from(2.5)` will be `[0, 1, 2]` instead of `[0, 1]`
|
||||
* Fixed [#85](https://github.com/zloirock/core-js/issues/85) - invalid `Promise` unhandled rejection message in nested `setTimeout`
|
||||
* Fixed [#86](https://github.com/zloirock/core-js/issues/86) - support FF extensions
|
||||
* Fixed [#89](https://github.com/zloirock/core-js/issues/89) - behavior `Number` constructor in strange case
|
||||
|
||||
##### 0.9.18 - 2015.06.17
|
||||
* Removed `/` from [`RegExp.escape`](https://github.com/zloirock/core-js/#ecmascript-7-proposals) escaped characters
|
||||
|
||||
##### 0.9.17 - 2015.06.14
|
||||
* Updated [`RegExp.escape`](https://github.com/zloirock/core-js/#ecmascript-7-proposals) to the [latest proposal](https://github.com/benjamingr/RexExp.escape)
|
||||
* Fixed conflict with webpack dev server + IE buggy behavior
|
||||
|
||||
##### 0.9.16 - 2015.06.11
|
||||
* More correct order resolving thenable in [`Promise`](https://github.com/zloirock/core-js/#ecmascript-6-promise) polyfill
|
||||
* Uses polyfill instead of [buggy V8 `Promise`](https://github.com/zloirock/core-js/issues/78)
|
||||
|
||||
##### 0.9.15 - 2015.06.09
|
||||
* [Collections](https://github.com/zloirock/core-js/#ecmascript-6-collections) from `library` version return wrapped native instances
|
||||
* Fixed collections prototype methods in `library` version
|
||||
* Optimized [`Math.hypot`](https://github.com/zloirock/core-js/#ecmascript-6-math)
|
||||
|
||||
##### 0.9.14 - 2015.06.04
|
||||
* Updated [`Promise.resolve` behavior](https://esdiscuss.org/topic/fixing-promise-resolve)
|
||||
* Added fallback for IE11 buggy `Object.getOwnPropertyNames` + iframe
|
||||
* Some other fixes
|
||||
|
||||
##### 0.9.13 - 2015.05.25
|
||||
* Added fallback for [`Symbol` polyfill](https://github.com/zloirock/core-js/#ecmascript-6-symbol) for old Android
|
||||
* Some other fixes
|
||||
|
||||
##### 0.9.12 - 2015.05.24
|
||||
* Different instances `core-js` should use / recognize the same symbols
|
||||
* Some fixes
|
||||
|
||||
##### 0.9.11 - 2015.05.18
|
||||
* Simplified [custom build](https://github.com/zloirock/core-js/#custom-build)
|
||||
* Added custom build js api
|
||||
* Added `grunt-cli` to `devDependencies` for `npm run grunt`
|
||||
* Some fixes
|
||||
|
||||
##### 0.9.10 - 2015.05.16
|
||||
* Wrapped `Function#toString` for correct work wrapped methods / constructors with methods similar to the [`lodash` `isNative`](https://github.com/lodash/lodash/issues/1197)
|
||||
* Added proto versions of methods to export object in `default` version for consistency with `library` version
|
||||
|
||||
##### 0.9.9 - 2015.05.14
|
||||
* Wrapped `Object#propertyIsEnumerable` for [`Symbol` polyfill](https://github.com/zloirock/core-js/#ecmascript-6-symbol)
|
||||
* [Added proto versions of methods to `library` for ES7 bind syntax](https://github.com/zloirock/core-js/issues/65)
|
||||
* Some other fixes
|
||||
|
||||
##### 0.9.8 - 2015.05.12
|
||||
* Fixed [`Math.hypot`](https://github.com/zloirock/core-js/#ecmascript-6-math) with negative arguments
|
||||
* Added `Object#toString.toString` as fallback for [`lodash` `isNative`](https://github.com/lodash/lodash/issues/1197)
|
||||
|
||||
##### 0.9.7 - 2015.05.07
|
||||
* Added [support DOM collections](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice#Streamlining_cross-browser_behavior) to IE8- `Array#slice`
|
||||
|
||||
##### 0.9.6 - 2015.05.01
|
||||
* Added [`String#lpad`, `String#rpad`](https://github.com/zloirock/core-js/#ecmascript-7-proposals)
|
||||
|
||||
##### 0.9.5 - 2015.04.30
|
||||
* Added cap for `Function#@@hasInstance`
|
||||
* Some fixes and optimizations
|
||||
|
||||
##### 0.9.4 - 2015.04.27
|
||||
* Fixed `RegExp` constructor
|
||||
|
||||
##### 0.9.3 - 2015.04.26
|
||||
* Some fixes and optimizations
|
||||
|
||||
##### 0.9.2 - 2015.04.25
|
||||
* More correct [`Promise`](https://github.com/zloirock/core-js/#ecmascript-6-promise) unhandled rejection tracking and resolving / rejection priority
|
||||
|
||||
##### 0.9.1 - 2015.04.25
|
||||
* Fixed `__proto__`-based [`Promise`](https://github.com/zloirock/core-js/#ecmascript-6-promise) subclassing in some environments
|
||||
|
||||
##### 0.9.0 - 2015.04.24
|
||||
* Added correct [symbols](https://github.com/zloirock/core-js/#ecmascript-6-symbol) descriptors
|
||||
* Fixed behavior `Object.{assign, create, defineProperty, defineProperties, getOwnPropertyDescriptor, getOwnPropertyDescriptors}` with symbols
|
||||
* Added [single entry points](https://github.com/zloirock/core-js/#commonjs) for `Object.{create, defineProperty, defineProperties}`
|
||||
* Added [`Map#toJSON`](https://github.com/zloirock/core-js/#ecmascript-7-proposals)
|
||||
* Removed non-standard methods `Object#[_]` and `Function#only` - they solves syntax problems, but now in compilers available arrows and ~~in near future will be available~~ [available](http://babeljs.io/blog/2015/05/14/function-bind/) [bind syntax](https://github.com/zenparsing/es-function-bind)
|
||||
* Removed non-standard undocumented methods `Symbol.{pure, set}`
|
||||
* Some fixes and internal changes
|
||||
|
||||
##### 0.8.4 - 2015.04.18
|
||||
* Uses `webpack` instead of `browserify` for browser builds - more compression-friendly result
|
||||
|
||||
##### 0.8.3 - 2015.04.14
|
||||
* Fixed `Array` statics with single entry points
|
||||
|
||||
##### 0.8.2 - 2015.04.13
|
||||
* [`Math.fround`](https://github.com/zloirock/core-js/#ecmascript-6-math) now also works in IE9-
|
||||
* Added [`Set#toJSON`](https://github.com/zloirock/core-js/#ecmascript-7-proposals)
|
||||
* Some optimizations and fixes
|
||||
|
||||
##### 0.8.1 - 2015.04.03
|
||||
* Fixed `Symbol.keyFor`
|
||||
|
||||
##### 0.8.0 - 2015.04.02
|
||||
* Changed [CommonJS API](https://github.com/zloirock/core-js/#commonjs)
|
||||
* Splitted and renamed some modules
|
||||
* Added support ES3 environment (ES5 polyfill) to **all** default versions - size increases slightly (+ ~4kb w/o gzip), many issues disappear, if you don't need it - [simply include only required namespaces / features / modules](https://github.com/zloirock/core-js/#commonjs)
|
||||
* Removed [abstract references](https://github.com/zenparsing/es-abstract-refs) support - proposal has been superseded =\
|
||||
* [`$for.isIterable` -> `core.isIterable`, `$for.getIterator` -> `core.getIterator`](https://github.com/zloirock/core-js/#ecmascript-6-iterators), temporary available in old namespace
|
||||
* Fixed iterators support in v8 `Promise.all` and `Promise.race`
|
||||
* Many other fixes
|
||||
|
||||
##### 0.7.2 - 2015.03.09
|
||||
* Some fixes
|
||||
|
||||
##### 0.7.1 - 2015.03.07
|
||||
* Some fixes
|
||||
|
||||
##### 0.7.0 - 2015.03.06
|
||||
* Rewritten and splitted into [CommonJS modules](https://github.com/zloirock/core-js/#commonjs)
|
||||
|
||||
##### 0.6.1 - 2015.02.24
|
||||
* Fixed support [`Object.defineProperty`](https://github.com/zloirock/core-js/#ecmascript-5) with accessors on DOM elements on IE8
|
||||
|
||||
##### 0.6.0 - 2015.02.23
|
||||
* Added support safe closing iteration - calling `iterator.return` on abort iteration, if it exists
|
||||
* Added basic support [`Promise`](https://github.com/zloirock/core-js/#ecmascript-6-promise) unhandled rejection tracking in shim
|
||||
* Added [`Object.getOwnPropertyDescriptors`](https://github.com/zloirock/core-js/#ecmascript-7-proposals)
|
||||
* Removed `console` cap - creates too many problems
|
||||
* Restructuring [namespaces](https://github.com/zloirock/core-js/#custom-build)
|
||||
* Some fixes
|
||||
|
||||
##### 0.5.4 - 2015.02.15
|
||||
* Some fixes
|
||||
|
||||
##### 0.5.3 - 2015.02.14
|
||||
* Added [support binary and octal literals](https://github.com/zloirock/core-js/#ecmascript-6-number) to `Number` constructor
|
||||
* Added [`Date#toISOString`](https://github.com/zloirock/core-js/#ecmascript-5)
|
||||
|
||||
##### 0.5.2 - 2015.02.10
|
||||
* Some fixes
|
||||
|
||||
##### 0.5.1 - 2015.02.09
|
||||
* Some fixes
|
||||
|
||||
##### 0.5.0 - 2015.02.08
|
||||
* Systematization of modules
|
||||
* Splitted [`es6` module](https://github.com/zloirock/core-js/#ecmascript-6)
|
||||
* Splitted `console` module: `web.console` - only cap for missing methods, `core.log` - bound methods & additional features
|
||||
* Added [`delay` method](https://github.com/zloirock/core-js/#delay)
|
||||
* Some fixes
|
||||
|
||||
##### 0.4.10 - 2015.01.28
|
||||
* [`Object.getOwnPropertySymbols`](https://github.com/zloirock/core-js/#ecmascript-6-symbol) polyfill returns array of wrapped keys
|
||||
|
||||
##### 0.4.9 - 2015.01.27
|
||||
* FF20-24 fix
|
||||
|
||||
##### 0.4.8 - 2015.01.25
|
||||
* Some [collections](https://github.com/zloirock/core-js/#ecmascript-6-collections) fixes
|
||||
|
||||
##### 0.4.7 - 2015.01.25
|
||||
* Added support frozen objects as [collections](https://github.com/zloirock/core-js/#ecmascript-6-collections) keys
|
||||
|
||||
##### 0.4.6 - 2015.01.21
|
||||
* Added [`Object.getOwnPropertySymbols`](https://github.com/zloirock/core-js/#ecmascript-6-symbol)
|
||||
* Added [`NodeList.prototype[@@iterator]`](https://github.com/zloirock/core-js/#ecmascript-6-iterators)
|
||||
* Added basic `@@species` logic - getter in native constructors
|
||||
* Removed `Function#by`
|
||||
* Some fixes
|
||||
|
||||
##### 0.4.5 - 2015.01.16
|
||||
* Some fixes
|
||||
|
||||
##### 0.4.4 - 2015.01.11
|
||||
* Enabled CSP support
|
||||
|
||||
##### 0.4.3 - 2015.01.10
|
||||
* Added `Function` instances `name` property for IE9+
|
||||
|
||||
##### 0.4.2 - 2015.01.10
|
||||
* `Object` static methods accept primitives
|
||||
* `RegExp` constructor can alter flags (IE9+)
|
||||
* Added `Array.prototype[Symbol.unscopables]`
|
||||
|
||||
##### 0.4.1 - 2015.01.05
|
||||
* Some fixes
|
||||
|
||||
##### 0.4.0 - 2015.01.03
|
||||
* Added [`es6.reflect`](https://github.com/zloirock/core-js/#ecmascript-6-reflect) module:
|
||||
* Added `Reflect.apply`
|
||||
* Added `Reflect.construct`
|
||||
* Added `Reflect.defineProperty`
|
||||
* Added `Reflect.deleteProperty`
|
||||
* Added `Reflect.enumerate`
|
||||
* Added `Reflect.get`
|
||||
* Added `Reflect.getOwnPropertyDescriptor`
|
||||
* Added `Reflect.getPrototypeOf`
|
||||
* Added `Reflect.has`
|
||||
* Added `Reflect.isExtensible`
|
||||
* Added `Reflect.preventExtensions`
|
||||
* Added `Reflect.set`
|
||||
* Added `Reflect.setPrototypeOf`
|
||||
* `core-js` methods now can use external `Symbol.iterator` polyfill
|
||||
* Some fixes
|
||||
|
||||
##### 0.3.3 - 2014.12.28
|
||||
* [Console cap](https://github.com/zloirock/core-js/#console) excluded from node.js default builds
|
||||
|
||||
##### 0.3.2 - 2014.12.25
|
||||
* Added cap for [ES5](https://github.com/zloirock/core-js/#ecmascript-5) freeze-family methods
|
||||
* Fixed `console` bug
|
||||
|
||||
##### 0.3.1 - 2014.12.23
|
||||
* Some fixes
|
||||
|
||||
##### 0.3.0 - 2014.12.23
|
||||
* Optimize [`Map` & `Set`](https://github.com/zloirock/core-js/#ecmascript-6-collections):
|
||||
* Use entries chain on hash table
|
||||
* Fast & correct iteration
|
||||
* Iterators moved to [`es6`](https://github.com/zloirock/core-js/#ecmascript-6) and [`es6.collections`](https://github.com/zloirock/core-js/#ecmascript-6-collections) modules
|
||||
|
||||
##### 0.2.5 - 2014.12.20
|
||||
* `console` no longer shortcut for `console.log` (compatibility problems)
|
||||
* Some fixes
|
||||
|
||||
##### 0.2.4 - 2014.12.17
|
||||
* Better compliance of ES6
|
||||
* Added [`Math.fround`](https://github.com/zloirock/core-js/#ecmascript-6-math) (IE10+)
|
||||
* Some fixes
|
||||
|
||||
##### 0.2.3 - 2014.12.15
|
||||
* [Symbols](https://github.com/zloirock/core-js/#ecmascript-6-symbol):
|
||||
* Added option to disable addition setter to `Object.prototype` for Symbol polyfill:
|
||||
* Added `Symbol.useSimple`
|
||||
* Added `Symbol.useSetter`
|
||||
* Added cap for well-known Symbols:
|
||||
* Added `Symbol.hasInstance`
|
||||
* Added `Symbol.isConcatSpreadable`
|
||||
* Added `Symbol.match`
|
||||
* Added `Symbol.replace`
|
||||
* Added `Symbol.search`
|
||||
* Added `Symbol.species`
|
||||
* Added `Symbol.split`
|
||||
* Added `Symbol.toPrimitive`
|
||||
* Added `Symbol.unscopables`
|
||||
|
||||
##### 0.2.2 - 2014.12.13
|
||||
* Added [`RegExp#flags`](https://github.com/zloirock/core-js/#ecmascript-6-regexp) ([December 2014 Draft Rev 29](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#december_6_2014_draft_rev_29))
|
||||
* Added [`String.raw`](https://github.com/zloirock/core-js/#ecmascript-6-string)
|
||||
|
||||
##### 0.2.1 - 2014.12.12
|
||||
* Repair converting -0 to +0 in [native collections](https://github.com/zloirock/core-js/#ecmascript-6-collections)
|
||||
|
||||
##### 0.2.0 - 2014.12.06
|
||||
* Added [`es7.proposals`](https://github.com/zloirock/core-js/#ecmascript-7-proposals) and [`es7.abstract-refs`](https://github.com/zenparsing/es-abstract-refs) modules
|
||||
* Added [`String#at`](https://github.com/zloirock/core-js/#ecmascript-7-proposals)
|
||||
* Added real [`String Iterator`](https://github.com/zloirock/core-js/#ecmascript-6-iterators), older versions used Array Iterator
|
||||
* Added abstract references support:
|
||||
* Added `Symbol.referenceGet`
|
||||
* Added `Symbol.referenceSet`
|
||||
* Added `Symbol.referenceDelete`
|
||||
* Added `Function#@@referenceGet`
|
||||
* Added `Map#@@referenceGet`
|
||||
* Added `Map#@@referenceSet`
|
||||
* Added `Map#@@referenceDelete`
|
||||
* Added `WeakMap#@@referenceGet`
|
||||
* Added `WeakMap#@@referenceSet`
|
||||
* Added `WeakMap#@@referenceDelete`
|
||||
* Added `Dict.{...methods}[@@referenceGet]`
|
||||
* Removed deprecated `.contains` methods
|
||||
* Some fixes
|
||||
|
||||
##### 0.1.5 - 2014.12.01
|
||||
* Added [`Array#copyWithin`](https://github.com/zloirock/core-js/#ecmascript-6-array)
|
||||
* Added [`String#codePointAt`](https://github.com/zloirock/core-js/#ecmascript-6-string)
|
||||
* Added [`String.fromCodePoint`](https://github.com/zloirock/core-js/#ecmascript-6-string)
|
||||
|
||||
##### 0.1.4 - 2014.11.27
|
||||
* Added [`Dict.mapPairs`](https://github.com/zloirock/core-js/#dict)
|
||||
|
||||
##### 0.1.3 - 2014.11.20
|
||||
* [TC39 November meeting](https://github.com/rwaldron/tc39-notes/tree/master/es6/2014-11):
|
||||
* [`.contains` -> `.includes`](https://github.com/rwaldron/tc39-notes/blob/master/es6/2014-11/nov-18.md#51--44-arrayprototypecontains-and-stringprototypecontains)
|
||||
* `String#contains` -> [`String#includes`](https://github.com/zloirock/core-js/#ecmascript-6-string)
|
||||
* `Array#contains` -> [`Array#includes`](https://github.com/zloirock/core-js/#ecmascript-7-proposals)
|
||||
* `Dict.contains` -> [`Dict.includes`](https://github.com/zloirock/core-js/#dict)
|
||||
* [Removed `WeakMap#clear`](https://github.com/rwaldron/tc39-notes/blob/master/es6/2014-11/nov-19.md#412-should-weakmapweakset-have-a-clear-method-markm)
|
||||
* [Removed `WeakSet#clear`](https://github.com/rwaldron/tc39-notes/blob/master/es6/2014-11/nov-19.md#412-should-weakmapweakset-have-a-clear-method-markm)
|
||||
|
||||
##### 0.1.2 - 2014.11.19
|
||||
* `Map` & `Set` bug fix
|
||||
|
||||
##### 0.1.1 - 2014.11.18
|
||||
* Public release
|
|
@ -1,3 +0,0 @@
|
|||
require('LiveScript');
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
module.exports = require('./build/Gruntfile');
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2014-2019 Denis Pushkarev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
File diff suppressed because it is too large
Load Diff
|
@ -1,49 +0,0 @@
|
|||
{
|
||||
"name": "core.js",
|
||||
"main": "client/core.js",
|
||||
"version": "2.6.11",
|
||||
"description": "Standard Library",
|
||||
"keywords": [
|
||||
"ES3",
|
||||
"ES5",
|
||||
"ES6",
|
||||
"ES7",
|
||||
"ES2015",
|
||||
"ES2016",
|
||||
"ES2017",
|
||||
"ECMAScript 3",
|
||||
"ECMAScript 5",
|
||||
"ECMAScript 6",
|
||||
"ECMAScript 7",
|
||||
"ECMAScript 2015",
|
||||
"ECMAScript 2016",
|
||||
"ECMAScript 2017",
|
||||
"Harmony",
|
||||
"Strawman",
|
||||
"Map",
|
||||
"Set",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
"Promise",
|
||||
"Symbol",
|
||||
"TypedArray",
|
||||
"setImmediate",
|
||||
"Dict",
|
||||
"polyfill",
|
||||
"shim"
|
||||
],
|
||||
"authors": [
|
||||
"Denis Pushkarev <zloirock@zloirock.ru> (http://zloirock.ru/)"
|
||||
],
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/zloirock/core-js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zloirock/core-js.git"
|
||||
},
|
||||
"ignore": [
|
||||
"build",
|
||||
"node_modules",
|
||||
"tests"
|
||||
]
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
require! <[./build fs ./config]>
|
||||
module.exports = (grunt)->
|
||||
grunt.loadNpmTasks \grunt-contrib-clean
|
||||
grunt.loadNpmTasks \grunt-contrib-copy
|
||||
grunt.loadNpmTasks \grunt-contrib-uglify
|
||||
grunt.loadNpmTasks \grunt-contrib-watch
|
||||
grunt.loadNpmTasks \grunt-livescript
|
||||
grunt.loadNpmTasks \grunt-karma
|
||||
grunt.initConfig do
|
||||
pkg: grunt.file.readJSON './package.json'
|
||||
uglify: build:
|
||||
files: '<%=grunt.option("path")%>.min.js': '<%=grunt.option("path")%>.js'
|
||||
options:
|
||||
mangle: {+keep_fnames}
|
||||
compress: {+keep_fnames, +pure_getters}
|
||||
output: {max_line_len: 32000}
|
||||
ie8: on
|
||||
sourceMap: on
|
||||
banner: config.banner
|
||||
livescript: src: files:
|
||||
'./tests/helpers.js': './tests/helpers/*'
|
||||
'./tests/tests.js': './tests/tests/*'
|
||||
'./tests/library.js': './tests/library/*'
|
||||
'./tests/es.js': './tests/tests/es*'
|
||||
'./tests/experimental.js': './tests/experimental/*'
|
||||
'./build/index.js': './build/build.ls*'
|
||||
clean: <[./library]>
|
||||
copy: lib: files:
|
||||
* expand: on
|
||||
cwd: './'
|
||||
src: <[es5/** es6/** es7/** stage/** web/** core/** fn/** index.js shim.js]>
|
||||
dest: './library/'
|
||||
* expand: on
|
||||
cwd: './'
|
||||
src: <[modules/*]>
|
||||
dest: './library/'
|
||||
filter: \isFile
|
||||
* expand: on
|
||||
cwd: './modules/library/'
|
||||
src: '*'
|
||||
dest: './library/modules/'
|
||||
watch:
|
||||
core:
|
||||
files: './modules/*'
|
||||
tasks: \default
|
||||
tests:
|
||||
files: './tests/tests/*'
|
||||
tasks: \livescript
|
||||
karma:
|
||||
'options':
|
||||
configFile: './tests/karma.conf.js'
|
||||
browsers: <[PhantomJS]>
|
||||
singleRun: on
|
||||
'default': {}
|
||||
'library': files: <[client/library.js tests/helpers.js tests/library.js]>map -> src: it
|
||||
grunt.registerTask \build (options)->
|
||||
done = @async!
|
||||
build {
|
||||
modules: (options || 'es5,es6,es7,js,web,core')split \,
|
||||
blacklist: (grunt.option(\blacklist) || '')split \,
|
||||
library: grunt.option(\library) in <[yes on true]>
|
||||
umd: grunt.option(\umd) not in <[no off false]>
|
||||
}
|
||||
.then !->
|
||||
grunt.option(\path) || grunt.option(\path, './custom')
|
||||
fs.writeFile grunt.option(\path) + '.js', it, done
|
||||
.catch !->
|
||||
console.error it
|
||||
process.exit 1
|
||||
grunt.registerTask \client ->
|
||||
grunt.option \library ''
|
||||
grunt.option \path './client/core'
|
||||
grunt.task.run <[build:es5,es6,es7,js,web,core uglify]>
|
||||
grunt.registerTask \library ->
|
||||
grunt.option \library 'true'
|
||||
grunt.option \path './client/library'
|
||||
grunt.task.run <[build:es5,es6,es7,js,web,core uglify]>
|
||||
grunt.registerTask \shim ->
|
||||
grunt.option \library ''
|
||||
grunt.option \path './client/shim'
|
||||
grunt.task.run <[build:es5,es6,es7,js,web uglify]>
|
||||
grunt.registerTask \e ->
|
||||
grunt.option \library ''>
|
||||
grunt.option \path './client/core'
|
||||
grunt.task.run <[build:es5,es6,es7,js,web,core,exp uglify]>
|
||||
grunt.registerTask \default <[clean copy client library shim]>
|
|
@ -1,62 +0,0 @@
|
|||
require! {
|
||||
'../library/fn/promise': Promise
|
||||
'./config': {list, experimental, libraryBlacklist, es5SpecialCase, banner}
|
||||
fs: {readFile, writeFile, unlink}
|
||||
path: {basename, dirname, join}
|
||||
webpack, temp
|
||||
}
|
||||
|
||||
module.exports = ({modules = [], blacklist = [], library = no, umd = on})->
|
||||
resolve, reject <~! new Promise _
|
||||
let @ = modules.reduce ((memo, it)-> memo[it] = on; memo), {}
|
||||
if @exp => for experimental => @[..] = on
|
||||
if @es5 => for es5SpecialCase => @[..] = on
|
||||
for ns of @
|
||||
if @[ns]
|
||||
for name in list
|
||||
if name.indexOf("#ns.") is 0 and name not in experimental
|
||||
@[name] = on
|
||||
|
||||
if library => blacklist ++= libraryBlacklist
|
||||
for ns in blacklist
|
||||
for name in list
|
||||
if name is ns or name.indexOf("#ns.") is 0
|
||||
@[name] = no
|
||||
|
||||
TARGET = temp.path {suffix: '.js'}
|
||||
|
||||
err, info <~! webpack do
|
||||
entry: list.filter(~> @[it]).map ~>
|
||||
if library => join __dirname, '..', 'library', 'modules', it
|
||||
else join __dirname, '..', 'modules', it
|
||||
output:
|
||||
path: dirname TARGET
|
||||
filename: basename "./#TARGET"
|
||||
if err => return reject err
|
||||
|
||||
err, script <~! readFile TARGET
|
||||
if err => return reject err
|
||||
|
||||
err <~! unlink TARGET
|
||||
if err => return reject err
|
||||
|
||||
if umd
|
||||
exportScript = """
|
||||
// CommonJS export
|
||||
if (typeof module != 'undefined' && module.exports) module.exports = __e;
|
||||
// RequireJS export
|
||||
else if (typeof define == 'function' && define.amd) define(function () { return __e; });
|
||||
// Export to global object
|
||||
else __g.core = __e;
|
||||
"""
|
||||
else
|
||||
exportScript = ""
|
||||
|
||||
resolve """
|
||||
#banner
|
||||
!function(__e, __g, undefined){
|
||||
'use strict';
|
||||
#script
|
||||
#exportScript
|
||||
}(1, 1);
|
||||
"""
|
|
@ -1,275 +0,0 @@
|
|||
module.exports = {
|
||||
list: [
|
||||
'es6.symbol',
|
||||
'es6.object.define-property',
|
||||
'es6.object.define-properties',
|
||||
'es6.object.get-own-property-descriptor',
|
||||
'es6.object.create',
|
||||
'es6.object.get-prototype-of',
|
||||
'es6.object.keys',
|
||||
'es6.object.get-own-property-names',
|
||||
'es6.object.freeze',
|
||||
'es6.object.seal',
|
||||
'es6.object.prevent-extensions',
|
||||
'es6.object.is-frozen',
|
||||
'es6.object.is-sealed',
|
||||
'es6.object.is-extensible',
|
||||
'es6.object.assign',
|
||||
'es6.object.is',
|
||||
'es6.object.set-prototype-of',
|
||||
'es6.object.to-string',
|
||||
'es6.function.bind',
|
||||
'es6.function.name',
|
||||
'es6.function.has-instance',
|
||||
'es6.number.constructor',
|
||||
'es6.number.to-fixed',
|
||||
'es6.number.to-precision',
|
||||
'es6.number.epsilon',
|
||||
'es6.number.is-finite',
|
||||
'es6.number.is-integer',
|
||||
'es6.number.is-nan',
|
||||
'es6.number.is-safe-integer',
|
||||
'es6.number.max-safe-integer',
|
||||
'es6.number.min-safe-integer',
|
||||
'es6.number.parse-float',
|
||||
'es6.number.parse-int',
|
||||
'es6.parse-int',
|
||||
'es6.parse-float',
|
||||
'es6.math.acosh',
|
||||
'es6.math.asinh',
|
||||
'es6.math.atanh',
|
||||
'es6.math.cbrt',
|
||||
'es6.math.clz32',
|
||||
'es6.math.cosh',
|
||||
'es6.math.expm1',
|
||||
'es6.math.fround',
|
||||
'es6.math.hypot',
|
||||
'es6.math.imul',
|
||||
'es6.math.log10',
|
||||
'es6.math.log1p',
|
||||
'es6.math.log2',
|
||||
'es6.math.sign',
|
||||
'es6.math.sinh',
|
||||
'es6.math.tanh',
|
||||
'es6.math.trunc',
|
||||
'es6.string.from-code-point',
|
||||
'es6.string.raw',
|
||||
'es6.string.trim',
|
||||
'es6.string.code-point-at',
|
||||
'es6.string.ends-with',
|
||||
'es6.string.includes',
|
||||
'es6.string.repeat',
|
||||
'es6.string.starts-with',
|
||||
'es6.string.iterator',
|
||||
'es6.string.anchor',
|
||||
'es6.string.big',
|
||||
'es6.string.blink',
|
||||
'es6.string.bold',
|
||||
'es6.string.fixed',
|
||||
'es6.string.fontcolor',
|
||||
'es6.string.fontsize',
|
||||
'es6.string.italics',
|
||||
'es6.string.link',
|
||||
'es6.string.small',
|
||||
'es6.string.strike',
|
||||
'es6.string.sub',
|
||||
'es6.string.sup',
|
||||
'es6.array.is-array',
|
||||
'es6.array.from',
|
||||
'es6.array.of',
|
||||
'es6.array.join',
|
||||
'es6.array.slice',
|
||||
'es6.array.sort',
|
||||
'es6.array.for-each',
|
||||
'es6.array.map',
|
||||
'es6.array.filter',
|
||||
'es6.array.some',
|
||||
'es6.array.every',
|
||||
'es6.array.reduce',
|
||||
'es6.array.reduce-right',
|
||||
'es6.array.index-of',
|
||||
'es6.array.last-index-of',
|
||||
'es6.array.copy-within',
|
||||
'es6.array.fill',
|
||||
'es6.array.find',
|
||||
'es6.array.find-index',
|
||||
'es6.array.iterator',
|
||||
'es6.array.species',
|
||||
'es6.regexp.constructor',
|
||||
'es6.regexp.exec',
|
||||
'es6.regexp.to-string',
|
||||
'es6.regexp.flags',
|
||||
'es6.regexp.match',
|
||||
'es6.regexp.replace',
|
||||
'es6.regexp.search',
|
||||
'es6.regexp.split',
|
||||
'es6.promise',
|
||||
'es6.map',
|
||||
'es6.set',
|
||||
'es6.weak-map',
|
||||
'es6.weak-set',
|
||||
'es6.reflect.apply',
|
||||
'es6.reflect.construct',
|
||||
'es6.reflect.define-property',
|
||||
'es6.reflect.delete-property',
|
||||
'es6.reflect.enumerate',
|
||||
'es6.reflect.get',
|
||||
'es6.reflect.get-own-property-descriptor',
|
||||
'es6.reflect.get-prototype-of',
|
||||
'es6.reflect.has',
|
||||
'es6.reflect.is-extensible',
|
||||
'es6.reflect.own-keys',
|
||||
'es6.reflect.prevent-extensions',
|
||||
'es6.reflect.set',
|
||||
'es6.reflect.set-prototype-of',
|
||||
'es6.date.now',
|
||||
'es6.date.to-json',
|
||||
'es6.date.to-iso-string',
|
||||
'es6.date.to-string',
|
||||
'es6.date.to-primitive',
|
||||
'es6.typed.array-buffer',
|
||||
'es6.typed.data-view',
|
||||
'es6.typed.int8-array',
|
||||
'es6.typed.uint8-array',
|
||||
'es6.typed.uint8-clamped-array',
|
||||
'es6.typed.int16-array',
|
||||
'es6.typed.uint16-array',
|
||||
'es6.typed.int32-array',
|
||||
'es6.typed.uint32-array',
|
||||
'es6.typed.float32-array',
|
||||
'es6.typed.float64-array',
|
||||
'es7.array.includes',
|
||||
'es7.array.flat-map',
|
||||
'es7.array.flatten',
|
||||
'es7.string.at',
|
||||
'es7.string.pad-start',
|
||||
'es7.string.pad-end',
|
||||
'es7.string.trim-left',
|
||||
'es7.string.trim-right',
|
||||
'es7.string.match-all',
|
||||
'es7.symbol.async-iterator',
|
||||
'es7.symbol.observable',
|
||||
'es7.object.get-own-property-descriptors',
|
||||
'es7.object.values',
|
||||
'es7.object.entries',
|
||||
'es7.object.define-getter',
|
||||
'es7.object.define-setter',
|
||||
'es7.object.lookup-getter',
|
||||
'es7.object.lookup-setter',
|
||||
'es7.map.to-json',
|
||||
'es7.set.to-json',
|
||||
'es7.map.of',
|
||||
'es7.set.of',
|
||||
'es7.weak-map.of',
|
||||
'es7.weak-set.of',
|
||||
'es7.map.from',
|
||||
'es7.set.from',
|
||||
'es7.weak-map.from',
|
||||
'es7.weak-set.from',
|
||||
'es7.global',
|
||||
'es7.system.global',
|
||||
'es7.error.is-error',
|
||||
'es7.math.clamp',
|
||||
'es7.math.deg-per-rad',
|
||||
'es7.math.degrees',
|
||||
'es7.math.fscale',
|
||||
'es7.math.iaddh',
|
||||
'es7.math.isubh',
|
||||
'es7.math.imulh',
|
||||
'es7.math.rad-per-deg',
|
||||
'es7.math.radians',
|
||||
'es7.math.scale',
|
||||
'es7.math.umulh',
|
||||
'es7.math.signbit',
|
||||
'es7.promise.finally',
|
||||
'es7.promise.try',
|
||||
'es7.reflect.define-metadata',
|
||||
'es7.reflect.delete-metadata',
|
||||
'es7.reflect.get-metadata',
|
||||
'es7.reflect.get-metadata-keys',
|
||||
'es7.reflect.get-own-metadata',
|
||||
'es7.reflect.get-own-metadata-keys',
|
||||
'es7.reflect.has-metadata',
|
||||
'es7.reflect.has-own-metadata',
|
||||
'es7.reflect.metadata',
|
||||
'es7.asap',
|
||||
'es7.observable',
|
||||
'web.immediate',
|
||||
'web.dom.iterable',
|
||||
'web.timers',
|
||||
'core.dict',
|
||||
'core.get-iterator-method',
|
||||
'core.get-iterator',
|
||||
'core.is-iterable',
|
||||
'core.delay',
|
||||
'core.function.part',
|
||||
'core.object.is-object',
|
||||
'core.object.classof',
|
||||
'core.object.define',
|
||||
'core.object.make',
|
||||
'core.number.iterator',
|
||||
'core.regexp.escape',
|
||||
'core.string.escape-html',
|
||||
'core.string.unescape-html',
|
||||
],
|
||||
experimental: [
|
||||
],
|
||||
libraryBlacklist: [
|
||||
'es6.object.to-string',
|
||||
'es6.function.name',
|
||||
'es6.regexp.constructor',
|
||||
'es6.regexp.to-string',
|
||||
'es6.regexp.flags',
|
||||
'es6.regexp.match',
|
||||
'es6.regexp.replace',
|
||||
'es6.regexp.search',
|
||||
'es6.regexp.split',
|
||||
'es6.number.constructor',
|
||||
'es6.date.to-string',
|
||||
'es6.date.to-primitive',
|
||||
],
|
||||
es5SpecialCase: [
|
||||
'es6.object.create',
|
||||
'es6.object.define-property',
|
||||
'es6.object.define-properties',
|
||||
'es6.object.get-own-property-descriptor',
|
||||
'es6.object.get-prototype-of',
|
||||
'es6.object.keys',
|
||||
'es6.object.get-own-property-names',
|
||||
'es6.object.freeze',
|
||||
'es6.object.seal',
|
||||
'es6.object.prevent-extensions',
|
||||
'es6.object.is-frozen',
|
||||
'es6.object.is-sealed',
|
||||
'es6.object.is-extensible',
|
||||
'es6.function.bind',
|
||||
'es6.array.is-array',
|
||||
'es6.array.join',
|
||||
'es6.array.slice',
|
||||
'es6.array.sort',
|
||||
'es6.array.for-each',
|
||||
'es6.array.map',
|
||||
'es6.array.filter',
|
||||
'es6.array.some',
|
||||
'es6.array.every',
|
||||
'es6.array.reduce',
|
||||
'es6.array.reduce-right',
|
||||
'es6.array.index-of',
|
||||
'es6.array.last-index-of',
|
||||
'es6.number.to-fixed',
|
||||
'es6.number.to-precision',
|
||||
'es6.date.now',
|
||||
'es6.date.to-iso-string',
|
||||
'es6.date.to-json',
|
||||
'es6.string.trim',
|
||||
'es6.regexp.to-string',
|
||||
'es6.parse-int',
|
||||
'es6.parse-float',
|
||||
],
|
||||
banner: '/**\n' +
|
||||
' * core-js ' + require('../package').version + '\n' +
|
||||
' * https://github.com/zloirock/core-js\n' +
|
||||
' * License: http://rock.mit-license.org\n' +
|
||||
' * © ' + new Date().getFullYear() + ' Denis Pushkarev\n' +
|
||||
' */',
|
||||
};
|
|
@ -1,104 +0,0 @@
|
|||
// Generated by LiveScript 1.4.0
|
||||
(function(){
|
||||
var Promise, ref$, list, experimental, libraryBlacklist, es5SpecialCase, banner, readFile, writeFile, unlink, basename, dirname, join, webpack, temp;
|
||||
Promise = require('../library/fn/promise');
|
||||
ref$ = require('./config'), list = ref$.list, experimental = ref$.experimental, libraryBlacklist = ref$.libraryBlacklist, es5SpecialCase = ref$.es5SpecialCase, banner = ref$.banner;
|
||||
ref$ = require('fs'), readFile = ref$.readFile, writeFile = ref$.writeFile, unlink = ref$.unlink;
|
||||
ref$ = require('path'), basename = ref$.basename, dirname = ref$.dirname, join = ref$.join;
|
||||
webpack = require('webpack');
|
||||
temp = require('temp');
|
||||
module.exports = function(arg$){
|
||||
var modules, ref$, blacklist, library, umd, this$ = this;
|
||||
modules = (ref$ = arg$.modules) != null
|
||||
? ref$
|
||||
: [], blacklist = (ref$ = arg$.blacklist) != null
|
||||
? ref$
|
||||
: [], library = (ref$ = arg$.library) != null ? ref$ : false, umd = (ref$ = arg$.umd) != null ? ref$ : true;
|
||||
return new Promise(function(resolve, reject){
|
||||
(function(){
|
||||
var i$, x$, ref$, len$, y$, ns, name, j$, len1$, TARGET, this$ = this;
|
||||
if (this.exp) {
|
||||
for (i$ = 0, len$ = (ref$ = experimental).length; i$ < len$; ++i$) {
|
||||
x$ = ref$[i$];
|
||||
this[x$] = true;
|
||||
}
|
||||
}
|
||||
if (this.es5) {
|
||||
for (i$ = 0, len$ = (ref$ = es5SpecialCase).length; i$ < len$; ++i$) {
|
||||
y$ = ref$[i$];
|
||||
this[y$] = true;
|
||||
}
|
||||
}
|
||||
for (ns in this) {
|
||||
if (this[ns]) {
|
||||
for (i$ = 0, len$ = (ref$ = list).length; i$ < len$; ++i$) {
|
||||
name = ref$[i$];
|
||||
if (name.indexOf(ns + ".") === 0 && !in$(name, experimental)) {
|
||||
this[name] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (library) {
|
||||
blacklist = blacklist.concat(libraryBlacklist);
|
||||
}
|
||||
for (i$ = 0, len$ = blacklist.length; i$ < len$; ++i$) {
|
||||
ns = blacklist[i$];
|
||||
for (j$ = 0, len1$ = (ref$ = list).length; j$ < len1$; ++j$) {
|
||||
name = ref$[j$];
|
||||
if (name === ns || name.indexOf(ns + ".") === 0) {
|
||||
this[name] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
TARGET = temp.path({
|
||||
suffix: '.js'
|
||||
});
|
||||
webpack({
|
||||
entry: list.filter(function(it){
|
||||
return this$[it];
|
||||
}).map(function(it){
|
||||
if (library) {
|
||||
return join(__dirname, '..', 'library', 'modules', it);
|
||||
} else {
|
||||
return join(__dirname, '..', 'modules', it);
|
||||
}
|
||||
}),
|
||||
output: {
|
||||
path: dirname(TARGET),
|
||||
filename: basename("./" + TARGET)
|
||||
}
|
||||
}, function(err, info){
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
readFile(TARGET, function(err, script){
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
unlink(TARGET, function(err){
|
||||
var exportScript;
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
if (umd) {
|
||||
exportScript = "// CommonJS export\nif (typeof module != 'undefined' && module.exports) module.exports = __e;\n// RequireJS export\nelse if (typeof define == 'function' && define.amd) define(function () { return __e; });\n// Export to global object\nelse __g.core = __e;";
|
||||
} else {
|
||||
exportScript = "";
|
||||
}
|
||||
resolve("" + banner + "\n!function(__e, __g, undefined){\n'use strict';\n" + script + "\n" + exportScript + "\n}(1, 1);");
|
||||
});
|
||||
});
|
||||
});
|
||||
}.call(modules.reduce(function(memo, it){
|
||||
memo[it] = true;
|
||||
return memo;
|
||||
}, {})));
|
||||
});
|
||||
};
|
||||
function in$(x, xs){
|
||||
var i = -1, l = xs.length >>> 0;
|
||||
while (++i < l) if (x === xs[i]) return true;
|
||||
return false;
|
||||
}
|
||||
}).call(this);
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +0,0 @@
|
|||
require('../modules/core.function.part');
|
||||
module.exports = require('../modules/_core')._;
|
|
@ -1,2 +0,0 @@
|
|||
require('../modules/core.delay');
|
||||
module.exports = require('../modules/_core').delay;
|
|
@ -1,2 +0,0 @@
|
|||
require('../modules/core.dict');
|
||||
module.exports = require('../modules/_core').Dict;
|
|
@ -1,2 +0,0 @@
|
|||
require('../modules/core.function.part');
|
||||
module.exports = require('../modules/_core').Function;
|
|
@ -1,15 +0,0 @@
|
|||
require('../modules/core.dict');
|
||||
require('../modules/core.get-iterator-method');
|
||||
require('../modules/core.get-iterator');
|
||||
require('../modules/core.is-iterable');
|
||||
require('../modules/core.delay');
|
||||
require('../modules/core.function.part');
|
||||
require('../modules/core.object.is-object');
|
||||
require('../modules/core.object.classof');
|
||||
require('../modules/core.object.define');
|
||||
require('../modules/core.object.make');
|
||||
require('../modules/core.number.iterator');
|
||||
require('../modules/core.regexp.escape');
|
||||
require('../modules/core.string.escape-html');
|
||||
require('../modules/core.string.unescape-html');
|
||||
module.exports = require('../modules/_core');
|
|
@ -1,2 +0,0 @@
|
|||
require('../modules/core.number.iterator');
|
||||
module.exports = require('../modules/_core').Number;
|
|
@ -1,5 +0,0 @@
|
|||
require('../modules/core.object.is-object');
|
||||
require('../modules/core.object.classof');
|
||||
require('../modules/core.object.define');
|
||||
require('../modules/core.object.make');
|
||||
module.exports = require('../modules/_core').Object;
|
|
@ -1,2 +0,0 @@
|
|||
require('../modules/core.regexp.escape');
|
||||
module.exports = require('../modules/_core').RegExp;
|
|
@ -1,3 +0,0 @@
|
|||
require('../modules/core.string.escape-html');
|
||||
require('../modules/core.string.unescape-html');
|
||||
module.exports = require('../modules/_core').String;
|
|
@ -1,37 +0,0 @@
|
|||
require('../modules/es6.object.create');
|
||||
require('../modules/es6.object.define-property');
|
||||
require('../modules/es6.object.define-properties');
|
||||
require('../modules/es6.object.get-own-property-descriptor');
|
||||
require('../modules/es6.object.get-prototype-of');
|
||||
require('../modules/es6.object.keys');
|
||||
require('../modules/es6.object.get-own-property-names');
|
||||
require('../modules/es6.object.freeze');
|
||||
require('../modules/es6.object.seal');
|
||||
require('../modules/es6.object.prevent-extensions');
|
||||
require('../modules/es6.object.is-frozen');
|
||||
require('../modules/es6.object.is-sealed');
|
||||
require('../modules/es6.object.is-extensible');
|
||||
require('../modules/es6.function.bind');
|
||||
require('../modules/es6.array.is-array');
|
||||
require('../modules/es6.array.join');
|
||||
require('../modules/es6.array.slice');
|
||||
require('../modules/es6.array.sort');
|
||||
require('../modules/es6.array.for-each');
|
||||
require('../modules/es6.array.map');
|
||||
require('../modules/es6.array.filter');
|
||||
require('../modules/es6.array.some');
|
||||
require('../modules/es6.array.every');
|
||||
require('../modules/es6.array.reduce');
|
||||
require('../modules/es6.array.reduce-right');
|
||||
require('../modules/es6.array.index-of');
|
||||
require('../modules/es6.array.last-index-of');
|
||||
require('../modules/es6.number.to-fixed');
|
||||
require('../modules/es6.number.to-precision');
|
||||
require('../modules/es6.date.now');
|
||||
require('../modules/es6.date.to-iso-string');
|
||||
require('../modules/es6.date.to-json');
|
||||
require('../modules/es6.parse-int');
|
||||
require('../modules/es6.parse-float');
|
||||
require('../modules/es6.string.trim');
|
||||
require('../modules/es6.regexp.to-string');
|
||||
module.exports = require('../modules/_core');
|
|
@ -1,23 +0,0 @@
|
|||
require('../modules/es6.string.iterator');
|
||||
require('../modules/es6.array.is-array');
|
||||
require('../modules/es6.array.from');
|
||||
require('../modules/es6.array.of');
|
||||
require('../modules/es6.array.join');
|
||||
require('../modules/es6.array.slice');
|
||||
require('../modules/es6.array.sort');
|
||||
require('../modules/es6.array.for-each');
|
||||
require('../modules/es6.array.map');
|
||||
require('../modules/es6.array.filter');
|
||||
require('../modules/es6.array.some');
|
||||
require('../modules/es6.array.every');
|
||||
require('../modules/es6.array.reduce');
|
||||
require('../modules/es6.array.reduce-right');
|
||||
require('../modules/es6.array.index-of');
|
||||
require('../modules/es6.array.last-index-of');
|
||||
require('../modules/es6.array.copy-within');
|
||||
require('../modules/es6.array.fill');
|
||||
require('../modules/es6.array.find');
|
||||
require('../modules/es6.array.find-index');
|
||||
require('../modules/es6.array.species');
|
||||
require('../modules/es6.array.iterator');
|
||||
module.exports = require('../modules/_core').Array;
|
|
@ -1,6 +0,0 @@
|
|||
require('../modules/es6.date.now');
|
||||
require('../modules/es6.date.to-json');
|
||||
require('../modules/es6.date.to-iso-string');
|
||||
require('../modules/es6.date.to-string');
|
||||
require('../modules/es6.date.to-primitive');
|
||||
module.exports = Date;
|
|
@ -1,4 +0,0 @@
|
|||
require('../modules/es6.function.bind');
|
||||
require('../modules/es6.function.name');
|
||||
require('../modules/es6.function.has-instance');
|
||||
module.exports = require('../modules/_core').Function;
|
|
@ -1,139 +0,0 @@
|
|||
require('../modules/es6.symbol');
|
||||
require('../modules/es6.object.create');
|
||||
require('../modules/es6.object.define-property');
|
||||
require('../modules/es6.object.define-properties');
|
||||
require('../modules/es6.object.get-own-property-descriptor');
|
||||
require('../modules/es6.object.get-prototype-of');
|
||||
require('../modules/es6.object.keys');
|
||||
require('../modules/es6.object.get-own-property-names');
|
||||
require('../modules/es6.object.freeze');
|
||||
require('../modules/es6.object.seal');
|
||||
require('../modules/es6.object.prevent-extensions');
|
||||
require('../modules/es6.object.is-frozen');
|
||||
require('../modules/es6.object.is-sealed');
|
||||
require('../modules/es6.object.is-extensible');
|
||||
require('../modules/es6.object.assign');
|
||||
require('../modules/es6.object.is');
|
||||
require('../modules/es6.object.set-prototype-of');
|
||||
require('../modules/es6.object.to-string');
|
||||
require('../modules/es6.function.bind');
|
||||
require('../modules/es6.function.name');
|
||||
require('../modules/es6.function.has-instance');
|
||||
require('../modules/es6.parse-int');
|
||||
require('../modules/es6.parse-float');
|
||||
require('../modules/es6.number.constructor');
|
||||
require('../modules/es6.number.to-fixed');
|
||||
require('../modules/es6.number.to-precision');
|
||||
require('../modules/es6.number.epsilon');
|
||||
require('../modules/es6.number.is-finite');
|
||||
require('../modules/es6.number.is-integer');
|
||||
require('../modules/es6.number.is-nan');
|
||||
require('../modules/es6.number.is-safe-integer');
|
||||
require('../modules/es6.number.max-safe-integer');
|
||||
require('../modules/es6.number.min-safe-integer');
|
||||
require('../modules/es6.number.parse-float');
|
||||
require('../modules/es6.number.parse-int');
|
||||
require('../modules/es6.math.acosh');
|
||||
require('../modules/es6.math.asinh');
|
||||
require('../modules/es6.math.atanh');
|
||||
require('../modules/es6.math.cbrt');
|
||||
require('../modules/es6.math.clz32');
|
||||
require('../modules/es6.math.cosh');
|
||||
require('../modules/es6.math.expm1');
|
||||
require('../modules/es6.math.fround');
|
||||
require('../modules/es6.math.hypot');
|
||||
require('../modules/es6.math.imul');
|
||||
require('../modules/es6.math.log10');
|
||||
require('../modules/es6.math.log1p');
|
||||
require('../modules/es6.math.log2');
|
||||
require('../modules/es6.math.sign');
|
||||
require('../modules/es6.math.sinh');
|
||||
require('../modules/es6.math.tanh');
|
||||
require('../modules/es6.math.trunc');
|
||||
require('../modules/es6.string.from-code-point');
|
||||
require('../modules/es6.string.raw');
|
||||
require('../modules/es6.string.trim');
|
||||
require('../modules/es6.string.iterator');
|
||||
require('../modules/es6.string.code-point-at');
|
||||
require('../modules/es6.string.ends-with');
|
||||
require('../modules/es6.string.includes');
|
||||
require('../modules/es6.string.repeat');
|
||||
require('../modules/es6.string.starts-with');
|
||||
require('../modules/es6.string.anchor');
|
||||
require('../modules/es6.string.big');
|
||||
require('../modules/es6.string.blink');
|
||||
require('../modules/es6.string.bold');
|
||||
require('../modules/es6.string.fixed');
|
||||
require('../modules/es6.string.fontcolor');
|
||||
require('../modules/es6.string.fontsize');
|
||||
require('../modules/es6.string.italics');
|
||||
require('../modules/es6.string.link');
|
||||
require('../modules/es6.string.small');
|
||||
require('../modules/es6.string.strike');
|
||||
require('../modules/es6.string.sub');
|
||||
require('../modules/es6.string.sup');
|
||||
require('../modules/es6.date.now');
|
||||
require('../modules/es6.date.to-json');
|
||||
require('../modules/es6.date.to-iso-string');
|
||||
require('../modules/es6.date.to-string');
|
||||
require('../modules/es6.date.to-primitive');
|
||||
require('../modules/es6.array.is-array');
|
||||
require('../modules/es6.array.from');
|
||||
require('../modules/es6.array.of');
|
||||
require('../modules/es6.array.join');
|
||||
require('../modules/es6.array.slice');
|
||||
require('../modules/es6.array.sort');
|
||||
require('../modules/es6.array.for-each');
|
||||
require('../modules/es6.array.map');
|
||||
require('../modules/es6.array.filter');
|
||||
require('../modules/es6.array.some');
|
||||
require('../modules/es6.array.every');
|
||||
require('../modules/es6.array.reduce');
|
||||
require('../modules/es6.array.reduce-right');
|
||||
require('../modules/es6.array.index-of');
|
||||
require('../modules/es6.array.last-index-of');
|
||||
require('../modules/es6.array.copy-within');
|
||||
require('../modules/es6.array.fill');
|
||||
require('../modules/es6.array.find');
|
||||
require('../modules/es6.array.find-index');
|
||||
require('../modules/es6.array.species');
|
||||
require('../modules/es6.array.iterator');
|
||||
require('../modules/es6.regexp.constructor');
|
||||
require('../modules/es6.regexp.exec');
|
||||
require('../modules/es6.regexp.to-string');
|
||||
require('../modules/es6.regexp.flags');
|
||||
require('../modules/es6.regexp.match');
|
||||
require('../modules/es6.regexp.replace');
|
||||
require('../modules/es6.regexp.search');
|
||||
require('../modules/es6.regexp.split');
|
||||
require('../modules/es6.promise');
|
||||
require('../modules/es6.map');
|
||||
require('../modules/es6.set');
|
||||
require('../modules/es6.weak-map');
|
||||
require('../modules/es6.weak-set');
|
||||
require('../modules/es6.typed.array-buffer');
|
||||
require('../modules/es6.typed.data-view');
|
||||
require('../modules/es6.typed.int8-array');
|
||||
require('../modules/es6.typed.uint8-array');
|
||||
require('../modules/es6.typed.uint8-clamped-array');
|
||||
require('../modules/es6.typed.int16-array');
|
||||
require('../modules/es6.typed.uint16-array');
|
||||
require('../modules/es6.typed.int32-array');
|
||||
require('../modules/es6.typed.uint32-array');
|
||||
require('../modules/es6.typed.float32-array');
|
||||
require('../modules/es6.typed.float64-array');
|
||||
require('../modules/es6.reflect.apply');
|
||||
require('../modules/es6.reflect.construct');
|
||||
require('../modules/es6.reflect.define-property');
|
||||
require('../modules/es6.reflect.delete-property');
|
||||
require('../modules/es6.reflect.enumerate');
|
||||
require('../modules/es6.reflect.get');
|
||||
require('../modules/es6.reflect.get-own-property-descriptor');
|
||||
require('../modules/es6.reflect.get-prototype-of');
|
||||
require('../modules/es6.reflect.has');
|
||||
require('../modules/es6.reflect.is-extensible');
|
||||
require('../modules/es6.reflect.own-keys');
|
||||
require('../modules/es6.reflect.prevent-extensions');
|
||||
require('../modules/es6.reflect.set');
|
||||
require('../modules/es6.reflect.set-prototype-of');
|
||||
module.exports = require('../modules/_core');
|
|
@ -1,5 +0,0 @@
|
|||
require('../modules/es6.object.to-string');
|
||||
require('../modules/es6.string.iterator');
|
||||
require('../modules/web.dom.iterable');
|
||||
require('../modules/es6.map');
|
||||
module.exports = require('../modules/_core').Map;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue