new license file version [CI SKIP]
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: ljharb
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: npm/is-negative-zero
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,523 @@
|
||||
<div align="center">
|
||||
<br>
|
||||
<br>
|
||||
<img width="360" src="media/logo.svg" alt="Got">
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<p>
|
||||
<p>
|
||||
<sup>
|
||||
Sindre's open source work is supported by the community.<br>Special thanks to:
|
||||
</sup>
|
||||
</p>
|
||||
<br>
|
||||
<a href="https://retool.com/?utm_campaign=sindresorhus">
|
||||
<img src="https://sindresorhus.com/assets/thanks/retool-logo.svg" width="210">
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://strapi.io/?ref=sindresorhus">
|
||||
<div>
|
||||
<img src="https://sindresorhus.com/assets/thanks/strapi-logo-white-bg.png" width="200" alt="Strapi">
|
||||
</div>
|
||||
<b>Strapi is the leading open-source headless CMS.</b>
|
||||
<div>
|
||||
<sup>It’s 100% JavaScript, fully customizable, and developer-first.</sup>
|
||||
</div>
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-light-mode-only">
|
||||
<div>
|
||||
<img src="https://sindresorhus.com/assets/thanks/anvil-logo-light.svg" width="200" alt="Anvil">
|
||||
</div>
|
||||
<br>
|
||||
<b>Paperwork that makes the data work.</b>
|
||||
<div>
|
||||
<sub>
|
||||
Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms.
|
||||
<br>
|
||||
The easiest way to build paperwork automation into your product.
|
||||
</sub>
|
||||
</div>
|
||||
</a>
|
||||
<a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-dark-mode-only">
|
||||
<div>
|
||||
<img src="https://sindresorhus.com/assets/thanks/anvil-logo-dark.svg" width="200" alt="Anvil">
|
||||
</div>
|
||||
<br>
|
||||
<b>Paperwork that makes the data work.</b>
|
||||
<div>
|
||||
<sub>
|
||||
Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms.
|
||||
<br>
|
||||
The easiest way to build paperwork automation into your product.
|
||||
</sub>
|
||||
</div>
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
</p>
|
||||
<br>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
> Human-friendly and powerful HTTP request library for Node.js
|
||||
|
||||
<!-- [](https://codecov.io/gh/sindresorhus/got/branch/main) -->
|
||||
[](https://npmjs.com/got)
|
||||
[](https://packagephobia.com/result?p=got)
|
||||
|
||||
[See how Got compares to other HTTP libraries](#comparison)
|
||||
|
||||
---
|
||||
|
||||
For browser usage, we recommend [Ky](https://github.com/sindresorhus/ky) by the same people.
|
||||
|
||||
---
|
||||
|
||||
**Support questions should be asked [here](https://github.com/sindresorhus/got/discussions).**
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install got
|
||||
```
|
||||
|
||||
**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you will have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM.
|
||||
|
||||
**Got v11 (the previous major version) is no longer maintained and we will not accept any backport requests.**
|
||||
|
||||
## Take a peek
|
||||
|
||||
**A [quick start](documentation/quick-start.md) guide is available.**
|
||||
|
||||
### JSON mode
|
||||
|
||||
Got has a dedicated option for handling JSON payload.\
|
||||
Furthermore, the promise exposes a `.json<T>()` function that returns `Promise<T>`.
|
||||
|
||||
```js
|
||||
import got from 'got';
|
||||
|
||||
const {data} = await got.post('https://httpbin.org/anything', {
|
||||
json: {
|
||||
hello: 'world'
|
||||
}
|
||||
}).json();
|
||||
|
||||
console.log(data);
|
||||
//=> {"hello": "world"}
|
||||
```
|
||||
|
||||
For advanced JSON usage, check out the [`parseJson`](documentation/2-options.md#parsejson) and [`stringifyJson`](documentation/2-options.md#stringifyjson) options.
|
||||
|
||||
**For more useful tips like this, visit the [Tips](documentation/tips.md) page.**
|
||||
|
||||
## Highlights
|
||||
|
||||
- [Used by 8K+ packages and 4M+ repos](https://github.com/sindresorhus/got/network/dependents)
|
||||
- [Actively maintained](https://github.com/sindresorhus/got/graphs/contributors)
|
||||
- [Trusted by many companies](#widely-used)
|
||||
|
||||
## Documentation
|
||||
|
||||
By default, Got will retry on failure. To disable this option, set [`options.retry.limit`](documentation/7-retry.md#retry) to 0.
|
||||
|
||||
#### Main API
|
||||
|
||||
- [x] [Promise API](documentation/1-promise.md)
|
||||
- [x] [Options](documentation/2-options.md)
|
||||
- [x] [Stream API](documentation/3-streams.md)
|
||||
- [x] [Pagination API](documentation/4-pagination.md)
|
||||
- [x] [Advanced HTTPS API](documentation/5-https.md)
|
||||
- [x] [HTTP/2 support](documentation/2-options.md#http2)
|
||||
- [x] [`Response` class](documentation/3-streams.md#response-2)
|
||||
|
||||
#### Timeouts and retries
|
||||
|
||||
- [x] [Advanced timeout handling](documentation/6-timeout.md)
|
||||
- [x] [Retries on failure](documentation/7-retry.md)
|
||||
- [x] [Errors with metadata](documentation/8-errors.md)
|
||||
|
||||
#### Advanced creation
|
||||
|
||||
- [x] [Hooks](documentation/9-hooks.md)
|
||||
- [x] [Instances](documentation/10-instances.md)
|
||||
- [x] [Progress events & other events](documentation/3-streams.md#events)
|
||||
- [x] [Plugins](documentation/lets-make-a-plugin.md)
|
||||
- [x] [Compose](documentation/examples/advanced-creation.js)
|
||||
|
||||
#### Cache, Proxy and UNIX sockets
|
||||
|
||||
- [x] [RFC compliant caching](documentation/cache.md)
|
||||
- [x] [Proxy support](documentation/tips.md#proxying)
|
||||
- [x] [Unix Domain Sockets](documentation/2-options.md#enableunixsockets)
|
||||
|
||||
#### Integration
|
||||
|
||||
- [x] [TypeScript support](documentation/typescript.md)
|
||||
- [x] [AWS](documentation/tips.md#aws)
|
||||
- [x] [Testing](documentation/tips.md#testing)
|
||||
|
||||
---
|
||||
|
||||
### Migration guides
|
||||
|
||||
- [Request migration guide](documentation/migration-guides/request.md)
|
||||
- [*(Note that Request is unmaintained)*](https://github.com/request/request/issues/3142)
|
||||
- [Axios](documentation/migration-guides/axios.md)
|
||||
- [Node.js](documentation/migration-guides/nodejs.md)
|
||||
|
||||
## Got plugins
|
||||
|
||||
- [`got4aws`](https://github.com/SamVerschueren/got4aws) - Got convenience wrapper to interact with AWS v4 signed APIs
|
||||
- [`gh-got`](https://github.com/sindresorhus/gh-got) - Got convenience wrapper to interact with the GitHub API
|
||||
- [`gl-got`](https://github.com/singapore/gl-got) - Got convenience wrapper to interact with the GitLab API
|
||||
- [`gotql`](https://github.com/khaosdoctor/gotql) - Got convenience wrapper to interact with GraphQL using JSON-parsed queries instead of strings
|
||||
- [`got-fetch`](https://github.com/alexghr/got-fetch) - Got with a [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) interface
|
||||
- [`got-scraping`](https://github.com/apify/got-scraping) - Got wrapper specifically designed for web scraping purposes
|
||||
- [`got-ssrf`](https://github.com/JaneJeon/got-ssrf) - Got wrapper to protect server-side requests against SSRF attacks
|
||||
|
||||
### Legacy
|
||||
|
||||
- [travis-got](https://github.com/samverschueren/travis-got) - Got convenience wrapper to interact with the Travis API
|
||||
- [graphql-got](https://github.com/kevva/graphql-got) - Got convenience wrapper to interact with GraphQL
|
||||
|
||||
## Comparison
|
||||
|
||||
| | `got` | [`node-fetch`][n0] | [`ky`][k0] | [`axios`][a0] | [`superagent`][s0] |
|
||||
|-----------------------|:-------------------:|:--------------------:|:------------------------:|:------------------:|:----------------------:|
|
||||
| HTTP/2 support | :heavy_check_mark:¹ | :x: | :x: | :x: | :heavy_check_mark:\*\* |
|
||||
| Browser support | :x: | :heavy_check_mark:\* | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Promise API | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Stream API | :heavy_check_mark: | Node.js only | :x: | :x: | :heavy_check_mark: |
|
||||
| Pagination API | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
||||
| Request cancelation | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| RFC compliant caching | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
||||
| Cookies (out-of-box) | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
||||
| Follows redirects | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Retries on failure | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Progress events | :heavy_check_mark: | :x: | :heavy_check_mark:\*\*\* | Browser only | :heavy_check_mark: |
|
||||
| Handles gzip/deflate | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Advanced timeouts | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
||||
| Timings | :heavy_check_mark: | :x: | :x: | :x: | :x: |
|
||||
| Errors with metadata | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| JSON mode | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Custom defaults | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Composable | :heavy_check_mark: | :x: | :x: | :x: | :heavy_check_mark: |
|
||||
| Hooks | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Issues open | [![][gio]][g1] | [![][nio]][n1] | [![][kio]][k1] | [![][aio]][a1] | [![][sio]][s1] |
|
||||
| Issues closed | [![][gic]][g2] | [![][nic]][n2] | [![][kic]][k2] | [![][aic]][a2] | [![][sic]][s2] |
|
||||
| Downloads | [![][gd]][g3] | [![][nd]][n3] | [![][kd]][k3] | [![][ad]][a3] | [![][sd]][s3] |
|
||||
| Coverage | TBD | [![][nc]][n4] | [![][kc]][k4] | [![][ac]][a4] | [![][sc]][s4] |
|
||||
| Build | [![][gb]][g5] | [![][nb]][n5] | [![][kb]][k5] | [![][ab]][a5] | [![][sb]][s5] |
|
||||
| Bugs | [![][gbg]][g6] | [![][nbg]][n6] | [![][kbg]][k6] | [![][abg]][a6] | [![][sbg]][s6] |
|
||||
| Dependents | [![][gdp]][g7] | [![][ndp]][n7] | [![][kdp]][k7] | [![][adp]][a7] | [![][sdp]][s7] |
|
||||
| Install size | [![][gis]][g8] | [![][nis]][n8] | [![][kis]][k8] | [![][ais]][a8] | [![][sis]][s8] |
|
||||
| GitHub stars | [![][gs]][g9] | [![][ns]][n9] | [![][ks]][k9] | [![][as]][a9] | [![][ss]][s9] |
|
||||
| TypeScript support | [![][gts]][g10] | [![][nts]][n10] | [![][kts]][k10] | [![][ats]][a10] | [![][sts]][s11] |
|
||||
| Last commit | [![][glc]][g11] | [![][nlc]][n11] | [![][klc]][k11] | [![][alc]][a11] | [![][slc]][s11] |
|
||||
|
||||
\* It's almost API compatible with the browser `fetch` API.\
|
||||
\*\* Need to switch the protocol manually. Doesn't accept PUSH streams and doesn't reuse HTTP/2 sessions.\
|
||||
\*\*\* Currently, only `DownloadProgress` event is supported, `UploadProgress` event is not supported.\
|
||||
¹ Requires Node.js 15.10.0 or above.\
|
||||
:sparkle: Almost-stable feature, but the API may change. Don't hesitate to try it out!\
|
||||
:grey_question: Feature in early stage of development. Very experimental.
|
||||
|
||||
<!-- GITHUB -->
|
||||
[k0]: https://github.com/sindresorhus/ky
|
||||
[n0]: https://github.com/node-fetch/node-fetch
|
||||
[a0]: https://github.com/axios/axios
|
||||
[s0]: https://github.com/visionmedia/superagent
|
||||
|
||||
<!-- ISSUES OPEN -->
|
||||
[gio]: https://img.shields.io/github/issues-raw/sindresorhus/got?color=gray&label
|
||||
[kio]: https://img.shields.io/github/issues-raw/sindresorhus/ky?color=gray&label
|
||||
[nio]: https://img.shields.io/github/issues-raw/bitinn/node-fetch?color=gray&label
|
||||
[aio]: https://img.shields.io/github/issues-raw/axios/axios?color=gray&label
|
||||
[sio]: https://img.shields.io/github/issues-raw/visionmedia/superagent?color=gray&label
|
||||
|
||||
[g1]: https://github.com/sindresorhus/got/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
|
||||
[k1]: https://github.com/sindresorhus/ky/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
|
||||
[n1]: https://github.com/bitinn/node-fetch/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
|
||||
[a1]: https://github.com/axios/axios/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
|
||||
[s1]: https://github.com/visionmedia/superagent/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
|
||||
|
||||
<!-- ISSUES CLOSED -->
|
||||
[gic]: https://img.shields.io/github/issues-closed-raw/sindresorhus/got?color=blue&label
|
||||
[kic]: https://img.shields.io/github/issues-closed-raw/sindresorhus/ky?color=blue&label
|
||||
[nic]: https://img.shields.io/github/issues-closed-raw/bitinn/node-fetch?color=blue&label
|
||||
[aic]: https://img.shields.io/github/issues-closed-raw/axios/axios?color=blue&label
|
||||
[sic]: https://img.shields.io/github/issues-closed-raw/visionmedia/superagent?color=blue&label
|
||||
|
||||
[g2]: https://github.com/sindresorhus/got/issues?q=is%3Aissue+is%3Aclosed+sort%3Aupdated-desc
|
||||
[k2]: https://github.com/sindresorhus/ky/issues?q=is%3Aissue+is%3Aclosed+sort%3Aupdated-desc
|
||||
[n2]: https://github.com/bitinn/node-fetch/issues?q=is%3Aissue+is%3Aclosed+sort%3Aupdated-desc
|
||||
[a2]: https://github.com/axios/axios/issues?q=is%3Aissue+is%3Aclosed+sort%3Aupdated-desc
|
||||
[s2]: https://github.com/visionmedia/superagent/issues?q=is%3Aissue+is%3Aclosed+sort%3Aupdated-desc
|
||||
|
||||
<!-- DOWNLOADS -->
|
||||
[gd]: https://img.shields.io/npm/dm/got?color=darkgreen&label
|
||||
[kd]: https://img.shields.io/npm/dm/ky?color=darkgreen&label
|
||||
[nd]: https://img.shields.io/npm/dm/node-fetch?color=darkgreen&label
|
||||
[ad]: https://img.shields.io/npm/dm/axios?color=darkgreen&label
|
||||
[sd]: https://img.shields.io/npm/dm/superagent?color=darkgreen&label
|
||||
|
||||
[g3]: https://www.npmjs.com/package/got
|
||||
[k3]: https://www.npmjs.com/package/ky
|
||||
[n3]: https://www.npmjs.com/package/node-fetch
|
||||
[a3]: https://www.npmjs.com/package/axios
|
||||
[s3]: https://www.npmjs.com/package/superagent
|
||||
|
||||
<!-- COVERAGE -->
|
||||
[gc]: https://img.shields.io/coveralls/github/sindresorhus/got?color=0b9062&label
|
||||
[kc]: https://img.shields.io/codecov/c/github/sindresorhus/ky?color=0b9062&label
|
||||
[nc]: https://img.shields.io/coveralls/github/bitinn/node-fetch?color=0b9062&label
|
||||
[ac]: https://img.shields.io/coveralls/github/mzabriskie/axios?color=0b9062&label
|
||||
[sc]: https://img.shields.io/codecov/c/github/visionmedia/superagent?color=0b9062&label
|
||||
|
||||
[g4]: https://coveralls.io/github/sindresorhus/got
|
||||
[k4]: https://codecov.io/gh/sindresorhus/ky
|
||||
[n4]: https://coveralls.io/github/bitinn/node-fetch
|
||||
[a4]: https://coveralls.io/github/mzabriskie/axios
|
||||
[s4]: https://codecov.io/gh/visionmedia/superagent
|
||||
|
||||
<!-- BUILD -->
|
||||
[gb]: https://github.com/sindresorhus/got/actions/workflows/main.yml/badge.svg
|
||||
[kb]: https://github.com/sindresorhus/ky/actions/workflows/main.yml/badge.svg
|
||||
[nb]: https://img.shields.io/travis/bitinn/node-fetch?label
|
||||
[ab]: https://img.shields.io/travis/axios/axios?label
|
||||
[sb]: https://img.shields.io/travis/visionmedia/superagent?label
|
||||
|
||||
[g5]: https://github.com/sindresorhus/got/actions/workflows/main.yml
|
||||
[k5]: https://github.com/sindresorhus/ky/actions/workflows/main.yml
|
||||
[n5]: https://travis-ci.org/github/bitinn/node-fetch
|
||||
[a5]: https://travis-ci.org/github/axios/axios
|
||||
[s5]: https://travis-ci.org/github/visionmedia/superagent
|
||||
|
||||
<!-- BUGS -->
|
||||
[gbg]: https://img.shields.io/github/issues-raw/sindresorhus/got/bug?color=darkred&label
|
||||
[kbg]: https://img.shields.io/github/issues-raw/sindresorhus/ky/bug?color=darkred&label
|
||||
[nbg]: https://img.shields.io/github/issues-raw/bitinn/node-fetch/bug?color=darkred&label
|
||||
[abg]: https://img.shields.io/github/issues-raw/axios/axios/type:confirmed%20bug?color=darkred&label
|
||||
[sbg]: https://img.shields.io/github/issues-raw/visionmedia/superagent/Bug?color=darkred&label
|
||||
|
||||
[g6]: https://github.com/sindresorhus/got/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abug
|
||||
[k6]: https://github.com/sindresorhus/ky/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abug
|
||||
[n6]: https://github.com/bitinn/node-fetch/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abug
|
||||
[a6]: https://github.com/axios/axios/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22type%3Aconfirmed+bug%22
|
||||
[s6]: https://github.com/visionmedia/superagent/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3ABug
|
||||
|
||||
<!-- DEPENDENTS -->
|
||||
[gdp]: https://badgen.net/npm/dependents/got?color=orange&label
|
||||
[kdp]: https://badgen.net/npm/dependents/ky?color=orange&label
|
||||
[ndp]: https://badgen.net/npm/dependents/node-fetch?color=orange&label
|
||||
[adp]: https://badgen.net/npm/dependents/axios?color=orange&label
|
||||
[sdp]: https://badgen.net/npm/dependents/superagent?color=orange&label
|
||||
|
||||
[g7]: https://www.npmjs.com/package/got?activeTab=dependents
|
||||
[k7]: https://www.npmjs.com/package/ky?activeTab=dependents
|
||||
[n7]: https://www.npmjs.com/package/node-fetch?activeTab=dependents
|
||||
[a7]: https://www.npmjs.com/package/axios?activeTab=dependents
|
||||
[s7]: https://www.npmjs.com/package/visionmedia?activeTab=dependents
|
||||
|
||||
<!-- INSTALL SIZE -->
|
||||
[gis]: https://badgen.net/packagephobia/install/got?color=blue&label
|
||||
[kis]: https://badgen.net/packagephobia/install/ky?color=blue&label
|
||||
[nis]: https://badgen.net/packagephobia/install/node-fetch?color=blue&label
|
||||
[ais]: https://badgen.net/packagephobia/install/axios?color=blue&label
|
||||
[sis]: https://badgen.net/packagephobia/install/superagent?color=blue&label
|
||||
|
||||
[g8]: https://packagephobia.com/result?p=got
|
||||
[k8]: https://packagephobia.com/result?p=ky
|
||||
[n8]: https://packagephobia.com/result?p=node-fetch
|
||||
[a8]: https://packagephobia.com/result?p=axios
|
||||
[s8]: https://packagephobia.com/result?p=superagent
|
||||
|
||||
<!-- GITHUB STARS -->
|
||||
[gs]: https://img.shields.io/github/stars/sindresorhus/got?color=white&label
|
||||
[ks]: https://img.shields.io/github/stars/sindresorhus/ky?color=white&label
|
||||
[ns]: https://img.shields.io/github/stars/bitinn/node-fetch?color=white&label
|
||||
[as]: https://img.shields.io/github/stars/axios/axios?color=white&label
|
||||
[ss]: https://img.shields.io/github/stars/visionmedia/superagent?color=white&label
|
||||
|
||||
[g9]: https://github.com/sindresorhus/got
|
||||
[k9]: https://github.com/sindresorhus/ky
|
||||
[n9]: https://github.com/node-fetch/node-fetch
|
||||
[a9]: https://github.com/axios/axios
|
||||
[s9]: https://github.com/visionmedia/superagent
|
||||
|
||||
<!-- TYPESCRIPT SUPPORT -->
|
||||
[gts]: https://badgen.net/npm/types/got?label
|
||||
[kts]: https://badgen.net/npm/types/ky?label
|
||||
[nts]: https://badgen.net/npm/types/node-fetch?label
|
||||
[ats]: https://badgen.net/npm/types/axios?label
|
||||
[sts]: https://badgen.net/npm/types/superagent?label
|
||||
|
||||
[g10]: https://github.com/sindresorhus/got
|
||||
[k10]: https://github.com/sindresorhus/ky
|
||||
[n10]: https://github.com/node-fetch/node-fetch
|
||||
[a10]: https://github.com/axios/axios
|
||||
[s10]: https://github.com/visionmedia/superagent
|
||||
|
||||
<!-- LAST COMMIT -->
|
||||
[glc]: https://img.shields.io/github/last-commit/sindresorhus/got?color=gray&label
|
||||
[klc]: https://img.shields.io/github/last-commit/sindresorhus/ky?color=gray&label
|
||||
[nlc]: https://img.shields.io/github/last-commit/bitinn/node-fetch?color=gray&label
|
||||
[alc]: https://img.shields.io/github/last-commit/axios/axios?color=gray&label
|
||||
[slc]: https://img.shields.io/github/last-commit/visionmedia/superagent?color=gray&label
|
||||
|
||||
[g11]: https://github.com/sindresorhus/got/commits
|
||||
[k11]: https://github.com/sindresorhus/ky/commits
|
||||
[n11]: https://github.com/node-fetch/node-fetch/commits
|
||||
[a11]: https://github.com/axios/axios/commits
|
||||
[s11]: https://github.com/visionmedia/superagent/commits
|
||||
|
||||
[Click here][InstallSizeOfTheDependencies] to see the install size of the Got dependencies.
|
||||
|
||||
[InstallSizeOfTheDependencies]: https://packagephobia.com/result?p=@sindresorhus/is@4.0.1,@szmarczak/http-timer@4.0.5,@types/cacheable-request@6.0.1,@types/responselike@1.0.0,cacheable-lookup@6.0.0,cacheable-request@7.0.2,decompress-response@6.0.0,get-stream@6.0.1,http2-wrapper@2.0.5,lowercase-keys@2.0.0,p-cancelable@2.1.1,responselike@2.0.0
|
||||
|
||||
## Maintainers
|
||||
|
||||
[](https://sindresorhus.com) | [](https://github.com/szmarczak)
|
||||
---|---
|
||||
[Sindre Sorhus](https://sindresorhus.com) | [Szymon Marczak](https://github.com/szmarczak)
|
||||
|
||||
###### Former
|
||||
|
||||
- [Vsevolod Strukchinsky](https://github.com/floatdrop)
|
||||
- [Alexander Tesfamichael](https://github.com/alextes)
|
||||
- [Brandon Smith](https://github.com/brandon93s)
|
||||
- [Luke Childs](https://github.com/lukechilds)
|
||||
- [Giovanni Minotti](https://github.com/Giotino)
|
||||
|
||||
<a name="widely-used"></a>
|
||||
## These amazing companies are using Got
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="https://segment.com">
|
||||
<img width="90" valign="middle" src="https://user-images.githubusercontent.com/697676/47693700-ddb62500-dbb7-11e8-8332-716a91010c2d.png">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://antora.org">
|
||||
<img width="100" valign="middle" src="https://user-images.githubusercontent.com/79351/47706840-d874cc80-dbef-11e8-87c6-5f0c60cbf5dc.png">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://getvoip.com">
|
||||
<img width="150" valign="middle" src="https://user-images.githubusercontent.com/10832620/47869404-429e9480-dddd-11e8-8a7a-ca43d7f06020.png">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/exoframejs/exoframe">
|
||||
<img width="150" valign="middle" src="https://user-images.githubusercontent.com/365944/47791460-11a95b80-dd1a-11e8-9070-e8f2a215e03a.png">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="http://karaokes.moe">
|
||||
<img width="140" valign="middle" src="https://camo.githubusercontent.com/6860e5fa4684c14d8e1aa65df0aba4e6808ea1a9/687474703a2f2f6b6172616f6b65732e6d6f652f6173736574732f696d616765732f696e6465782e706e67">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/renovatebot/renovate">
|
||||
<img width="150" valign="middle" src="https://camo.githubusercontent.com/206d470ac709b9a702a97b0c08d6f389a086793d/68747470733a2f2f72656e6f76617465626f742e636f6d2f696d616765732f6c6f676f2e737667">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://resist.bot">
|
||||
<img width="150" valign="middle" src="https://user-images.githubusercontent.com/3322287/51992724-28736180-2473-11e9-9764-599cfda4b012.png">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://www.naturalcycles.com">
|
||||
<img width="150" valign="middle" src="https://user-images.githubusercontent.com/170270/92244143-d0a8a200-eec2-11ea-9fc0-1c07f90b2113.png">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="https://microlink.io">
|
||||
<img width="150" valign="middle" src="https://user-images.githubusercontent.com/36894700/91992974-1cc5dc00-ed35-11ea-9d04-f58b42ce6a5e.png">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://radity.com">
|
||||
<img width="150" valign="middle" src="https://user-images.githubusercontent.com/29518613/91814036-97fb9500-ec44-11ea-8c6c-d198cc23ca29.png">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://apify.com">
|
||||
<img width="150" valign="middle" src="https://user-images.githubusercontent.com/23726914/128673143-958b5930-b677-40ef-8087-5698a0c29c45.png">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- <br> -->
|
||||
|
||||
<!-- *Creating an awesome product? Open an issue to get listed here.* -->
|
||||
|
||||
<br>
|
||||
|
||||
> Segment is a happy user of Got! Got powers the main backend API that our app talks to. It's used by our in-house RPC client that we use to communicate with all microservices.
|
||||
>
|
||||
> — <a href="https://github.com/vadimdemedes">Vadim Demedes</a>
|
||||
|
||||
> Antora, a static site generator for creating documentation sites, uses Got to download the UI bundle. In Antora, the UI bundle (aka theme) is maintained as a separate project. That project exports the UI as a zip file we call the UI bundle. The main site generator downloads that UI from a URL using Got and streams it to vinyl-zip to extract the files. Those files go on to be used to create the HTML pages and supporting assets.
|
||||
>
|
||||
> — <a href="https://github.com/mojavelinux">Dan Allen</a>
|
||||
|
||||
> GetVoIP is happily using Got in production. One of the unique capabilities of Got is the ability to handle Unix sockets which enables us to build a full control interfaces for our docker stack.
|
||||
>
|
||||
> — <a href="https://github.com/danielkalen">Daniel Kalen</a>
|
||||
|
||||
> We're using Got inside of Exoframe to handle all the communication between CLI and server. Exoframe is a self-hosted tool that allows simple one-command deployments using Docker.
|
||||
>
|
||||
> — <a href="https://github.com/yamalight">Tim Ermilov</a>
|
||||
|
||||
> Karaoke Mugen uses Got to fetch content updates from its online server.
|
||||
>
|
||||
> — <a href="https://github.com/AxelTerizaki">Axel Terizaki</a>
|
||||
|
||||
> Renovate uses Got, gh-got and gl-got to send millions of queries per day to GitHub, GitLab, npmjs, PyPi, Packagist, Docker Hub, Terraform, CircleCI, and more.
|
||||
>
|
||||
> — <a href="https://github.com/rarkins">Rhys Arkins</a>
|
||||
|
||||
> Resistbot uses Got to communicate from the API frontend where all correspondence ingresses to the officials lookup database in back.
|
||||
>
|
||||
> — <a href="https://github.com/chris-erickson">Chris Erickson</a>
|
||||
|
||||
> Natural Cycles is using Got to communicate with all kinds of 3rd-party REST APIs (over 9000!).
|
||||
>
|
||||
> — <a href="https://github.com/kirillgroshkov">Kirill Groshkov</a>
|
||||
|
||||
> Microlink is a cloud browser as an API service that uses Got widely as the main HTTP client, serving ~22M requests a month, every time a network call needs to be performed.
|
||||
>
|
||||
> — <a href="https://github.com/Kikobeats">Kiko Beats</a>
|
||||
|
||||
> We’re using Got at Radity. Thanks for such an amazing work!
|
||||
>
|
||||
> — <a href="https://github.com/MirzayevFarid">Mirzayev Farid</a>
|
||||
|
||||
> Got has been a crucial component of Apify's scraping for years. We use it to extract data from billions of web pages every month, and we really appreciate the powerful API and extensibility, which allowed us to build our own specialized HTTP client on top of Got. The support has always been stellar too.
|
||||
>
|
||||
> — <a href="https://github.com/mnmkng">Ondra Urban</a>
|
||||
|
||||
## For enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription.
|
||||
|
||||
The maintainers of `got` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-got?utm_source=npm-got&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
Detect whether the terminal supports Unicode.
|
||||
|
||||
@example
|
||||
```
|
||||
import isUnicodeSupported from 'is-unicode-supported';
|
||||
|
||||
isUnicodeSupported();
|
||||
//=> true
|
||||
```
|
||||
*/
|
||||
export default function isUnicodeSupported(): boolean;
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
@license
|
||||
Rollup.js v2.79.1
|
||||
Thu, 22 Sep 2022 04:55:29 GMT - commit 69ff4181e701a0fe0026d0ba147f31bc86beffa8
|
||||
|
||||
https://github.com/rollup/rollup
|
||||
|
||||
Released under the MIT License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
||||
|
||||
const rollup = require('./shared/rollup.js');
|
||||
require('path');
|
||||
require('process');
|
||||
require('perf_hooks');
|
||||
require('crypto');
|
||||
require('fs');
|
||||
require('events');
|
||||
|
||||
|
||||
|
||||
exports.VERSION = rollup.version;
|
||||
exports.defineConfig = rollup.defineConfig;
|
||||
exports.rollup = rollup.rollup;
|
||||
exports.watch = rollup.watch;
|
||||
//# sourceMappingURL=rollup.js.map
|
||||
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "human-signals",
|
||||
"version": "2.1.0",
|
||||
"main": "build/src/main.js",
|
||||
"files": [
|
||||
"build/src",
|
||||
"!~"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "gulp test"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-push": "gulp check --full"
|
||||
}
|
||||
},
|
||||
"description": "Human-friendly process signals",
|
||||
"keywords": [
|
||||
"signal",
|
||||
"signals",
|
||||
"handlers",
|
||||
"error-handling",
|
||||
"errors",
|
||||
"interrupts",
|
||||
"sigterm",
|
||||
"sigint",
|
||||
"irq",
|
||||
"process",
|
||||
"exit",
|
||||
"exit-code",
|
||||
"status",
|
||||
"operating-system",
|
||||
"es6",
|
||||
"javascript",
|
||||
"linux",
|
||||
"macos",
|
||||
"windows",
|
||||
"nodejs"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"homepage": "https://git.io/JeluP",
|
||||
"repository": "ehmicky/human-signals",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ehmicky/human-signals/issues"
|
||||
},
|
||||
"author": "ehmicky <ehmicky@gmail.com> (https://github.com/ehmicky)",
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"test": "test"
|
||||
},
|
||||
"types": "build/src/main.d.ts",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@ehmicky/dev-tasks": "^0.31.9",
|
||||
"ajv": "^6.12.0",
|
||||
"ava": "^3.5.0",
|
||||
"gulp": "^4.0.2",
|
||||
"husky": "^4.2.3",
|
||||
"test-each": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.17.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
var copyObject = require('./_copyObject'),
|
||||
createAssigner = require('./_createAssigner'),
|
||||
keysIn = require('./keysIn');
|
||||
|
||||
/**
|
||||
* This method is like `_.assign` except that it iterates over own and
|
||||
* inherited source properties.
|
||||
*
|
||||
* **Note:** This method mutates `object`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @alias extend
|
||||
* @category Object
|
||||
* @param {Object} object The destination object.
|
||||
* @param {...Object} [sources] The source objects.
|
||||
* @returns {Object} Returns `object`.
|
||||
* @see _.assign
|
||||
* @example
|
||||
*
|
||||
* function Foo() {
|
||||
* this.a = 1;
|
||||
* }
|
||||
*
|
||||
* function Bar() {
|
||||
* this.c = 3;
|
||||
* }
|
||||
*
|
||||
* Foo.prototype.b = 2;
|
||||
* Bar.prototype.d = 4;
|
||||
*
|
||||
* _.assignIn({ 'a': 0 }, new Foo, new Bar);
|
||||
* // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
||||
*/
|
||||
var assignIn = createAssigner(function(object, source) {
|
||||
copyObject(source, keysIn(source), object);
|
||||
});
|
||||
|
||||
module.exports = assignIn;
|
||||
@@ -0,0 +1,40 @@
|
||||
import {ProcessorLocal} from "./ProcessorLocal";
|
||||
import { Converter } from "./Converter";
|
||||
import P from "bluebird";
|
||||
import {readFileSync} from "fs";
|
||||
import path from "path";
|
||||
import assert from "assert";
|
||||
import { JSONResult } from "./lineToJson";
|
||||
const dataDir=path.join(__dirname,"../test/data/");
|
||||
describe("ProcessLocal",()=>{
|
||||
it ("should process csv chunks and output json",async function (){
|
||||
const processor=new ProcessorLocal(new Converter());
|
||||
const data=readFileSync(dataDir+"/complexJSONCSV");
|
||||
const lines=await processor.process(data);
|
||||
assert(lines.length === 2);
|
||||
const line0=lines[0] as JSONResult;
|
||||
assert.equal(line0.fieldA.title,"Food Factory");
|
||||
assert.equal(line0.fieldA.children.length,2);
|
||||
assert.equal(line0.fieldA.children[1].employee[0].name,"Tim");
|
||||
})
|
||||
it ("should process csv chunks and output csv rows",async function (){
|
||||
const processor=new ProcessorLocal(new Converter({output:"line"}));
|
||||
const data=readFileSync(dataDir+"/complexJSONCSV");
|
||||
const lines=await processor.process(data);
|
||||
|
||||
assert(lines.length === 2);
|
||||
})
|
||||
it ("should return empty array if preRawHook removed the data",()=>{
|
||||
const conv=new Converter();
|
||||
conv.preRawData((str)=>{
|
||||
return "";
|
||||
});
|
||||
const processor=new ProcessorLocal(conv);
|
||||
const data=readFileSync(dataDir+"/complexJSONCSV");
|
||||
return processor.process(data)
|
||||
.then((list)=>{
|
||||
assert.equal(list.length,0);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { operate } from '../util/lift';
|
||||
import { createOperatorSubscriber } from './OperatorSubscriber';
|
||||
export function takeWhile(predicate, inclusive) {
|
||||
if (inclusive === void 0) { inclusive = false; }
|
||||
return operate(function (source, subscriber) {
|
||||
var index = 0;
|
||||
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
||||
var result = predicate(value, index++);
|
||||
(result || inclusive) && subscriber.next(value);
|
||||
!result && subscriber.complete();
|
||||
}));
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=takeWhile.js.map
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "for-each",
|
||||
"version": "0.3.3",
|
||||
"description": "A better forEach",
|
||||
"keywords": [],
|
||||
"author": "Raynos <raynos2@gmail.com>",
|
||||
"repository": "git://github.com/Raynos/for-each.git",
|
||||
"main": "index",
|
||||
"homepage": "https://github.com/Raynos/for-each",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jake Verbaten"
|
||||
},
|
||||
{
|
||||
"name": "Jordan Harband",
|
||||
"url": "https://github.com/ljharb"
|
||||
}
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/Raynos/for-each/issues",
|
||||
"email": "raynos2@gmail.com"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-callable": "^1.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ljharb/eslint-config": "^12.2.1",
|
||||
"eslint": "^4.19.1",
|
||||
"nsp": "^3.2.1",
|
||||
"tape": "^4.9.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://github.com/Raynos/for-each/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"scripts": {
|
||||
"pretest": "npm run lint",
|
||||
"test": "npm run tests-only",
|
||||
"tests-only": "node test/test",
|
||||
"posttest": "npm run security",
|
||||
"lint": "eslint *.js test/*.js",
|
||||
"security": "nsp check"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/test.js",
|
||||
"browsers": [
|
||||
"iexplore/6.0..latest",
|
||||
"firefox/3.0..6.0",
|
||||
"firefox/15.0..latest",
|
||||
"firefox/nightly",
|
||||
"chrome/4.0..10.0",
|
||||
"chrome/20.0..latest",
|
||||
"chrome/canary",
|
||||
"opera/10.0..latest",
|
||||
"opera/next",
|
||||
"safari/4.0..latest",
|
||||
"ipad/6.0..latest",
|
||||
"iphone/6.0..latest",
|
||||
"android-browser/4.2"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"78":0.01798,"94":0.00449,"95":0.00899,"97":0.00449,"98":0.00449,"99":0.00899,"102":0.02247,"106":0.42244,"109":0.87184,"110":0.46288,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 96 100 101 103 104 105 107 108 111 112 3.5 3.6"},D:{"43":0.00449,"47":0.02696,"49":0.00449,"58":0.00899,"69":0.03595,"70":0.00449,"78":0.11684,"79":0.26515,"83":0.00449,"86":0.10336,"87":0.21122,"89":0.02696,"90":0.00449,"91":0.00899,"93":0.23818,"94":0.27413,"95":0.01798,"100":0.05842,"102":0.00449,"103":1.31674,"104":0.02696,"105":0.02696,"107":0.11235,"108":0.54377,"109":17.69737,"110":8.25098,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 48 50 51 52 53 54 55 56 57 59 60 61 62 63 64 65 66 67 68 71 72 73 74 75 76 77 80 81 84 85 88 92 96 97 98 99 101 106 111 112 113"},F:{"28":0.03146,"83":0.00449,"91":0.00449,"94":0.03146,"95":0.05393,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 84 85 86 87 88 89 90 92 93 9.5-9.6 10.5 10.6 11.1 11.5 11.6 12.1","10.0-10.1":0},B:{"107":0.00899,"108":0.0719,"109":1.99534,"110":4.26031,_:"12 13 14 15 16 17 18 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106"},E:{"4":0,"11":0.02247,"12":0.00899,"14":0.09887,_:"0 5 6 7 8 9 10 13 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 16.4","12.1":0.00899,"13.1":0.00899,"14.1":0.45839,"15.1":0.00449,"15.2-15.3":0.00899,"15.4":0.00449,"15.5":0.05842,"15.6":0.91678,"16.0":0.00449,"16.1":0.55276,"16.2":2.28745,"16.3":0.18425},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0,"6.0-6.1":0,"7.0-7.1":0,"8.1-8.4":0,"9.0-9.2":0,"9.3":0.00513,"10.0-10.2":0,"10.3":0.41728,"11.0-11.2":0.00513,"11.3-11.4":0,"12.0-12.1":0,"12.2-12.5":0.07525,"13.0-13.1":0,"13.2":0,"13.3":0,"13.4-13.7":0.0342,"14.0-14.4":0.13339,"14.5-14.8":0.41728,"15.0-15.1":0.0342,"15.2-15.3":0.19667,"15.4":0.69091,"15.5":0.26679,"15.6":0.773,"16.0":2.70551,"16.1":2.85772,"16.2":5.82488,"16.3":1.06202,"16.4":0},P:{"4":0.2888,"20":0.80505,"5.0-5.4":0.01042,"6.2-6.4":0.0206,"7.2-7.4":0.16948,"8.2":0.02044,"9.2":0.12711,"10.1":0.0217,"11.1-11.2":0.01059,"12.0":0.01031,"13.0":0.11652,"14.0":0.05157,"15.0":0.04126,"16.0":0.23723,"17.0":0.01059,"18.0":0.18566,"19.0":0.84742},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0,"4.4":0,"4.4.3-4.4.4":0},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"11":0.00899,_:"6 7 8 9 10 5.5"},N:{"10":0.03712,"11":0.07423},S:{"2.5":0,_:"3.0-3.1"},J:{"7":0,"10":0},O:{"0":0.60015},H:{"0":0.05213},L:{"0":35.63063},R:{_:"0"},M:{"0":1.91058},Q:{"13.1":0}};
|
||||
@@ -0,0 +1,6 @@
|
||||
'use strict'
|
||||
module.exports = (d, num) => {
|
||||
num = String(num)
|
||||
while (num.length < d) num = '0' + num
|
||||
return num
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fsWalk = require("@nodelib/fs.walk");
|
||||
const reader_1 = require("./reader");
|
||||
const stream_1 = require("./stream");
|
||||
class ReaderAsync extends reader_1.default {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this._walkAsync = fsWalk.walk;
|
||||
this._readerStream = new stream_1.default(this._settings);
|
||||
}
|
||||
dynamic(root, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._walkAsync(root, options, (error, entries) => {
|
||||
if (error === null) {
|
||||
resolve(entries);
|
||||
}
|
||||
else {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
async static(patterns, options) {
|
||||
const entries = [];
|
||||
const stream = this._readerStream.static(patterns, options);
|
||||
// After #235, replace it with an asynchronous iterator.
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.once('error', reject);
|
||||
stream.on('data', (entry) => entries.push(entry));
|
||||
stream.once('end', () => resolve(entries));
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.default = ReaderAsync;
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.removeDuplicateSlashes = exports.transform = void 0;
|
||||
/**
|
||||
* Matches a sequence of two or more consecutive slashes, excluding the first two slashes at the beginning of the string.
|
||||
* The latter is due to the presence of the device path at the beginning of the UNC path.
|
||||
* @todo rewrite to negative lookbehind with the next major release.
|
||||
*/
|
||||
const DOUBLE_SLASH_RE = /(?!^)\/{2,}/g;
|
||||
function transform(patterns) {
|
||||
return patterns.map((pattern) => removeDuplicateSlashes(pattern));
|
||||
}
|
||||
exports.transform = transform;
|
||||
/**
|
||||
* This package only works with forward slashes as a path separator.
|
||||
* Because of this, we cannot use the standard `path.normalize` method, because on Windows platform it will use of backslashes.
|
||||
*/
|
||||
function removeDuplicateSlashes(pattern) {
|
||||
return pattern.replace(DOUBLE_SLASH_RE, '/');
|
||||
}
|
||||
exports.removeDuplicateSlashes = removeDuplicateSlashes;
|
||||
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.repeatWhen = void 0;
|
||||
var innerFrom_1 = require("../observable/innerFrom");
|
||||
var Subject_1 = require("../Subject");
|
||||
var lift_1 = require("../util/lift");
|
||||
var OperatorSubscriber_1 = require("./OperatorSubscriber");
|
||||
function repeatWhen(notifier) {
|
||||
return lift_1.operate(function (source, subscriber) {
|
||||
var innerSub;
|
||||
var syncResub = false;
|
||||
var completions$;
|
||||
var isNotifierComplete = false;
|
||||
var isMainComplete = false;
|
||||
var checkComplete = function () { return isMainComplete && isNotifierComplete && (subscriber.complete(), true); };
|
||||
var getCompletionSubject = function () {
|
||||
if (!completions$) {
|
||||
completions$ = new Subject_1.Subject();
|
||||
innerFrom_1.innerFrom(notifier(completions$)).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function () {
|
||||
if (innerSub) {
|
||||
subscribeForRepeatWhen();
|
||||
}
|
||||
else {
|
||||
syncResub = true;
|
||||
}
|
||||
}, function () {
|
||||
isNotifierComplete = true;
|
||||
checkComplete();
|
||||
}));
|
||||
}
|
||||
return completions$;
|
||||
};
|
||||
var subscribeForRepeatWhen = function () {
|
||||
isMainComplete = false;
|
||||
innerSub = source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, undefined, function () {
|
||||
isMainComplete = true;
|
||||
!checkComplete() && getCompletionSubject().next();
|
||||
}));
|
||||
if (syncResub) {
|
||||
innerSub.unsubscribe();
|
||||
innerSub = null;
|
||||
syncResub = false;
|
||||
subscribeForRepeatWhen();
|
||||
}
|
||||
};
|
||||
subscribeForRepeatWhen();
|
||||
});
|
||||
}
|
||||
exports.repeatWhen = repeatWhen;
|
||||
//# sourceMappingURL=repeatWhen.js.map
|
||||
@@ -0,0 +1,378 @@
|
||||
# Glob
|
||||
|
||||
Match files using the patterns the shell uses, like stars and stuff.
|
||||
|
||||
[](https://travis-ci.org/isaacs/node-glob/) [](https://ci.appveyor.com/project/isaacs/node-glob) [](https://coveralls.io/github/isaacs/node-glob?branch=master)
|
||||
|
||||
This is a glob implementation in JavaScript. It uses the `minimatch`
|
||||
library to do its matching.
|
||||
|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
Install with npm
|
||||
|
||||
```
|
||||
npm i glob
|
||||
```
|
||||
|
||||
```javascript
|
||||
var glob = require("glob")
|
||||
|
||||
// options is optional
|
||||
glob("**/*.js", options, function (er, files) {
|
||||
// files is an array of filenames.
|
||||
// If the `nonull` option is set, and nothing
|
||||
// was found, then files is ["**/*.js"]
|
||||
// er is an error object or null.
|
||||
})
|
||||
```
|
||||
|
||||
## Glob Primer
|
||||
|
||||
"Globs" are the patterns you type when you do stuff like `ls *.js` on
|
||||
the command line, or put `build/*` in a `.gitignore` file.
|
||||
|
||||
Before parsing the path part patterns, braced sections are expanded
|
||||
into a set. Braced sections start with `{` and end with `}`, with any
|
||||
number of comma-delimited sections within. Braced sections may contain
|
||||
slash characters, so `a{/b/c,bcd}` would expand into `a/b/c` and `abcd`.
|
||||
|
||||
The following characters have special magic meaning when used in a
|
||||
path portion:
|
||||
|
||||
* `*` Matches 0 or more characters in a single path portion
|
||||
* `?` Matches 1 character
|
||||
* `[...]` Matches a range of characters, similar to a RegExp range.
|
||||
If the first character of the range is `!` or `^` then it matches
|
||||
any character not in the range.
|
||||
* `!(pattern|pattern|pattern)` Matches anything that does not match
|
||||
any of the patterns provided.
|
||||
* `?(pattern|pattern|pattern)` Matches zero or one occurrence of the
|
||||
patterns provided.
|
||||
* `+(pattern|pattern|pattern)` Matches one or more occurrences of the
|
||||
patterns provided.
|
||||
* `*(a|b|c)` Matches zero or more occurrences of the patterns provided
|
||||
* `@(pattern|pat*|pat?erN)` Matches exactly one of the patterns
|
||||
provided
|
||||
* `**` If a "globstar" is alone in a path portion, then it matches
|
||||
zero or more directories and subdirectories searching for matches.
|
||||
It does not crawl symlinked directories.
|
||||
|
||||
### Dots
|
||||
|
||||
If a file or directory path portion has a `.` as the first character,
|
||||
then it will not match any glob pattern unless that pattern's
|
||||
corresponding path part also has a `.` as its first character.
|
||||
|
||||
For example, the pattern `a/.*/c` would match the file at `a/.b/c`.
|
||||
However the pattern `a/*/c` would not, because `*` does not start with
|
||||
a dot character.
|
||||
|
||||
You can make glob treat dots as normal characters by setting
|
||||
`dot:true` in the options.
|
||||
|
||||
### Basename Matching
|
||||
|
||||
If you set `matchBase:true` in the options, and the pattern has no
|
||||
slashes in it, then it will seek for any file anywhere in the tree
|
||||
with a matching basename. For example, `*.js` would match
|
||||
`test/simple/basic.js`.
|
||||
|
||||
### Empty Sets
|
||||
|
||||
If no matching files are found, then an empty array is returned. This
|
||||
differs from the shell, where the pattern itself is returned. For
|
||||
example:
|
||||
|
||||
$ echo a*s*d*f
|
||||
a*s*d*f
|
||||
|
||||
To get the bash-style behavior, set the `nonull:true` in the options.
|
||||
|
||||
### See Also:
|
||||
|
||||
* `man sh`
|
||||
* `man bash` (Search for "Pattern Matching")
|
||||
* `man 3 fnmatch`
|
||||
* `man 5 gitignore`
|
||||
* [minimatch documentation](https://github.com/isaacs/minimatch)
|
||||
|
||||
## glob.hasMagic(pattern, [options])
|
||||
|
||||
Returns `true` if there are any special characters in the pattern, and
|
||||
`false` otherwise.
|
||||
|
||||
Note that the options affect the results. If `noext:true` is set in
|
||||
the options object, then `+(a|b)` will not be considered a magic
|
||||
pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`
|
||||
then that is considered magical, unless `nobrace:true` is set in the
|
||||
options.
|
||||
|
||||
## glob(pattern, [options], cb)
|
||||
|
||||
* `pattern` `{String}` Pattern to be matched
|
||||
* `options` `{Object}`
|
||||
* `cb` `{Function}`
|
||||
* `err` `{Error | null}`
|
||||
* `matches` `{Array<String>}` filenames found matching the pattern
|
||||
|
||||
Perform an asynchronous glob search.
|
||||
|
||||
## glob.sync(pattern, [options])
|
||||
|
||||
* `pattern` `{String}` Pattern to be matched
|
||||
* `options` `{Object}`
|
||||
* return: `{Array<String>}` filenames found matching the pattern
|
||||
|
||||
Perform a synchronous glob search.
|
||||
|
||||
## Class: glob.Glob
|
||||
|
||||
Create a Glob object by instantiating the `glob.Glob` class.
|
||||
|
||||
```javascript
|
||||
var Glob = require("glob").Glob
|
||||
var mg = new Glob(pattern, options, cb)
|
||||
```
|
||||
|
||||
It's an EventEmitter, and starts walking the filesystem to find matches
|
||||
immediately.
|
||||
|
||||
### new glob.Glob(pattern, [options], [cb])
|
||||
|
||||
* `pattern` `{String}` pattern to search for
|
||||
* `options` `{Object}`
|
||||
* `cb` `{Function}` Called when an error occurs, or matches are found
|
||||
* `err` `{Error | null}`
|
||||
* `matches` `{Array<String>}` filenames found matching the pattern
|
||||
|
||||
Note that if the `sync` flag is set in the options, then matches will
|
||||
be immediately available on the `g.found` member.
|
||||
|
||||
### Properties
|
||||
|
||||
* `minimatch` The minimatch object that the glob uses.
|
||||
* `options` The options object passed in.
|
||||
* `aborted` Boolean which is set to true when calling `abort()`. There
|
||||
is no way at this time to continue a glob search after aborting, but
|
||||
you can re-use the statCache to avoid having to duplicate syscalls.
|
||||
* `cache` Convenience object. Each field has the following possible
|
||||
values:
|
||||
* `false` - Path does not exist
|
||||
* `true` - Path exists
|
||||
* `'FILE'` - Path exists, and is not a directory
|
||||
* `'DIR'` - Path exists, and is a directory
|
||||
* `[file, entries, ...]` - Path exists, is a directory, and the
|
||||
array value is the results of `fs.readdir`
|
||||
* `statCache` Cache of `fs.stat` results, to prevent statting the same
|
||||
path multiple times.
|
||||
* `symlinks` A record of which paths are symbolic links, which is
|
||||
relevant in resolving `**` patterns.
|
||||
* `realpathCache` An optional object which is passed to `fs.realpath`
|
||||
to minimize unnecessary syscalls. It is stored on the instantiated
|
||||
Glob object, and may be re-used.
|
||||
|
||||
### Events
|
||||
|
||||
* `end` When the matching is finished, this is emitted with all the
|
||||
matches found. If the `nonull` option is set, and no match was found,
|
||||
then the `matches` list contains the original pattern. The matches
|
||||
are sorted, unless the `nosort` flag is set.
|
||||
* `match` Every time a match is found, this is emitted with the specific
|
||||
thing that matched. It is not deduplicated or resolved to a realpath.
|
||||
* `error` Emitted when an unexpected error is encountered, or whenever
|
||||
any fs error occurs if `options.strict` is set.
|
||||
* `abort` When `abort()` is called, this event is raised.
|
||||
|
||||
### Methods
|
||||
|
||||
* `pause` Temporarily stop the search
|
||||
* `resume` Resume the search
|
||||
* `abort` Stop the search forever
|
||||
|
||||
### Options
|
||||
|
||||
All the options that can be passed to Minimatch can also be passed to
|
||||
Glob to change pattern matching behavior. Also, some have been added,
|
||||
or have glob-specific ramifications.
|
||||
|
||||
All options are false by default, unless otherwise noted.
|
||||
|
||||
All options are added to the Glob object, as well.
|
||||
|
||||
If you are running many `glob` operations, you can pass a Glob object
|
||||
as the `options` argument to a subsequent operation to shortcut some
|
||||
`stat` and `readdir` calls. At the very least, you may pass in shared
|
||||
`symlinks`, `statCache`, `realpathCache`, and `cache` options, so that
|
||||
parallel glob operations will be sped up by sharing information about
|
||||
the filesystem.
|
||||
|
||||
* `cwd` The current working directory in which to search. Defaults
|
||||
to `process.cwd()`.
|
||||
* `root` The place where patterns starting with `/` will be mounted
|
||||
onto. Defaults to `path.resolve(options.cwd, "/")` (`/` on Unix
|
||||
systems, and `C:\` or some such on Windows.)
|
||||
* `dot` Include `.dot` files in normal matches and `globstar` matches.
|
||||
Note that an explicit dot in a portion of the pattern will always
|
||||
match dot files.
|
||||
* `nomount` By default, a pattern starting with a forward-slash will be
|
||||
"mounted" onto the root setting, so that a valid filesystem path is
|
||||
returned. Set this flag to disable that behavior.
|
||||
* `mark` Add a `/` character to directory matches. Note that this
|
||||
requires additional stat calls.
|
||||
* `nosort` Don't sort the results.
|
||||
* `stat` Set to true to stat *all* results. This reduces performance
|
||||
somewhat, and is completely unnecessary, unless `readdir` is presumed
|
||||
to be an untrustworthy indicator of file existence.
|
||||
* `silent` When an unusual error is encountered when attempting to
|
||||
read a directory, a warning will be printed to stderr. Set the
|
||||
`silent` option to true to suppress these warnings.
|
||||
* `strict` When an unusual error is encountered when attempting to
|
||||
read a directory, the process will just continue on in search of
|
||||
other matches. Set the `strict` option to raise an error in these
|
||||
cases.
|
||||
* `cache` See `cache` property above. Pass in a previously generated
|
||||
cache object to save some fs calls.
|
||||
* `statCache` A cache of results of filesystem information, to prevent
|
||||
unnecessary stat calls. While it should not normally be necessary
|
||||
to set this, you may pass the statCache from one glob() call to the
|
||||
options object of another, if you know that the filesystem will not
|
||||
change between calls. (See "Race Conditions" below.)
|
||||
* `symlinks` A cache of known symbolic links. You may pass in a
|
||||
previously generated `symlinks` object to save `lstat` calls when
|
||||
resolving `**` matches.
|
||||
* `sync` DEPRECATED: use `glob.sync(pattern, opts)` instead.
|
||||
* `nounique` In some cases, brace-expanded patterns can result in the
|
||||
same file showing up multiple times in the result set. By default,
|
||||
this implementation prevents duplicates in the result set. Set this
|
||||
flag to disable that behavior.
|
||||
* `nonull` Set to never return an empty set, instead returning a set
|
||||
containing the pattern itself. This is the default in glob(3).
|
||||
* `debug` Set to enable debug logging in minimatch and glob.
|
||||
* `nobrace` Do not expand `{a,b}` and `{1..3}` brace sets.
|
||||
* `noglobstar` Do not match `**` against multiple filenames. (Ie,
|
||||
treat it as a normal `*` instead.)
|
||||
* `noext` Do not match `+(a|b)` "extglob" patterns.
|
||||
* `nocase` Perform a case-insensitive match. Note: on
|
||||
case-insensitive filesystems, non-magic patterns will match by
|
||||
default, since `stat` and `readdir` will not raise errors.
|
||||
* `matchBase` Perform a basename-only match if the pattern does not
|
||||
contain any slash characters. That is, `*.js` would be treated as
|
||||
equivalent to `**/*.js`, matching all js files in all directories.
|
||||
* `nodir` Do not match directories, only files. (Note: to match
|
||||
*only* directories, simply put a `/` at the end of the pattern.)
|
||||
* `ignore` Add a pattern or an array of glob patterns to exclude matches.
|
||||
Note: `ignore` patterns are *always* in `dot:true` mode, regardless
|
||||
of any other settings.
|
||||
* `follow` Follow symlinked directories when expanding `**` patterns.
|
||||
Note that this can result in a lot of duplicate references in the
|
||||
presence of cyclic links.
|
||||
* `realpath` Set to true to call `fs.realpath` on all of the results.
|
||||
In the case of a symlink that cannot be resolved, the full absolute
|
||||
path to the matched entry is returned (though it will usually be a
|
||||
broken symlink)
|
||||
* `absolute` Set to true to always receive absolute paths for matched
|
||||
files. Unlike `realpath`, this also affects the values returned in
|
||||
the `match` event.
|
||||
* `fs` File-system object with Node's `fs` API. By default, the built-in
|
||||
`fs` module will be used. Set to a volume provided by a library like
|
||||
`memfs` to avoid using the "real" file-system.
|
||||
|
||||
## Comparisons to other fnmatch/glob implementations
|
||||
|
||||
While strict compliance with the existing standards is a worthwhile
|
||||
goal, some discrepancies exist between node-glob and other
|
||||
implementations, and are intentional.
|
||||
|
||||
The double-star character `**` is supported by default, unless the
|
||||
`noglobstar` flag is set. This is supported in the manner of bsdglob
|
||||
and bash 4.3, where `**` only has special significance if it is the only
|
||||
thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
|
||||
`a/**b` will not.
|
||||
|
||||
Note that symlinked directories are not crawled as part of a `**`,
|
||||
though their contents may match against subsequent portions of the
|
||||
pattern. This prevents infinite loops and duplicates and the like.
|
||||
|
||||
If an escaped pattern has no matches, and the `nonull` flag is set,
|
||||
then glob returns the pattern as-provided, rather than
|
||||
interpreting the character escapes. For example,
|
||||
`glob.match([], "\\*a\\?")` will return `"\\*a\\?"` rather than
|
||||
`"*a?"`. This is akin to setting the `nullglob` option in bash, except
|
||||
that it does not resolve escaped pattern characters.
|
||||
|
||||
If brace expansion is not disabled, then it is performed before any
|
||||
other interpretation of the glob pattern. Thus, a pattern like
|
||||
`+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded
|
||||
**first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are
|
||||
checked for validity. Since those two are valid, matching proceeds.
|
||||
|
||||
### Comments and Negation
|
||||
|
||||
Previously, this module let you mark a pattern as a "comment" if it
|
||||
started with a `#` character, or a "negated" pattern if it started
|
||||
with a `!` character.
|
||||
|
||||
These options were deprecated in version 5, and removed in version 6.
|
||||
|
||||
To specify things that should not match, use the `ignore` option.
|
||||
|
||||
## Windows
|
||||
|
||||
**Please only use forward-slashes in glob expressions.**
|
||||
|
||||
Though windows uses either `/` or `\` as its path separator, only `/`
|
||||
characters are used by this glob implementation. You must use
|
||||
forward-slashes **only** in glob expressions. Back-slashes will always
|
||||
be interpreted as escape characters, not path separators.
|
||||
|
||||
Results from absolute patterns such as `/foo/*` are mounted onto the
|
||||
root setting using `path.join`. On windows, this will by default result
|
||||
in `/foo/*` matching `C:\foo\bar.txt`.
|
||||
|
||||
## Race Conditions
|
||||
|
||||
Glob searching, by its very nature, is susceptible to race conditions,
|
||||
since it relies on directory walking and such.
|
||||
|
||||
As a result, it is possible that a file that exists when glob looks for
|
||||
it may have been deleted or modified by the time it returns the result.
|
||||
|
||||
As part of its internal implementation, this program caches all stat
|
||||
and readdir calls that it makes, in order to cut down on system
|
||||
overhead. However, this also makes it even more susceptible to races,
|
||||
especially if the cache or statCache objects are reused between glob
|
||||
calls.
|
||||
|
||||
Users are thus advised not to use a glob result as a guarantee of
|
||||
filesystem state in the face of rapid changes. For the vast majority
|
||||
of operations, this is never a problem.
|
||||
|
||||
## Glob Logo
|
||||
Glob's logo was created by [Tanya Brassie](http://tanyabrassie.com/). Logo files can be found [here](https://github.com/isaacs/node-glob/tree/master/logo).
|
||||
|
||||
The logo is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/).
|
||||
|
||||
## Contributing
|
||||
|
||||
Any change to behavior (including bugfixes) must come with a test.
|
||||
|
||||
Patches that fail tests or reduce performance will be rejected.
|
||||
|
||||
```
|
||||
# to run tests
|
||||
npm test
|
||||
|
||||
# to re-generate test fixtures
|
||||
npm run test-regen
|
||||
|
||||
# to benchmark against bash/zsh
|
||||
npm run bench
|
||||
|
||||
# to profile javascript
|
||||
npm run prof
|
||||
```
|
||||
|
||||

|
||||
@@ -0,0 +1,65 @@
|
||||
import { EndpointDefaults } from "./EndpointDefaults";
|
||||
import { RequestOptions } from "./RequestOptions";
|
||||
import { RequestParameters } from "./RequestParameters";
|
||||
import { Route } from "./Route";
|
||||
import { Endpoints } from "./generated/Endpoints";
|
||||
export interface EndpointInterface<D extends object = object> {
|
||||
/**
|
||||
* Transforms a GitHub REST API endpoint into generic request options
|
||||
*
|
||||
* @param {object} endpoint Must set `url` unless it's set defaults. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
||||
*/
|
||||
<O extends RequestParameters = RequestParameters>(options: O & {
|
||||
method?: string;
|
||||
} & ("url" extends keyof D ? {
|
||||
url?: string;
|
||||
} : {
|
||||
url: string;
|
||||
})): RequestOptions & Pick<D & O, keyof RequestOptions>;
|
||||
/**
|
||||
* Transforms a GitHub REST API endpoint into generic request options
|
||||
*
|
||||
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
|
||||
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
||||
*/
|
||||
<R extends Route, P extends RequestParameters = R extends keyof Endpoints ? Endpoints[R]["parameters"] & RequestParameters : RequestParameters>(route: keyof Endpoints | R, parameters?: P): (R extends keyof Endpoints ? Endpoints[R]["request"] : RequestOptions) & Pick<P, keyof RequestOptions>;
|
||||
/**
|
||||
* Object with current default route and parameters
|
||||
*/
|
||||
DEFAULTS: D & EndpointDefaults;
|
||||
/**
|
||||
* Returns a new `endpoint` interface with new defaults
|
||||
*/
|
||||
defaults: <O extends RequestParameters = RequestParameters>(newDefaults: O) => EndpointInterface<D & O>;
|
||||
merge: {
|
||||
/**
|
||||
* Merges current endpoint defaults with passed route and parameters,
|
||||
* without transforming them into request options.
|
||||
*
|
||||
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
|
||||
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
||||
*
|
||||
*/
|
||||
<R extends Route, P extends RequestParameters = R extends keyof Endpoints ? Endpoints[R]["parameters"] & RequestParameters : RequestParameters>(route: keyof Endpoints | R, parameters?: P): D & (R extends keyof Endpoints ? Endpoints[R]["request"] & Endpoints[R]["parameters"] : EndpointDefaults) & P;
|
||||
/**
|
||||
* Merges current endpoint defaults with passed route and parameters,
|
||||
* without transforming them into request options.
|
||||
*
|
||||
* @param {object} endpoint Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
||||
*/
|
||||
<P extends RequestParameters = RequestParameters>(options: P): EndpointDefaults & D & P;
|
||||
/**
|
||||
* Returns current default options.
|
||||
*
|
||||
* @deprecated use endpoint.DEFAULTS instead
|
||||
*/
|
||||
(): D & EndpointDefaults;
|
||||
};
|
||||
/**
|
||||
* Stateless method to turn endpoint options into request options.
|
||||
* Calling `endpoint(options)` is the same as calling `endpoint.parse(endpoint.merge(options))`.
|
||||
*
|
||||
* @param {object} options `method`, `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
|
||||
*/
|
||||
parse: <O extends EndpointDefaults = EndpointDefaults>(options: O) => RequestOptions & Pick<O, keyof RequestOptions>;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function defined() {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
if (typeof arguments[i] !== 'undefined') {
|
||||
return arguments[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"bufferToggle.js","sourceRoot":"","sources":["../../../../src/internal/operators/bufferToggle.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AA6C9C,MAAM,UAAU,YAAY,CAC1B,QAA4B,EAC5B,eAAmD;IAEnD,OAAO,OAAO,CAAC,UAAC,MAAM,EAAE,UAAU;QAChC,IAAM,OAAO,GAAU,EAAE,CAAC;QAG1B,SAAS,CAAC,QAAQ,CAAC,CAAC,SAAS,CAC3B,wBAAwB,CACtB,UAAU,EACV,UAAC,SAAS;YACR,IAAM,MAAM,GAAQ,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAGrB,IAAM,mBAAmB,GAAG,IAAI,YAAY,EAAE,CAAC;YAE/C,IAAM,UAAU,GAAG;gBACjB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAC3B,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACxB,mBAAmB,CAAC,WAAW,EAAE,CAAC;YACpC,CAAC,CAAC;YAGF,mBAAmB,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,wBAAwB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACnI,CAAC,EACD,IAAI,CACL,CACF,CAAC;QAEF,MAAM,CAAC,SAAS,CACd,wBAAwB,CACtB,UAAU,EACV,UAAC,KAAK;;;gBAEJ,KAAqB,IAAA,YAAA,SAAA,OAAO,CAAA,gCAAA,qDAAE;oBAAzB,IAAM,MAAM,oBAAA;oBACf,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACpB;;;;;;;;;QACH,CAAC,EACD;YAEE,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;gBACzB,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAG,CAAC,CAAC;aACnC;YACD,UAAU,CAAC,QAAQ,EAAE,CAAC;QACxB,CAAC,CACF,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
||||
@@ -0,0 +1,18 @@
|
||||
var asciiToArray = require('./_asciiToArray'),
|
||||
hasUnicode = require('./_hasUnicode'),
|
||||
unicodeToArray = require('./_unicodeToArray');
|
||||
|
||||
/**
|
||||
* Converts `string` to an array.
|
||||
*
|
||||
* @private
|
||||
* @param {string} string The string to convert.
|
||||
* @returns {Array} Returns the converted array.
|
||||
*/
|
||||
function stringToArray(string) {
|
||||
return hasUnicode(string)
|
||||
? unicodeToArray(string)
|
||||
: asciiToArray(string);
|
||||
}
|
||||
|
||||
module.exports = stringToArray;
|
||||
@@ -0,0 +1,41 @@
|
||||
var arrayEach = require('./_arrayEach'),
|
||||
baseEach = require('./_baseEach'),
|
||||
castFunction = require('./_castFunction'),
|
||||
isArray = require('./isArray');
|
||||
|
||||
/**
|
||||
* Iterates over elements of `collection` and invokes `iteratee` for each element.
|
||||
* The iteratee is invoked with three arguments: (value, index|key, collection).
|
||||
* Iteratee functions may exit iteration early by explicitly returning `false`.
|
||||
*
|
||||
* **Note:** As with other "Collections" methods, objects with a "length"
|
||||
* property are iterated like arrays. To avoid this behavior use `_.forIn`
|
||||
* or `_.forOwn` for object iteration.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 0.1.0
|
||||
* @alias each
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||||
* @returns {Array|Object} Returns `collection`.
|
||||
* @see _.forEachRight
|
||||
* @example
|
||||
*
|
||||
* _.forEach([1, 2], function(value) {
|
||||
* console.log(value);
|
||||
* });
|
||||
* // => Logs `1` then `2`.
|
||||
*
|
||||
* _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
|
||||
* console.log(key);
|
||||
* });
|
||||
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
||||
*/
|
||||
function forEach(collection, iteratee) {
|
||||
var func = isArray(collection) ? arrayEach : baseEach;
|
||||
return func(collection, castFunction(iteratee));
|
||||
}
|
||||
|
||||
module.exports = forEach;
|
||||
@@ -0,0 +1,141 @@
|
||||
import { ErrorInfo, PreactContext, Ref as PreactRef } from '../..';
|
||||
|
||||
type Inputs = ReadonlyArray<unknown>;
|
||||
|
||||
export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
|
||||
/**
|
||||
* Returns a stateful value, and a function to update it.
|
||||
* @param initialState The initial value (or a function that returns the initial value)
|
||||
*/
|
||||
export function useState<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
|
||||
|
||||
export function useState<S = undefined>(): [
|
||||
S | undefined,
|
||||
StateUpdater<S | undefined>
|
||||
];
|
||||
|
||||
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
||||
/**
|
||||
* An alternative to `useState`.
|
||||
*
|
||||
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
|
||||
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
||||
* updates because you can pass `dispatch` down instead of callbacks.
|
||||
* @param reducer Given the current state and an action, returns the new state
|
||||
* @param initialState The initial value to store as state
|
||||
*/
|
||||
export function useReducer<S, A>(
|
||||
reducer: Reducer<S, A>,
|
||||
initialState: S
|
||||
): [S, (action: A) => void];
|
||||
|
||||
/**
|
||||
* An alternative to `useState`.
|
||||
*
|
||||
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
|
||||
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
||||
* updates because you can pass `dispatch` down instead of callbacks.
|
||||
* @param reducer Given the current state and an action, returns the new state
|
||||
* @param initialArg The initial argument to pass to the `init` function
|
||||
* @param init A function that, given the `initialArg`, returns the initial value to store as state
|
||||
*/
|
||||
export function useReducer<S, A, I>(
|
||||
reducer: Reducer<S, A>,
|
||||
initialArg: I,
|
||||
init: (arg: I) => S
|
||||
): [S, (action: A) => void];
|
||||
|
||||
/** @deprecated Use the `Ref` type instead. */
|
||||
type PropRef<T> = MutableRef<T>;
|
||||
interface Ref<T> {
|
||||
readonly current: T | null;
|
||||
}
|
||||
|
||||
interface MutableRef<T> {
|
||||
current: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
|
||||
* (`initialValue`). The returned object will persist for the full lifetime of the component.
|
||||
*
|
||||
* Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
|
||||
* value around similar to how you’d use instance fields in classes.
|
||||
*
|
||||
* @param initialValue the initial value to store in the ref object
|
||||
*/
|
||||
export function useRef<T>(initialValue: T): MutableRef<T>;
|
||||
export function useRef<T>(initialValue: T | null): Ref<T>;
|
||||
export function useRef<T = undefined>(): MutableRef<T | undefined>;
|
||||
|
||||
type EffectCallback = () => void | (() => void);
|
||||
/**
|
||||
* Accepts a function that contains imperative, possibly effectful code.
|
||||
* The effects run after browser paint, without blocking it.
|
||||
*
|
||||
* @param effect Imperative function that can return a cleanup function
|
||||
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
||||
*/
|
||||
export function useEffect(effect: EffectCallback, inputs?: Inputs): void;
|
||||
|
||||
type CreateHandle = () => object;
|
||||
|
||||
/**
|
||||
* @param ref The ref that will be mutated
|
||||
* @param create The function that will be executed to get the value that will be attached to
|
||||
* ref.current
|
||||
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
||||
*/
|
||||
export function useImperativeHandle<T, R extends T>(
|
||||
ref: PreactRef<T>,
|
||||
create: () => R,
|
||||
inputs?: Inputs
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Accepts a function that contains imperative, possibly effectful code.
|
||||
* Use this to read layout from the DOM and synchronously re-render.
|
||||
* Updates scheduled inside `useLayoutEffect` will be flushed synchronously, after all DOM mutations but before the browser has a chance to paint.
|
||||
* Prefer the standard `useEffect` hook when possible to avoid blocking visual updates.
|
||||
*
|
||||
* @param effect Imperative function that can return a cleanup function
|
||||
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
||||
*/
|
||||
export function useLayoutEffect(effect: EffectCallback, inputs?: Inputs): void;
|
||||
|
||||
/**
|
||||
* Returns a memoized version of the callback that only changes if one of the `inputs`
|
||||
* has changed (using ===).
|
||||
*/
|
||||
export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
|
||||
|
||||
/**
|
||||
* Pass a factory function and an array of inputs.
|
||||
* useMemo will only recompute the memoized value when one of the inputs has changed.
|
||||
* This optimization helps to avoid expensive calculations on every render.
|
||||
* If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
|
||||
*/
|
||||
// for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
|
||||
export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;
|
||||
|
||||
/**
|
||||
* Returns the current context value, as given by the nearest context provider for the given context.
|
||||
* When the provider updates, this Hook will trigger a rerender with the latest context value.
|
||||
*
|
||||
* @param context The context you want to use
|
||||
*/
|
||||
export function useContext<T>(context: PreactContext<T>): T;
|
||||
|
||||
/**
|
||||
* Customize the displayed value in the devtools panel.
|
||||
*
|
||||
* @param value Custom hook name or object that is passed to formatter
|
||||
* @param formatter Formatter to modify value before sending it to the devtools
|
||||
*/
|
||||
export function useDebugValue<T>(value: T, formatter?: (value: T) => any): void;
|
||||
|
||||
export function useErrorBoundary(
|
||||
callback?: (error: any, errorInfo: ErrorInfo) => Promise<void> | void
|
||||
): [any, () => void];
|
||||
|
||||
export function useId(): string;
|
||||
@@ -0,0 +1,40 @@
|
||||
import type {Except} from './except';
|
||||
import type {Simplify} from './simplify';
|
||||
|
||||
/**
|
||||
Create a type that strips `readonly` from all or some of an object's keys. Inverse of `Readonly<T>`.
|
||||
|
||||
This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Writable} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
readonly a: number;
|
||||
readonly b: readonly string[]; // To show that only the mutability status of the properties, not their values, are affected.
|
||||
readonly c: boolean;
|
||||
};
|
||||
|
||||
const writableFoo: Writable<Foo> = {a: 1, b: ['2'], c: true};
|
||||
writableFoo.a = 3;
|
||||
writableFoo.b[0] = 'new value'; // Will still fail as the value of property "b" is still a readonly type.
|
||||
writableFoo.b = ['something']; // Will work as the "b" property itself is no longer readonly.
|
||||
|
||||
type SomeWritable = Writable<Foo, 'b' | 'c'>;
|
||||
// type SomeWritable = {
|
||||
// readonly a: number;
|
||||
// b: readonly string[]; // It's now writable. The type of the property remains unaffected.
|
||||
// c: boolean; // It's now writable.
|
||||
// }
|
||||
```
|
||||
|
||||
@category Object
|
||||
*/
|
||||
export type Writable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
|
||||
Simplify<
|
||||
// Pick just the keys that are not writable from the base type.
|
||||
Except<BaseType, Keys> &
|
||||
// Pick the keys that should be writable from the base type and make them writable by removing the `readonly` modifier from the key.
|
||||
{-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]}
|
||||
>;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"endWith.js","sourceRoot":"","sources":["../../../../src/internal/operators/endWith.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AA8DtC,MAAM,UAAU,OAAO;IAAI,gBAAmC;SAAnC,UAAmC,EAAnC,qBAAmC,EAAnC,IAAmC;QAAnC,2BAAmC;;IAC5D,OAAO,UAAC,MAAqB,IAAK,OAAA,MAAM,CAAC,MAAM,EAAE,EAAE,wCAAI,MAAM,IAAmB,EAA9C,CAA8C,CAAC;AACnF,CAAC"}
|
||||
@@ -0,0 +1,33 @@
|
||||
import type {PromiseValue} from './promise-value';
|
||||
import type {SetReturnType} from './set-return-type';
|
||||
|
||||
/**
|
||||
Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types.
|
||||
|
||||
Use-case: You have two functions, one synchronous and one asynchronous that do the same thing. Instead of having to duplicate the type definition, you can use `Asyncify` to reuse the synchronous type.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Asyncify} from 'type-fest';
|
||||
|
||||
// Synchronous function.
|
||||
function getFooSync(someArg: SomeType): Foo {
|
||||
// …
|
||||
}
|
||||
|
||||
type AsyncifiedFooGetter = Asyncify<typeof getFooSync>;
|
||||
//=> type AsyncifiedFooGetter = (someArg: SomeType) => Promise<Foo>;
|
||||
|
||||
// Same as `getFooSync` but asynchronous.
|
||||
const getFooAsync: AsyncifiedFooGetter = (someArg) => {
|
||||
// TypeScript now knows that `someArg` is `SomeType` automatically.
|
||||
// It also knows that this function must return `Promise<Foo>`.
|
||||
// If you have `@typescript-eslint/promise-function-async` linter rule enabled, it will even report that "Functions that return promises must be async.".
|
||||
|
||||
// …
|
||||
}
|
||||
```
|
||||
|
||||
@category Async
|
||||
*/
|
||||
export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<PromiseValue<ReturnType<Fn>>>>;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"scanInternals.js","sourceRoot":"","sources":["../../../../src/internal/operators/scanInternals.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAWhE,MAAM,UAAU,aAAa,CAC3B,WAA2D,EAC3D,IAAO,EACP,OAAgB,EAChB,UAAmB,EACnB,kBAAqC;IAErC,OAAO,UAAC,MAAqB,EAAE,UAA2B;QAIxD,IAAI,QAAQ,GAAG,OAAO,CAAC;QAIvB,IAAI,KAAK,GAAQ,IAAI,CAAC;QAEtB,IAAI,KAAK,GAAG,CAAC,CAAC;QAGd,MAAM,CAAC,SAAS,CACd,wBAAwB,CACtB,UAAU,EACV,UAAC,KAAK;YAEJ,IAAM,CAAC,GAAG,KAAK,EAAE,CAAC;YAElB,KAAK,GAAG,QAAQ;gBACd,CAAC;oBACC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC9B,CAAC;oBAGC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;YAG/B,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC,EAGD,kBAAkB;YAChB,CAAC;gBACC,QAAQ,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACnC,UAAU,CAAC,QAAQ,EAAE,CAAC;YACxB,CAAC,CAAC,CACL,CACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { Transformer, Preprocessor } from '../types';
|
||||
export declare function transformMarkup({ content, filename }: {
|
||||
content: string;
|
||||
filename: string;
|
||||
}, transformer: Preprocessor | Transformer<unknown>, options?: Record<string, any>): Promise<import("svelte/types/compiler/preprocess").Processed>;
|
||||
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var str = "æøåäüö";
|
||||
|
||||
module.exports = function () {
|
||||
if (typeof str.normalize !== "function") return false;
|
||||
return str.normalize("NFKD") === "æøåäüö";
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
Represents an array of strings split using a given character or character set.
|
||||
|
||||
Use-case: Defining the return type of a method like `String.prototype.split`.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {Split} from 'type-fest';
|
||||
|
||||
declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
|
||||
|
||||
type Item = 'foo' | 'bar' | 'baz' | 'waldo';
|
||||
const items = 'foo,bar,baz,waldo';
|
||||
let array: Item[];
|
||||
|
||||
array = split(items, ',');
|
||||
```
|
||||
|
||||
@category String
|
||||
@category Template literal
|
||||
*/
|
||||
export type Split<
|
||||
S extends string,
|
||||
Delimiter extends string,
|
||||
> = S extends `${infer Head}${Delimiter}${infer Tail}`
|
||||
? [Head, ...Split<Tail, Delimiter>]
|
||||
: S extends Delimiter
|
||||
? []
|
||||
: [S];
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Def, Plugin } from "./types";
|
||||
export default function (defs: Def[]): {
|
||||
Type: {
|
||||
or(...types: any[]): import("./lib/types").Type<any>;
|
||||
from<T>(value: any, name?: string | undefined): import("./lib/types").Type<T>;
|
||||
def(typeName: string): import("./lib/types").Def<any>;
|
||||
hasDef(typeName: string): boolean;
|
||||
};
|
||||
builtInTypes: {
|
||||
string: import("./lib/types").Type<string>;
|
||||
function: import("./lib/types").Type<Function>;
|
||||
array: import("./lib/types").Type<any[]>;
|
||||
object: import("./lib/types").Type<{
|
||||
[key: string]: any;
|
||||
}>;
|
||||
RegExp: import("./lib/types").Type<RegExp>;
|
||||
Date: import("./lib/types").Type<Date>;
|
||||
number: import("./lib/types").Type<number>;
|
||||
boolean: import("./lib/types").Type<boolean>;
|
||||
null: import("./lib/types").Type<null>;
|
||||
undefined: import("./lib/types").Type<undefined>;
|
||||
};
|
||||
namedTypes: import("./gen/namedTypes").NamedTypes;
|
||||
builders: import("./gen/builders").builders;
|
||||
defineMethod: (name: any, func?: Function | undefined) => Function;
|
||||
getFieldNames: (object: any) => string[];
|
||||
getFieldValue: (object: any, fieldName: any) => any;
|
||||
eachField: (object: any, callback: (name: any, value: any) => any, context?: any) => void;
|
||||
someField: (object: any, callback: (name: any, value: any) => any, context?: any) => boolean;
|
||||
getSupertypeNames: (typeName: string) => string[];
|
||||
getBuilderName: (typeName: any) => any;
|
||||
astNodesAreEquivalent: {
|
||||
(a: any, b: any, problemPath?: any): boolean;
|
||||
assert(a: any, b: any): void;
|
||||
};
|
||||
finalize: () => void;
|
||||
Path: import("./lib/path").PathConstructor;
|
||||
NodePath: import("./lib/node-path").NodePathConstructor;
|
||||
PathVisitor: import("./lib/path-visitor").PathVisitorConstructor;
|
||||
use: <T_1>(plugin: Plugin<T_1>) => T_1;
|
||||
visit: <M = {}>(node: import("./lib/types").ASTNode, methods?: import("./main").Visitor<M> | undefined) => any;
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,18 @@
|
||||
// Given a version, figure out what the release channel is so that we can publish to the correct
|
||||
// channel on npm.
|
||||
//
|
||||
// E.g.:
|
||||
//
|
||||
// 1.2.3 -> latest (default)
|
||||
// 0.0.0-insiders.ffaa88 -> insiders
|
||||
// 4.1.0-alpha.4 -> alpha
|
||||
|
||||
let version =
|
||||
process.argv[2] || process.env.npm_package_version || require('../package.json').version
|
||||
|
||||
let match = /\d+\.\d+\.\d+-(.*)\.\d+/g.exec(version)
|
||||
if (match) {
|
||||
console.log(match[1])
|
||||
} else {
|
||||
console.log('latest')
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { VERSION } from "./version";
|
||||
/**
|
||||
* @param octokit Octokit instance
|
||||
* @param options Options passed to Octokit constructor
|
||||
*/
|
||||
export function requestLog(octokit) {
|
||||
octokit.hook.wrap("request", (request, options) => {
|
||||
octokit.log.debug("request", options);
|
||||
const start = Date.now();
|
||||
const requestOptions = octokit.request.endpoint.parse(options);
|
||||
const path = requestOptions.url.replace(options.baseUrl, "");
|
||||
return request(options)
|
||||
.then((response) => {
|
||||
octokit.log.info(`${requestOptions.method} ${path} - ${response.status} in ${Date.now() - start}ms`);
|
||||
return response;
|
||||
})
|
||||
.catch((error) => {
|
||||
octokit.log.info(`${requestOptions.method} ${path} - ${error.status} in ${Date.now() - start}ms`);
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
}
|
||||
requestLog.VERSION = VERSION;
|
||||
@@ -0,0 +1,120 @@
|
||||
import { OperatorFunction } from '../types';
|
||||
import { operate } from '../util/lift';
|
||||
import { createOperatorSubscriber } from './OperatorSubscriber';
|
||||
import { arrRemove } from '../util/arrRemove';
|
||||
|
||||
/**
|
||||
* Buffers the source Observable values until the size hits the maximum
|
||||
* `bufferSize` given.
|
||||
*
|
||||
* <span class="informal">Collects values from the past as an array, and emits
|
||||
* that array only when its size reaches `bufferSize`.</span>
|
||||
*
|
||||
* 
|
||||
*
|
||||
* Buffers a number of values from the source Observable by `bufferSize` then
|
||||
* emits the buffer and clears it, and starts a new buffer each
|
||||
* `startBufferEvery` values. If `startBufferEvery` is not provided or is
|
||||
* `null`, then new buffers are started immediately at the start of the source
|
||||
* and when each buffer closes and is emitted.
|
||||
*
|
||||
* ## Examples
|
||||
*
|
||||
* Emit the last two click events as an array
|
||||
*
|
||||
* ```ts
|
||||
* import { fromEvent, bufferCount } from 'rxjs';
|
||||
*
|
||||
* const clicks = fromEvent(document, 'click');
|
||||
* const buffered = clicks.pipe(bufferCount(2));
|
||||
* buffered.subscribe(x => console.log(x));
|
||||
* ```
|
||||
*
|
||||
* On every click, emit the last two click events as an array
|
||||
*
|
||||
* ```ts
|
||||
* import { fromEvent, bufferCount } from 'rxjs';
|
||||
*
|
||||
* const clicks = fromEvent(document, 'click');
|
||||
* const buffered = clicks.pipe(bufferCount(2, 1));
|
||||
* buffered.subscribe(x => console.log(x));
|
||||
* ```
|
||||
*
|
||||
* @see {@link buffer}
|
||||
* @see {@link bufferTime}
|
||||
* @see {@link bufferToggle}
|
||||
* @see {@link bufferWhen}
|
||||
* @see {@link pairwise}
|
||||
* @see {@link windowCount}
|
||||
*
|
||||
* @param {number} bufferSize The maximum size of the buffer emitted.
|
||||
* @param {number} [startBufferEvery] Interval at which to start a new buffer.
|
||||
* For example if `startBufferEvery` is `2`, then a new buffer will be started
|
||||
* on every other value from the source. A new buffer is started at the
|
||||
* beginning of the source by default.
|
||||
* @return A function that returns an Observable of arrays of buffered values.
|
||||
*/
|
||||
export function bufferCount<T>(bufferSize: number, startBufferEvery: number | null = null): OperatorFunction<T, T[]> {
|
||||
// If no `startBufferEvery` value was supplied, then we're
|
||||
// opening and closing on the bufferSize itself.
|
||||
startBufferEvery = startBufferEvery ?? bufferSize;
|
||||
|
||||
return operate((source, subscriber) => {
|
||||
let buffers: T[][] = [];
|
||||
let count = 0;
|
||||
|
||||
source.subscribe(
|
||||
createOperatorSubscriber(
|
||||
subscriber,
|
||||
(value) => {
|
||||
let toEmit: T[][] | null = null;
|
||||
|
||||
// Check to see if we need to start a buffer.
|
||||
// This will start one at the first value, and then
|
||||
// a new one every N after that.
|
||||
if (count++ % startBufferEvery! === 0) {
|
||||
buffers.push([]);
|
||||
}
|
||||
|
||||
// Push our value into our active buffers.
|
||||
for (const buffer of buffers) {
|
||||
buffer.push(value);
|
||||
// Check to see if we're over the bufferSize
|
||||
// if we are, record it so we can emit it later.
|
||||
// If we emitted it now and removed it, it would
|
||||
// mutate the `buffers` array while we're looping
|
||||
// over it.
|
||||
if (bufferSize <= buffer.length) {
|
||||
toEmit = toEmit ?? [];
|
||||
toEmit.push(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (toEmit) {
|
||||
// We have found some buffers that are over the
|
||||
// `bufferSize`. Emit them, and remove them from our
|
||||
// buffers list.
|
||||
for (const buffer of toEmit) {
|
||||
arrRemove(buffers, buffer);
|
||||
subscriber.next(buffer);
|
||||
}
|
||||
}
|
||||
},
|
||||
() => {
|
||||
// When the source completes, emit all of our
|
||||
// active buffers.
|
||||
for (const buffer of buffers) {
|
||||
subscriber.next(buffer);
|
||||
}
|
||||
subscriber.complete();
|
||||
},
|
||||
// Pass all errors through to consumer.
|
||||
undefined,
|
||||
() => {
|
||||
// Clean up our memory when we finalize
|
||||
buffers = null!;
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mergeMap.d.ts","sourceRoot":"","sources":["../../../../src/internal/operators/mergeMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAQ9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,eAAe,CAAC,GAAG,CAAC,EACxD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,EACvC,UAAU,CAAC,EAAE,MAAM,GAClB,gBAAgB,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,0JAA0J;AAC1J,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,eAAe,CAAC,GAAG,CAAC,EACxD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,EACvC,cAAc,EAAE,SAAS,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,gBAAgB,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,0JAA0J;AAC1J,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,eAAe,CAAC,GAAG,CAAC,EAC3D,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,EACvC,cAAc,EAAE,CAAC,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC,EAC5G,UAAU,CAAC,EAAE,MAAM,GAClB,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
||||
@@ -0,0 +1,154 @@
|
||||
var test = require('tape')
|
||||
var acorn = require('../')
|
||||
var walk = require('../walk')
|
||||
var baseAcorn = require('acorn')
|
||||
|
||||
test('parses object spread syntax', function (t) {
|
||||
var ast = acorn.parse('var a = { ...b }')
|
||||
t.equal(ast.body[0].declarations[0].init.type, 'ObjectExpression')
|
||||
t.equal(ast.body[0].declarations[0].init.properties[0].type, 'SpreadElement')
|
||||
|
||||
ast = acorn.parse('function a ({ ...b }) {}')
|
||||
t.equal(ast.body[0].params[0].type, 'ObjectPattern')
|
||||
t.equal(ast.body[0].params[0].properties[0].type, 'RestElement')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('does not change main acorn module', function (t) {
|
||||
t.throws(function () {
|
||||
baseAcorn.parse('var a = 10n')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('tokenizes object spread syntax', function (t) {
|
||||
var tokenizer = acorn.tokenizer('var a = { ...b }')
|
||||
|
||||
t.doesNotThrow(function (t) {
|
||||
while (tokenizer.getToken().type !== acorn.tokTypes.eof) {}
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('allows hashbangs by default', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('#!/usr/bin/env node\nconsole.log("ok")')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('allows top level return by default', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('console.log("ok"); return; console.log("not ok")')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports async generators', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('async function* a () { await x; yield 1 }')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports async iteration', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('async function l (y) { for await (const x of y) {} }')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports optional catch', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('try { throw null } catch {}')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports bigint', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('50n ** 50n')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports numeric separators', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('50_000_000n ** 1n')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports import.meta with sourceType: module', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('console.log(import.meta.url)', { sourceType: 'module' })
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports dynamic import() with sourceType: module', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('import("./whatever.mjs")', { sourceType: 'module' })
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports dynamic import() with sourceType: script', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('import("./whatever.mjs")', { sourceType: 'script' })
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports class instance properties', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('class X { x = y }', { sourceType: 'script' })
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports private class instance properties', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('class X { #x = y }', { sourceType: 'script' })
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports class static properties', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('class X { static x = y }', { sourceType: 'script' })
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports private class static properties', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('class X { static #x = y }', { sourceType: 'script' })
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('supports namespace export syntax with sourceType: module', function (t) {
|
||||
t.doesNotThrow(function () {
|
||||
acorn.parse('export * as x from "./x.mjs";', { sourceType: 'module' })
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('walk supports plugin syntax', function (t) {
|
||||
var ast = acorn.parse(
|
||||
'async function* a() { try { await import(xyz); } catch { for await (x of null) {} } yield import.meta.url }',
|
||||
{ sourceType: 'module' }
|
||||
)
|
||||
t.plan(2)
|
||||
walk.simple(ast, {
|
||||
Import: function () {
|
||||
t.pass('import()')
|
||||
},
|
||||
MetaProperty: function () {
|
||||
t.pass('import.meta')
|
||||
}
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "module",
|
||||
"browser": {
|
||||
"crypto": false,
|
||||
"./crypto": "./esm/cryptoBrowser.js"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
var parse = require("./parse");
|
||||
var walk = require("./walk");
|
||||
var stringify = require("./stringify");
|
||||
|
||||
function ValueParser(value) {
|
||||
if (this instanceof ValueParser) {
|
||||
this.nodes = parse(value);
|
||||
return this;
|
||||
}
|
||||
return new ValueParser(value);
|
||||
}
|
||||
|
||||
ValueParser.prototype.toString = function() {
|
||||
return Array.isArray(this.nodes) ? stringify(this.nodes) : "";
|
||||
};
|
||||
|
||||
ValueParser.prototype.walk = function(cb, bubble) {
|
||||
walk(this.nodes, cb, bubble);
|
||||
return this;
|
||||
};
|
||||
|
||||
ValueParser.unit = require("./unit");
|
||||
|
||||
ValueParser.walk = walk;
|
||||
|
||||
ValueParser.stringify = stringify;
|
||||
|
||||
module.exports = ValueParser;
|
||||
@@ -0,0 +1,210 @@
|
||||
# type-check [](https://travis-ci.org/gkz/type-check)
|
||||
|
||||
<a name="type-check" />
|
||||
|
||||
`type-check` is a library which allows you to check the types of JavaScript values at runtime with a Haskell like type syntax. It is great for checking external input, for testing, or even for adding a bit of safety to your internal code. It is a major component of [levn](https://github.com/gkz/levn). MIT license. Version 0.3.2. Check out the [demo](http://gkz.github.io/type-check/).
|
||||
|
||||
For updates on `type-check`, [follow me on twitter](https://twitter.com/gkzahariev).
|
||||
|
||||
npm install type-check
|
||||
|
||||
## Quick Examples
|
||||
|
||||
```js
|
||||
// Basic types:
|
||||
var typeCheck = require('type-check').typeCheck;
|
||||
typeCheck('Number', 1); // true
|
||||
typeCheck('Number', 'str'); // false
|
||||
typeCheck('Error', new Error); // true
|
||||
typeCheck('Undefined', undefined); // true
|
||||
|
||||
// Comment
|
||||
typeCheck('count::Number', 1); // true
|
||||
|
||||
// One type OR another type:
|
||||
typeCheck('Number | String', 2); // true
|
||||
typeCheck('Number | String', 'str'); // true
|
||||
|
||||
// Wildcard, matches all types:
|
||||
typeCheck('*', 2) // true
|
||||
|
||||
// Array, all elements of a single type:
|
||||
typeCheck('[Number]', [1, 2, 3]); // true
|
||||
typeCheck('[Number]', [1, 'str', 3]); // false
|
||||
|
||||
// Tuples, or fixed length arrays with elements of different types:
|
||||
typeCheck('(String, Number)', ['str', 2]); // true
|
||||
typeCheck('(String, Number)', ['str']); // false
|
||||
typeCheck('(String, Number)', ['str', 2, 5]); // false
|
||||
|
||||
// Object properties:
|
||||
typeCheck('{x: Number, y: Boolean}', {x: 2, y: false}); // true
|
||||
typeCheck('{x: Number, y: Boolean}', {x: 2}); // false
|
||||
typeCheck('{x: Number, y: Maybe Boolean}', {x: 2}); // true
|
||||
typeCheck('{x: Number, y: Boolean}', {x: 2, y: false, z: 3}); // false
|
||||
typeCheck('{x: Number, y: Boolean, ...}', {x: 2, y: false, z: 3}); // true
|
||||
|
||||
// A particular type AND object properties:
|
||||
typeCheck('RegExp{source: String, ...}', /re/i); // true
|
||||
typeCheck('RegExp{source: String, ...}', {source: 're'}); // false
|
||||
|
||||
// Custom types:
|
||||
var opt = {customTypes:
|
||||
{Even: { typeOf: 'Number', validate: function(x) { return x % 2 === 0; }}}};
|
||||
typeCheck('Even', 2, opt); // true
|
||||
|
||||
// Nested:
|
||||
var type = '{a: (String, [Number], {y: Array, ...}), b: Error{message: String, ...}}'
|
||||
typeCheck(type, {a: ['hi', [1, 2, 3], {y: [1, 'ms']}], b: new Error('oh no')}); // true
|
||||
```
|
||||
|
||||
Check out the [type syntax format](#syntax) and [guide](#guide).
|
||||
|
||||
## Usage
|
||||
|
||||
`require('type-check');` returns an object that exposes four properties. `VERSION` is the current version of the library as a string. `typeCheck`, `parseType`, and `parsedTypeCheck` are functions.
|
||||
|
||||
```js
|
||||
// typeCheck(type, input, options);
|
||||
typeCheck('Number', 2); // true
|
||||
|
||||
// parseType(type);
|
||||
var parsedType = parseType('Number'); // object
|
||||
|
||||
// parsedTypeCheck(parsedType, input, options);
|
||||
parsedTypeCheck(parsedType, 2); // true
|
||||
```
|
||||
|
||||
### typeCheck(type, input, options)
|
||||
|
||||
`typeCheck` checks a JavaScript value `input` against `type` written in the [type format](#type-format) (and taking account the optional `options`) and returns whether the `input` matches the `type`.
|
||||
|
||||
##### arguments
|
||||
* type - `String` - the type written in the [type format](#type-format) which to check against
|
||||
* input - `*` - any JavaScript value, which is to be checked against the type
|
||||
* options - `Maybe Object` - an optional parameter specifying additional options, currently the only available option is specifying [custom types](#custom-types)
|
||||
|
||||
##### returns
|
||||
`Boolean` - whether the input matches the type
|
||||
|
||||
##### example
|
||||
```js
|
||||
typeCheck('Number', 2); // true
|
||||
```
|
||||
|
||||
### parseType(type)
|
||||
|
||||
`parseType` parses string `type` written in the [type format](#type-format) into an object representing the parsed type.
|
||||
|
||||
##### arguments
|
||||
* type - `String` - the type written in the [type format](#type-format) which to parse
|
||||
|
||||
##### returns
|
||||
`Object` - an object in the parsed type format representing the parsed type
|
||||
|
||||
##### example
|
||||
```js
|
||||
parseType('Number'); // [{type: 'Number'}]
|
||||
```
|
||||
### parsedTypeCheck(parsedType, input, options)
|
||||
|
||||
`parsedTypeCheck` checks a JavaScript value `input` against parsed `type` in the parsed type format (and taking account the optional `options`) and returns whether the `input` matches the `type`. Use this in conjunction with `parseType` if you are going to use a type more than once.
|
||||
|
||||
##### arguments
|
||||
* type - `Object` - the type in the parsed type format which to check against
|
||||
* input - `*` - any JavaScript value, which is to be checked against the type
|
||||
* options - `Maybe Object` - an optional parameter specifying additional options, currently the only available option is specifying [custom types](#custom-types)
|
||||
|
||||
##### returns
|
||||
`Boolean` - whether the input matches the type
|
||||
|
||||
##### example
|
||||
```js
|
||||
parsedTypeCheck([{type: 'Number'}], 2); // true
|
||||
var parsedType = parseType('String');
|
||||
parsedTypeCheck(parsedType, 'str'); // true
|
||||
```
|
||||
|
||||
<a name="type-format" />
|
||||
## Type Format
|
||||
|
||||
### Syntax
|
||||
|
||||
White space is ignored. The root node is a __Types__.
|
||||
|
||||
* __Identifier__ = `[\$\w]+` - a group of any lower or upper case letters, numbers, underscores, or dollar signs - eg. `String`
|
||||
* __Type__ = an `Identifier`, an `Identifier` followed by a `Structure`, just a `Structure`, or a wildcard `*` - eg. `String`, `Object{x: Number}`, `{x: Number}`, `Array{0: String, 1: Boolean, length: Number}`, `*`
|
||||
* __Types__ = optionally a comment (an `Indentifier` followed by a `::`), optionally the identifier `Maybe`, one or more `Type`, separated by `|` - eg. `Number`, `String | Date`, `Maybe Number`, `Maybe Boolean | String`
|
||||
* __Structure__ = `Fields`, or a `Tuple`, or an `Array` - eg. `{x: Number}`, `(String, Number)`, `[Date]`
|
||||
* __Fields__ = a `{`, followed one or more `Field` separated by a comma `,` (trailing comma `,` is permitted), optionally an `...` (always preceded by a comma `,`), followed by a `}` - eg. `{x: Number, y: String}`, `{k: Function, ...}`
|
||||
* __Field__ = an `Identifier`, followed by a colon `:`, followed by `Types` - eg. `x: Date | String`, `y: Boolean`
|
||||
* __Tuple__ = a `(`, followed by one or more `Types` separated by a comma `,` (trailing comma `,` is permitted), followed by a `)` - eg `(Date)`, `(Number, Date)`
|
||||
* __Array__ = a `[` followed by exactly one `Types` followed by a `]` - eg. `[Boolean]`, `[Boolean | Null]`
|
||||
|
||||
### Guide
|
||||
|
||||
`type-check` uses `Object.toString` to find out the basic type of a value. Specifically,
|
||||
|
||||
```js
|
||||
{}.toString.call(VALUE).slice(8, -1)
|
||||
{}.toString.call(true).slice(8, -1) // 'Boolean'
|
||||
```
|
||||
A basic type, eg. `Number`, uses this check. This is much more versatile than using `typeof` - for example, with `document`, `typeof` produces `'object'` which isn't that useful, and our technique produces `'HTMLDocument'`.
|
||||
|
||||
You may check for multiple types by separating types with a `|`. The checker proceeds from left to right, and passes if the value is any of the types - eg. `String | Boolean` first checks if the value is a string, and then if it is a boolean. If it is none of those, then it returns false.
|
||||
|
||||
Adding a `Maybe` in front of a list of multiple types is the same as also checking for `Null` and `Undefined` - eg. `Maybe String` is equivalent to `Undefined | Null | String`.
|
||||
|
||||
You may add a comment to remind you of what the type is for by following an identifier with a `::` before a type (or multiple types). The comment is simply thrown out.
|
||||
|
||||
The wildcard `*` matches all types.
|
||||
|
||||
There are three types of structures for checking the contents of a value: 'fields', 'tuple', and 'array'.
|
||||
|
||||
If used by itself, a 'fields' structure will pass with any type of object as long as it is an instance of `Object` and the properties pass - this allows for duck typing - eg. `{x: Boolean}`.
|
||||
|
||||
To check if the properties pass, and the value is of a certain type, you can specify the type - eg. `Error{message: String}`.
|
||||
|
||||
If you want to make a field optional, you can simply use `Maybe` - eg. `{x: Boolean, y: Maybe String}` will still pass if `y` is undefined (or null).
|
||||
|
||||
If you don't care if the value has properties beyond what you have specified, you can use the 'etc' operator `...` - eg. `{x: Boolean, ...}` will match an object with an `x` property that is a boolean, and with zero or more other properties.
|
||||
|
||||
For an array, you must specify one or more types (separated by `|`) - it will pass for something of any length as long as each element passes the types provided - eg. `[Number]`, `[Number | String]`.
|
||||
|
||||
A tuple checks for a fixed number of elements, each of a potentially different type. Each element is separated by a comma - eg. `(String, Number)`.
|
||||
|
||||
An array and tuple structure check that the value is of type `Array` by default, but if another type is specified, they will check for that instead - eg. `Int32Array[Number]`. You can use the wildcard `*` to search for any type at all.
|
||||
|
||||
Check out the [type precedence](https://github.com/zaboco/type-precedence) library for type-check.
|
||||
|
||||
## Options
|
||||
|
||||
Options is an object. It is an optional parameter to the `typeCheck` and `parsedTypeCheck` functions. The only current option is `customTypes`.
|
||||
|
||||
<a name="custom-types" />
|
||||
### Custom Types
|
||||
|
||||
__Example:__
|
||||
|
||||
```js
|
||||
var options = {
|
||||
customTypes: {
|
||||
Even: {
|
||||
typeOf: 'Number',
|
||||
validate: function(x) {
|
||||
return x % 2 === 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
typeCheck('Even', 2, options); // true
|
||||
typeCheck('Even', 3, options); // false
|
||||
```
|
||||
|
||||
`customTypes` allows you to set up custom types for validation. The value of this is an object. The keys of the object are the types you will be matching. Each value of the object will be an object having a `typeOf` property - a string, and `validate` property - a function.
|
||||
|
||||
The `typeOf` property is the type the value should be, and `validate` is a function which should return true if the value is of that type. `validate` receives one parameter, which is the value that we are checking.
|
||||
|
||||
## Technical About
|
||||
|
||||
`type-check` is written in [LiveScript](http://livescript.net/) - a language that compiles to JavaScript. It also uses the [prelude.ls](http://preludels.com/) library.
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"forkJoin.js","sourceRoot":"","sources":["../../../../src/internal/observable/forkJoin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA2IpD,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAW;IACrC,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,CAAC,UAAU,EAAE,EAAE;QAC3C,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAC3B,IAAI,CAAC,MAAM,EAAE;YACX,UAAU,CAAC,QAAQ,EAAE,CAAC;YACtB,OAAO;SACR;QACD,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,oBAAoB,GAAG,MAAM,CAAC;QAClC,IAAI,kBAAkB,GAAG,MAAM,CAAC;QAChC,KAAK,IAAI,WAAW,GAAG,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE,WAAW,EAAE,EAAE;YAC7D,IAAI,QAAQ,GAAG,KAAK,CAAC;YACrB,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CACvC,wBAAwB,CACtB,UAAU,EACV,CAAC,KAAK,EAAE,EAAE;gBACR,IAAI,CAAC,QAAQ,EAAE;oBACb,QAAQ,GAAG,IAAI,CAAC;oBAChB,kBAAkB,EAAE,CAAC;iBACtB;gBACD,MAAM,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC,EACD,GAAG,EAAE,CAAC,oBAAoB,EAAE,EAC5B,SAAS,EACT,GAAG,EAAE;gBACH,IAAI,CAAC,oBAAoB,IAAI,CAAC,QAAQ,EAAE;oBACtC,IAAI,CAAC,kBAAkB,EAAE;wBACvB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;qBAC7D;oBACD,UAAU,CAAC,QAAQ,EAAE,CAAC;iBACvB;YACH,CAAC,CACF,CACF,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IACH,OAAO,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACjF,CAAC"}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('./wrapperValue');
|
||||
@@ -0,0 +1,86 @@
|
||||
/* Generated by `npm run build`, do not edit! */
|
||||
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.DynamicImportKey = undefined;
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) { descriptor.writable = true; } Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) { defineProperties(Constructor.prototype, protoProps); } if (staticProps) { defineProperties(Constructor, staticProps); } return Constructor; }; }();
|
||||
|
||||
var _get = function () {
|
||||
function get(object, property, receiver) { if (object === null) { object = Function.prototype; } var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }
|
||||
|
||||
return get;
|
||||
}();
|
||||
|
||||
exports['default'] = dynamicImport;
|
||||
|
||||
var _acorn = require('acorn');
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) { Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } } /* eslint-disable no-underscore-dangle */
|
||||
|
||||
|
||||
var DynamicImportKey = exports.DynamicImportKey = 'Import';
|
||||
|
||||
// NOTE: This allows `yield import()` to parse correctly.
|
||||
_acorn.tokTypes._import.startsExpr = true;
|
||||
|
||||
function parseDynamicImport() {
|
||||
var node = this.startNode();
|
||||
this.next();
|
||||
if (this.type !== _acorn.tokTypes.parenL) {
|
||||
this.unexpected();
|
||||
}
|
||||
return this.finishNode(node, DynamicImportKey);
|
||||
}
|
||||
|
||||
function parenAfter() {
|
||||
return (/^(\s|\/\/.*|\/\*[^]*?\*\/)*\(/.test(this.input.slice(this.pos))
|
||||
);
|
||||
}
|
||||
|
||||
function dynamicImport(Parser) {
|
||||
return function (_Parser) {
|
||||
_inherits(_class, _Parser);
|
||||
|
||||
function _class() {
|
||||
_classCallCheck(this, _class);
|
||||
|
||||
return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(_class, [{
|
||||
key: 'parseStatement',
|
||||
value: function () {
|
||||
function parseStatement(context, topLevel, exports) {
|
||||
if (this.type === _acorn.tokTypes._import && parenAfter.call(this)) {
|
||||
return this.parseExpressionStatement(this.startNode(), this.parseExpression());
|
||||
}
|
||||
return _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'parseStatement', this).call(this, context, topLevel, exports);
|
||||
}
|
||||
|
||||
return parseStatement;
|
||||
}()
|
||||
}, {
|
||||
key: 'parseExprAtom',
|
||||
value: function () {
|
||||
function parseExprAtom(refDestructuringErrors) {
|
||||
if (this.type === _acorn.tokTypes._import) {
|
||||
return parseDynamicImport.call(this);
|
||||
}
|
||||
return _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'parseExprAtom', this).call(this, refDestructuringErrors);
|
||||
}
|
||||
|
||||
return parseExprAtom;
|
||||
}()
|
||||
}]);
|
||||
|
||||
return _class;
|
||||
}(Parser);
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
2018-06-17: Version 4.0.1
|
||||
|
||||
* Fix parsing async get/set in a class (issue 1861, 1875)
|
||||
* Account for different return statement argument (issue 1829, 1897, 1928)
|
||||
* Correct the handling of HTML comment when parsing a module (issue 1841)
|
||||
* Fix incorrect parse async with proto-identifier-shorthand (issue 1847)
|
||||
* Fix negative column in binary expression (issue 1844)
|
||||
* Fix incorrect YieldExpression in object methods (issue 1834)
|
||||
* Various documentation fixes
|
||||
|
||||
2017-06-10: Version 4.0.0
|
||||
|
||||
* Support ES2017 async function and await expression (issue 1079)
|
||||
* Support ES2017 trailing commas in function parameters (issue 1550)
|
||||
* Explicitly distinguish parsing a module vs a script (issue 1576)
|
||||
* Fix JSX non-empty container (issue 1786)
|
||||
* Allow JSX element in a yield expression (issue 1765)
|
||||
* Allow `in` expression in a concise body with a function body (issue 1793)
|
||||
* Setter function argument must not be a rest parameter (issue 1693)
|
||||
* Limit strict mode directive to functions with a simple parameter list (issue 1677)
|
||||
* Prohibit any escape sequence in a reserved word (issue 1612)
|
||||
* Only permit hex digits in hex escape sequence (issue 1619)
|
||||
* Prohibit labelled class/generator/function declaration (issue 1484)
|
||||
* Limit function declaration as if statement clause only in non-strict mode (issue 1657)
|
||||
* Tolerate missing ) in a with and do-while statement (issue 1481)
|
||||
|
||||
2016-12-22: Version 3.1.3
|
||||
|
||||
* Support binding patterns as rest element (issue 1681)
|
||||
* Account for different possible arguments of a yield expression (issue 1469)
|
||||
|
||||
2016-11-24: Version 3.1.2
|
||||
|
||||
* Ensure that import specifier is more restrictive (issue 1615)
|
||||
* Fix duplicated JSX tokens (issue 1613)
|
||||
* Scan template literal in a JSX expression container (issue 1622)
|
||||
* Improve XHTML entity scanning in JSX (issue 1629)
|
||||
|
||||
2016-10-31: Version 3.1.1
|
||||
|
||||
* Fix assignment expression problem in an export declaration (issue 1596)
|
||||
* Fix incorrect tokenization of hex digits (issue 1605)
|
||||
|
||||
2016-10-09: Version 3.1.0
|
||||
|
||||
* Do not implicitly collect comments when comment attachment is specified (issue 1553)
|
||||
* Fix incorrect handling of duplicated proto shorthand fields (issue 1485)
|
||||
* Prohibit initialization in some variants of for statements (issue 1309, 1561)
|
||||
* Fix incorrect parsing of export specifier (issue 1578)
|
||||
* Fix ESTree compatibility for assignment pattern (issue 1575)
|
||||
|
||||
2016-09-03: Version 3.0.0
|
||||
|
||||
* Support ES2016 exponentiation expression (issue 1490)
|
||||
* Support JSX syntax (issue 1467)
|
||||
* Use the latest Unicode 8.0 (issue 1475)
|
||||
* Add the support for syntax node delegate (issue 1435)
|
||||
* Fix ESTree compatibility on meta property (issue 1338)
|
||||
* Fix ESTree compatibility on default parameter value (issue 1081)
|
||||
* Fix ESTree compatibility on try handler (issue 1030)
|
||||
|
||||
2016-08-23: Version 2.7.3
|
||||
|
||||
* Fix tokenizer confusion with a comment (issue 1493, 1516)
|
||||
|
||||
2016-02-02: Version 2.7.2
|
||||
|
||||
* Fix out-of-bound error location in an invalid string literal (issue 1457)
|
||||
* Fix shorthand object destructuring defaults in variable declarations (issue 1459)
|
||||
|
||||
2015-12-10: Version 2.7.1
|
||||
|
||||
* Do not allow trailing comma in a variable declaration (issue 1360)
|
||||
* Fix assignment to `let` in non-strict mode (issue 1376)
|
||||
* Fix missing delegate property in YieldExpression (issue 1407)
|
||||
|
||||
2015-10-22: Version 2.7.0
|
||||
|
||||
* Fix the handling of semicolon in a break statement (issue 1044)
|
||||
* Run the test suite with major web browsers (issue 1259, 1317)
|
||||
* Allow `let` as an identifier in non-strict mode (issue 1289)
|
||||
* Attach orphaned comments as `innerComments` (issue 1328)
|
||||
* Add the support for token delegator (issue 1332)
|
||||
|
||||
2015-09-01: Version 2.6.0
|
||||
|
||||
* Properly allow or prohibit `let` in a binding identifier/pattern (issue 1048, 1098)
|
||||
* Add sourceType field for Program node (issue 1159)
|
||||
* Ensure that strict mode reserved word binding throw an error (issue 1171)
|
||||
* Run the test suite with Node.js and IE 11 on Windows (issue 1294)
|
||||
* Allow binding pattern with no initializer in a for statement (issue 1301)
|
||||
|
||||
2015-07-31: Version 2.5.0
|
||||
|
||||
* Run the test suite in a browser environment (issue 1004)
|
||||
* Ensure a comma between imported default binding and named imports (issue 1046)
|
||||
* Distinguish `yield` as a keyword vs an identifier (issue 1186)
|
||||
* Support ES6 meta property `new.target` (issue 1203)
|
||||
* Fix the syntax node for yield with expression (issue 1223)
|
||||
* Fix the check of duplicated proto in property names (issue 1225)
|
||||
* Fix ES6 Unicode escape in identifier name (issue 1229)
|
||||
* Support ES6 IdentifierStart and IdentifierPart (issue 1232)
|
||||
* Treat await as a reserved word when parsing as a module (issue 1234)
|
||||
* Recognize identifier characters from Unicode SMP (issue 1244)
|
||||
* Ensure that export and import can be followed by a comma (issue 1250)
|
||||
* Fix yield operator precedence (issue 1262)
|
||||
|
||||
2015-07-01: Version 2.4.1
|
||||
|
||||
* Fix some cases of comment attachment (issue 1071, 1175)
|
||||
* Fix the handling of destructuring in function arguments (issue 1193)
|
||||
* Fix invalid ranges in assignment expression (issue 1201)
|
||||
|
||||
2015-06-26: Version 2.4.0
|
||||
|
||||
* Support ES6 for-of iteration (issue 1047)
|
||||
* Support ES6 spread arguments (issue 1169)
|
||||
* Minimize npm payload (issue 1191)
|
||||
|
||||
2015-06-16: Version 2.3.0
|
||||
|
||||
* Support ES6 generator (issue 1033)
|
||||
* Improve parsing of regular expressions with `u` flag (issue 1179)
|
||||
|
||||
2015-04-17: Version 2.2.0
|
||||
|
||||
* Support ES6 import and export declarations (issue 1000)
|
||||
* Fix line terminator before arrow not recognized as error (issue 1009)
|
||||
* Support ES6 destructuring (issue 1045)
|
||||
* Support ES6 template literal (issue 1074)
|
||||
* Fix the handling of invalid/incomplete string escape sequences (issue 1106)
|
||||
* Fix ES3 static member access restriction (issue 1120)
|
||||
* Support for `super` in ES6 class (issue 1147)
|
||||
|
||||
2015-03-09: Version 2.1.0
|
||||
|
||||
* Support ES6 class (issue 1001)
|
||||
* Support ES6 rest parameter (issue 1011)
|
||||
* Expand the location of property getter, setter, and methods (issue 1029)
|
||||
* Enable TryStatement transition to a single handler (issue 1031)
|
||||
* Support ES6 computed property name (issue 1037)
|
||||
* Tolerate unclosed block comment (issue 1041)
|
||||
* Support ES6 lexical declaration (issue 1065)
|
||||
|
||||
2015-02-06: Version 2.0.0
|
||||
|
||||
* Support ES6 arrow function (issue 517)
|
||||
* Support ES6 Unicode code point escape (issue 521)
|
||||
* Improve the speed and accuracy of comment attachment (issue 522)
|
||||
* Support ES6 default parameter (issue 519)
|
||||
* Support ES6 regular expression flags (issue 557)
|
||||
* Fix scanning of implicit octal literals (issue 565)
|
||||
* Fix the handling of automatic semicolon insertion (issue 574)
|
||||
* Support ES6 method definition (issue 620)
|
||||
* Support ES6 octal integer literal (issue 621)
|
||||
* Support ES6 binary integer literal (issue 622)
|
||||
* Support ES6 object literal property value shorthand (issue 624)
|
||||
|
||||
2015-03-03: Version 1.2.5
|
||||
|
||||
* Fix scanning of implicit octal literals (issue 565)
|
||||
|
||||
2015-02-05: Version 1.2.4
|
||||
|
||||
* Fix parsing of LeftHandSideExpression in ForInStatement (issue 560)
|
||||
* Fix the handling of automatic semicolon insertion (issue 574)
|
||||
|
||||
2015-01-18: Version 1.2.3
|
||||
|
||||
* Fix division by this (issue 616)
|
||||
|
||||
2014-05-18: Version 1.2.2
|
||||
|
||||
* Fix duplicated tokens when collecting comments (issue 537)
|
||||
|
||||
2014-05-04: Version 1.2.1
|
||||
|
||||
* Ensure that Program node may still have leading comments (issue 536)
|
||||
|
||||
2014-04-29: Version 1.2.0
|
||||
|
||||
* Fix semicolon handling for expression statement (issue 462, 533)
|
||||
* Disallow escaped characters in regular expression flags (issue 503)
|
||||
* Performance improvement for location tracking (issue 520)
|
||||
* Improve the speed of comment attachment (issue 522)
|
||||
|
||||
2014-03-26: Version 1.1.1
|
||||
|
||||
* Fix token handling of forward slash after an array literal (issue 512)
|
||||
|
||||
2014-03-23: Version 1.1.0
|
||||
|
||||
* Optionally attach comments to the owning syntax nodes (issue 197)
|
||||
* Simplify binary parsing with stack-based shift reduce (issue 352)
|
||||
* Always include the raw source of literals (issue 376)
|
||||
* Add optional input source information (issue 386)
|
||||
* Tokenizer API for pure lexical scanning (issue 398)
|
||||
* Improve the web site and its online demos (issue 337, 400, 404)
|
||||
* Performance improvement for location tracking (issue 417, 424)
|
||||
* Support HTML comment syntax (issue 451)
|
||||
* Drop support for legacy browsers (issue 474)
|
||||
|
||||
2013-08-27: Version 1.0.4
|
||||
|
||||
* Minimize the payload for packages (issue 362)
|
||||
* Fix missing cases on an empty switch statement (issue 436)
|
||||
* Support escaped ] in regexp literal character classes (issue 442)
|
||||
* Tolerate invalid left-hand side expression (issue 130)
|
||||
|
||||
2013-05-17: Version 1.0.3
|
||||
|
||||
* Variable declaration needs at least one declarator (issue 391)
|
||||
* Fix benchmark's variance unit conversion (issue 397)
|
||||
* IE < 9: \v should be treated as vertical tab (issue 405)
|
||||
* Unary expressions should always have prefix: true (issue 418)
|
||||
* Catch clause should only accept an identifier (issue 423)
|
||||
* Tolerate setters without parameter (issue 426)
|
||||
|
||||
2012-11-02: Version 1.0.2
|
||||
|
||||
Improvement:
|
||||
|
||||
* Fix esvalidate JUnit output upon a syntax error (issue 374)
|
||||
|
||||
2012-10-28: Version 1.0.1
|
||||
|
||||
Improvements:
|
||||
|
||||
* esvalidate understands shebang in a Unix shell script (issue 361)
|
||||
* esvalidate treats fatal parsing failure as an error (issue 361)
|
||||
* Reduce Node.js package via .npmignore (issue 362)
|
||||
|
||||
2012-10-22: Version 1.0.0
|
||||
|
||||
Initial release.
|
||||
@@ -0,0 +1,125 @@
|
||||
let Prefixer = require('./prefixer')
|
||||
let OldValue = require('./old-value')
|
||||
let vendor = require('./vendor')
|
||||
let utils = require('./utils')
|
||||
|
||||
class Value extends Prefixer {
|
||||
/**
|
||||
* Clone decl for each prefixed values
|
||||
*/
|
||||
static save(prefixes, decl) {
|
||||
let prop = decl.prop
|
||||
let result = []
|
||||
|
||||
for (let prefix in decl._autoprefixerValues) {
|
||||
let value = decl._autoprefixerValues[prefix]
|
||||
|
||||
if (value === decl.value) {
|
||||
continue
|
||||
}
|
||||
|
||||
let item
|
||||
let propPrefix = vendor.prefix(prop)
|
||||
|
||||
if (propPrefix === '-pie-') {
|
||||
continue
|
||||
}
|
||||
|
||||
if (propPrefix === prefix) {
|
||||
item = decl.value = value
|
||||
result.push(item)
|
||||
continue
|
||||
}
|
||||
|
||||
let prefixed = prefixes.prefixed(prop, prefix)
|
||||
let rule = decl.parent
|
||||
|
||||
if (!rule.every(i => i.prop !== prefixed)) {
|
||||
result.push(item)
|
||||
continue
|
||||
}
|
||||
|
||||
let trimmed = value.replace(/\s+/, ' ')
|
||||
let already = rule.some(
|
||||
i => i.prop === decl.prop && i.value.replace(/\s+/, ' ') === trimmed
|
||||
)
|
||||
|
||||
if (already) {
|
||||
result.push(item)
|
||||
continue
|
||||
}
|
||||
|
||||
let cloned = this.clone(decl, { value })
|
||||
item = decl.parent.insertBefore(decl, cloned)
|
||||
|
||||
result.push(item)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Is declaration need to be prefixed
|
||||
*/
|
||||
check(decl) {
|
||||
let value = decl.value
|
||||
if (!value.includes(this.name)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return !!value.match(this.regexp())
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy regexp loading
|
||||
*/
|
||||
regexp() {
|
||||
return this.regexpCache || (this.regexpCache = utils.regexp(this.name))
|
||||
}
|
||||
|
||||
/**
|
||||
* Add prefix to values in string
|
||||
*/
|
||||
replace(string, prefix) {
|
||||
return string.replace(this.regexp(), `$1${prefix}$2`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value with comments if it was not changed
|
||||
*/
|
||||
value(decl) {
|
||||
if (decl.raws.value && decl.raws.value.value === decl.value) {
|
||||
return decl.raws.value.raw
|
||||
} else {
|
||||
return decl.value
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save values with next prefixed token
|
||||
*/
|
||||
add(decl, prefix) {
|
||||
if (!decl._autoprefixerValues) {
|
||||
decl._autoprefixerValues = {}
|
||||
}
|
||||
let value = decl._autoprefixerValues[prefix] || this.value(decl)
|
||||
|
||||
let before
|
||||
do {
|
||||
before = value
|
||||
value = this.replace(value, prefix)
|
||||
if (value === false) return
|
||||
} while (value !== before)
|
||||
|
||||
decl._autoprefixerValues[prefix] = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Return function to fast find prefixed value
|
||||
*/
|
||||
old(prefix) {
|
||||
return new OldValue(this.name, prefix + this.name)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Value
|
||||
@@ -0,0 +1,89 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const util_1 = require("./util");
|
||||
const weekdays = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
|
||||
/**
|
||||
* Only the first parameter is mandatory. Either the second, the third, or both
|
||||
* may be left out.
|
||||
*
|
||||
* If only one parameter is present, the function yeilds a true value on the
|
||||
* weekday that the parameter represents. If the string "GMT" is specified as
|
||||
* a second parameter, times are taken to be in GMT, otherwise in local timezone.
|
||||
*
|
||||
* If both wd1 and wd1 are defined, the condition is true if the current weekday
|
||||
* is in between those two weekdays. Bounds are inclusive. If the "GMT" parameter
|
||||
* is specified, times are taken to be in GMT, otherwise the local timezone is
|
||||
* used.
|
||||
*
|
||||
* Valid "weekday strings" are:
|
||||
*
|
||||
* SUN MON TUE WED THU FRI SAT
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* ``` js
|
||||
* weekdayRange("MON", "FRI")
|
||||
* true Monday trhough Friday (local timezone).
|
||||
*
|
||||
* weekdayRange("MON", "FRI", "GMT")
|
||||
* same as above, but GMT timezone.
|
||||
*
|
||||
* weekdayRange("SAT")
|
||||
* true on Saturdays local time.
|
||||
*
|
||||
* weekdayRange("SAT", "GMT")
|
||||
* true on Saturdays GMT time.
|
||||
*
|
||||
* weekdayRange("FRI", "MON")
|
||||
* true Friday through Monday (note, order does matter!).
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* @param {String} wd1 one of the weekday strings.
|
||||
* @param {String} wd2 one of the weekday strings.
|
||||
* @param {String} gmt is either the string: GMT or is left out.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function weekdayRange(wd1, wd2, gmt) {
|
||||
let useGMTzone = false;
|
||||
let wd1Index = -1;
|
||||
let wd2Index = -1;
|
||||
let wd2IsGmt = false;
|
||||
if ((0, util_1.isGMT)(gmt)) {
|
||||
useGMTzone = true;
|
||||
}
|
||||
else if ((0, util_1.isGMT)(wd2)) {
|
||||
useGMTzone = true;
|
||||
wd2IsGmt = true;
|
||||
}
|
||||
wd1Index = weekdays.indexOf(wd1);
|
||||
if (!wd2IsGmt && isWeekday(wd2)) {
|
||||
wd2Index = weekdays.indexOf(wd2);
|
||||
}
|
||||
let todaysDay = getTodaysDay(useGMTzone);
|
||||
let result;
|
||||
if (wd2Index < 0) {
|
||||
result = todaysDay === wd1Index;
|
||||
}
|
||||
else if (wd1Index <= wd2Index) {
|
||||
result = valueInRange(wd1Index, todaysDay, wd2Index);
|
||||
}
|
||||
else {
|
||||
result =
|
||||
valueInRange(wd1Index, todaysDay, 6) ||
|
||||
valueInRange(0, todaysDay, wd2Index);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.default = weekdayRange;
|
||||
function getTodaysDay(gmt) {
|
||||
return gmt ? new Date().getUTCDay() : new Date().getDay();
|
||||
}
|
||||
// start <= value <= finish
|
||||
function valueInRange(start, value, finish) {
|
||||
return start <= value && value <= finish;
|
||||
}
|
||||
function isWeekday(v) {
|
||||
return weekdays.indexOf(v) !== -1;
|
||||
}
|
||||
//# sourceMappingURL=weekdayRange.js.map
|
||||
@@ -0,0 +1,301 @@
|
||||
# resolve <sup>[![Version Badge][2]][1]</sup>
|
||||
|
||||
implements the [node `require.resolve()` algorithm](https://nodejs.org/api/modules.html#modules_all_together) such that you can `require.resolve()` on behalf of a file asynchronously and synchronously
|
||||
|
||||
[![github actions][actions-image]][actions-url]
|
||||
[![coverage][codecov-image]][codecov-url]
|
||||
[![dependency status][5]][6]
|
||||
[![dev dependency status][7]][8]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
[![npm badge][11]][1]
|
||||
|
||||
# example
|
||||
|
||||
asynchronously resolve:
|
||||
|
||||
```js
|
||||
var resolve = require('resolve/async'); // or, require('resolve')
|
||||
resolve('tap', { basedir: __dirname }, function (err, res) {
|
||||
if (err) console.error(err);
|
||||
else console.log(res);
|
||||
});
|
||||
```
|
||||
|
||||
```
|
||||
$ node example/async.js
|
||||
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
|
||||
```
|
||||
|
||||
synchronously resolve:
|
||||
|
||||
```js
|
||||
var resolve = require('resolve/sync'); // or, `require('resolve').sync
|
||||
var res = resolve('tap', { basedir: __dirname });
|
||||
console.log(res);
|
||||
```
|
||||
|
||||
```
|
||||
$ node example/sync.js
|
||||
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
|
||||
```
|
||||
|
||||
# methods
|
||||
|
||||
```js
|
||||
var resolve = require('resolve');
|
||||
var async = require('resolve/async');
|
||||
var sync = require('resolve/sync');
|
||||
```
|
||||
|
||||
For both the synchronous and asynchronous methods, errors may have any of the following `err.code` values:
|
||||
|
||||
- `MODULE_NOT_FOUND`: the given path string (`id`) could not be resolved to a module
|
||||
- `INVALID_BASEDIR`: the specified `opts.basedir` doesn't exist, or is not a directory
|
||||
- `INVALID_PACKAGE_MAIN`: a `package.json` was encountered with an invalid `main` property (eg. not a string)
|
||||
|
||||
## resolve(id, opts={}, cb)
|
||||
|
||||
Asynchronously resolve the module path string `id` into `cb(err, res [, pkg])`, where `pkg` (if defined) is the data from `package.json`.
|
||||
|
||||
options are:
|
||||
|
||||
* opts.basedir - directory to begin resolving from
|
||||
|
||||
* opts.package - `package.json` data applicable to the module being loaded
|
||||
|
||||
* opts.extensions - array of file extensions to search in order
|
||||
|
||||
* opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search
|
||||
|
||||
* opts.readFile - how to read files asynchronously
|
||||
|
||||
* opts.isFile - function to asynchronously test whether a file exists
|
||||
|
||||
* opts.isDirectory - function to asynchronously test whether a file exists and is a directory
|
||||
|
||||
* opts.realpath - function to asynchronously resolve a potential symlink to its real path
|
||||
|
||||
* `opts.readPackage(readFile, pkgfile, cb)` - function to asynchronously read and parse a package.json file
|
||||
* readFile - the passed `opts.readFile` or `fs.readFile` if not specified
|
||||
* pkgfile - path to package.json
|
||||
* cb - callback
|
||||
|
||||
* `opts.packageFilter(pkg, pkgfile, dir)` - transform the parsed package.json contents before looking at the "main" field
|
||||
* pkg - package data
|
||||
* pkgfile - path to package.json
|
||||
* dir - directory that contains package.json
|
||||
|
||||
* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package
|
||||
* pkg - package data
|
||||
* path - the path being resolved
|
||||
* relativePath - the path relative from the package.json location
|
||||
* returns - a relative path that will be joined from the package.json location
|
||||
|
||||
* opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this)
|
||||
|
||||
For advanced users, `paths` can also be a `opts.paths(request, start, opts)` function
|
||||
* request - the import specifier being resolved
|
||||
* start - lookup path
|
||||
* getNodeModulesDirs - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution
|
||||
* opts - the resolution options
|
||||
|
||||
* `opts.packageIterator(request, start, opts)` - return the list of candidate paths where the packages sources may be found (probably don't use this)
|
||||
* request - the import specifier being resolved
|
||||
* start - lookup path
|
||||
* getPackageCandidates - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution
|
||||
* opts - the resolution options
|
||||
|
||||
* opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"`
|
||||
|
||||
* opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving.
|
||||
This is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag.
|
||||
**Note:** this property is currently `true` by default but it will be changed to
|
||||
`false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*.
|
||||
|
||||
default `opts` values:
|
||||
|
||||
```js
|
||||
{
|
||||
paths: [],
|
||||
basedir: __dirname,
|
||||
extensions: ['.js'],
|
||||
includeCoreModules: true,
|
||||
readFile: fs.readFile,
|
||||
isFile: function isFile(file, cb) {
|
||||
fs.stat(file, function (err, stat) {
|
||||
if (!err) {
|
||||
return cb(null, stat.isFile() || stat.isFIFO());
|
||||
}
|
||||
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
|
||||
return cb(err);
|
||||
});
|
||||
},
|
||||
isDirectory: function isDirectory(dir, cb) {
|
||||
fs.stat(dir, function (err, stat) {
|
||||
if (!err) {
|
||||
return cb(null, stat.isDirectory());
|
||||
}
|
||||
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
|
||||
return cb(err);
|
||||
});
|
||||
},
|
||||
realpath: function realpath(file, cb) {
|
||||
var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
|
||||
realpath(file, function (realPathErr, realPath) {
|
||||
if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr);
|
||||
else cb(null, realPathErr ? file : realPath);
|
||||
});
|
||||
},
|
||||
readPackage: function defaultReadPackage(readFile, pkgfile, cb) {
|
||||
readFile(pkgfile, function (readFileErr, body) {
|
||||
if (readFileErr) cb(readFileErr);
|
||||
else {
|
||||
try {
|
||||
var pkg = JSON.parse(body);
|
||||
cb(null, pkg);
|
||||
} catch (jsonErr) {
|
||||
cb(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
moduleDirectory: 'node_modules',
|
||||
preserveSymlinks: true
|
||||
}
|
||||
```
|
||||
|
||||
## resolve.sync(id, opts)
|
||||
|
||||
Synchronously resolve the module path string `id`, returning the result and
|
||||
throwing an error when `id` can't be resolved.
|
||||
|
||||
options are:
|
||||
|
||||
* opts.basedir - directory to begin resolving from
|
||||
|
||||
* opts.extensions - array of file extensions to search in order
|
||||
|
||||
* opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search
|
||||
|
||||
* opts.readFileSync - how to read files synchronously
|
||||
|
||||
* opts.isFile - function to synchronously test whether a file exists
|
||||
|
||||
* opts.isDirectory - function to synchronously test whether a file exists and is a directory
|
||||
|
||||
* opts.realpathSync - function to synchronously resolve a potential symlink to its real path
|
||||
|
||||
* `opts.readPackageSync(readFileSync, pkgfile)` - function to synchronously read and parse a package.json file
|
||||
* readFileSync - the passed `opts.readFileSync` or `fs.readFileSync` if not specified
|
||||
* pkgfile - path to package.json
|
||||
|
||||
* `opts.packageFilter(pkg, dir)` - transform the parsed package.json contents before looking at the "main" field
|
||||
* pkg - package data
|
||||
* dir - directory that contains package.json (Note: the second argument will change to "pkgfile" in v2)
|
||||
|
||||
* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package
|
||||
* pkg - package data
|
||||
* path - the path being resolved
|
||||
* relativePath - the path relative from the package.json location
|
||||
* returns - a relative path that will be joined from the package.json location
|
||||
|
||||
* opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this)
|
||||
|
||||
For advanced users, `paths` can also be a `opts.paths(request, start, opts)` function
|
||||
* request - the import specifier being resolved
|
||||
* start - lookup path
|
||||
* getNodeModulesDirs - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution
|
||||
* opts - the resolution options
|
||||
|
||||
* `opts.packageIterator(request, start, opts)` - return the list of candidate paths where the packages sources may be found (probably don't use this)
|
||||
* request - the import specifier being resolved
|
||||
* start - lookup path
|
||||
* getPackageCandidates - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution
|
||||
* opts - the resolution options
|
||||
|
||||
* opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"`
|
||||
|
||||
* opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving.
|
||||
This is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag.
|
||||
**Note:** this property is currently `true` by default but it will be changed to
|
||||
`false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*.
|
||||
|
||||
default `opts` values:
|
||||
|
||||
```js
|
||||
{
|
||||
paths: [],
|
||||
basedir: __dirname,
|
||||
extensions: ['.js'],
|
||||
includeCoreModules: true,
|
||||
readFileSync: fs.readFileSync,
|
||||
isFile: function isFile(file) {
|
||||
try {
|
||||
var stat = fs.statSync(file);
|
||||
} catch (e) {
|
||||
if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
|
||||
throw e;
|
||||
}
|
||||
return stat.isFile() || stat.isFIFO();
|
||||
},
|
||||
isDirectory: function isDirectory(dir) {
|
||||
try {
|
||||
var stat = fs.statSync(dir);
|
||||
} catch (e) {
|
||||
if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
|
||||
throw e;
|
||||
}
|
||||
return stat.isDirectory();
|
||||
},
|
||||
realpathSync: function realpathSync(file) {
|
||||
try {
|
||||
var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;
|
||||
return realpath(file);
|
||||
} catch (realPathErr) {
|
||||
if (realPathErr.code !== 'ENOENT') {
|
||||
throw realPathErr;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
},
|
||||
readPackageSync: function defaultReadPackageSync(readFileSync, pkgfile) {
|
||||
var body = readFileSync(pkgfile);
|
||||
try {
|
||||
var pkg = JSON.parse(body);
|
||||
return pkg;
|
||||
} catch (jsonErr) {}
|
||||
},
|
||||
moduleDirectory: 'node_modules',
|
||||
preserveSymlinks: true
|
||||
}
|
||||
```
|
||||
|
||||
# install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```sh
|
||||
npm install resolve
|
||||
```
|
||||
|
||||
# license
|
||||
|
||||
MIT
|
||||
|
||||
[1]: https://npmjs.org/package/resolve
|
||||
[2]: https://versionbadg.es/browserify/resolve.svg
|
||||
[5]: https://david-dm.org/browserify/resolve.svg
|
||||
[6]: https://david-dm.org/browserify/resolve
|
||||
[7]: https://david-dm.org/browserify/resolve/dev-status.svg
|
||||
[8]: https://david-dm.org/browserify/resolve#info=devDependencies
|
||||
[11]: https://nodei.co/npm/resolve.png?downloads=true&stars=true
|
||||
[license-image]: https://img.shields.io/npm/l/resolve.svg
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: https://img.shields.io/npm/dm/resolve.svg
|
||||
[downloads-url]: https://npm-stat.com/charts.html?package=resolve
|
||||
[codecov-image]: https://codecov.io/gh/browserify/resolve/branch/main/graphs/badge.svg
|
||||
[codecov-url]: https://app.codecov.io/gh/browserify/resolve/
|
||||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/browserify/resolve
|
||||
[actions-url]: https://github.com/browserify/resolve/actions
|
||||
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [ljharb]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: npm/function.prototype.name
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,209 @@
|
||||
"use strict";
|
||||
|
||||
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var o, c, cg, cs, ce, ceg, ces, cew, cw, e, eg, es, ew, v, vg, vs, w, df, dfg, dfs;
|
||||
|
||||
o = Object.create(Object.prototype, {
|
||||
c: t("c", (c = {})),
|
||||
cgs: t.gs("c", (cg = function () {}), (cs = function () {})),
|
||||
ce: t("ce", (ce = {})),
|
||||
cegs: t.gs("ce", (ceg = function () {}), (ces = function () {})),
|
||||
cew: t("cew", (cew = {})),
|
||||
cw: t("cw", (cw = {})),
|
||||
e: t("e", (e = {})),
|
||||
egs: t.gs("e", (eg = function () {}), (es = function () {})),
|
||||
ew: t("ew", (ew = {})),
|
||||
v: t("", (v = {})),
|
||||
vgs: t.gs("", (vg = function () {}), (vs = function () {})),
|
||||
w: t("w", (w = {})),
|
||||
|
||||
df: t((df = {})),
|
||||
dfgs: t.gs((dfg = function () {}), (dfs = function () {}))
|
||||
});
|
||||
|
||||
return {
|
||||
c: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "c");
|
||||
a(d.value, c, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, true, "Configurable");
|
||||
a(d.enumerable, false, "Enumerable");
|
||||
a(d.writable, false, "Writable");
|
||||
|
||||
d = getOwnPropertyDescriptor(o, "cgs");
|
||||
a(d.value, undefined, "GS Value");
|
||||
a(d.get, cg, "GS Get");
|
||||
a(d.set, cs, "GS Set");
|
||||
a(d.configurable, true, "GS Configurable");
|
||||
a(d.enumerable, false, "GS Enumerable");
|
||||
a(d.writable, undefined, "GS Writable");
|
||||
},
|
||||
ce: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "ce");
|
||||
a(d.value, ce, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, true, "Configurable");
|
||||
a(d.enumerable, true, "Enumerable");
|
||||
a(d.writable, false, "Writable");
|
||||
|
||||
d = getOwnPropertyDescriptor(o, "cegs");
|
||||
a(d.value, undefined, "GS Value");
|
||||
a(d.get, ceg, "GS Get");
|
||||
a(d.set, ces, "GS Set");
|
||||
a(d.configurable, true, "GS Configurable");
|
||||
a(d.enumerable, true, "GS Enumerable");
|
||||
a(d.writable, undefined, "GS Writable");
|
||||
},
|
||||
cew: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "cew");
|
||||
a(d.value, cew, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, true, "Configurable");
|
||||
a(d.enumerable, true, "Enumerable");
|
||||
a(d.writable, true, "Writable");
|
||||
},
|
||||
cw: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "cw");
|
||||
a(d.value, cw, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, true, "Configurable");
|
||||
a(d.enumerable, false, "Enumerable");
|
||||
a(d.writable, true, "Writable");
|
||||
},
|
||||
e: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "e");
|
||||
a(d.value, e, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, false, "Configurable");
|
||||
a(d.enumerable, true, "Enumerable");
|
||||
a(d.writable, false, "Writable");
|
||||
|
||||
d = getOwnPropertyDescriptor(o, "egs");
|
||||
a(d.value, undefined, "GS Value");
|
||||
a(d.get, eg, "GS Get");
|
||||
a(d.set, es, "GS Set");
|
||||
a(d.configurable, false, "GS Configurable");
|
||||
a(d.enumerable, true, "GS Enumerable");
|
||||
a(d.writable, undefined, "GS Writable");
|
||||
},
|
||||
ew: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "ew");
|
||||
a(d.value, ew, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, false, "Configurable");
|
||||
a(d.enumerable, true, "Enumerable");
|
||||
a(d.writable, true, "Writable");
|
||||
},
|
||||
v: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "v");
|
||||
a(d.value, v, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, false, "Configurable");
|
||||
a(d.enumerable, false, "Enumerable");
|
||||
a(d.writable, false, "Writable");
|
||||
|
||||
d = getOwnPropertyDescriptor(o, "vgs");
|
||||
a(d.value, undefined, "GS Value");
|
||||
a(d.get, vg, "GS Get");
|
||||
a(d.set, vs, "GS Set");
|
||||
a(d.configurable, false, "GS Configurable");
|
||||
a(d.enumerable, false, "GS Enumerable");
|
||||
a(d.writable, undefined, "GS Writable");
|
||||
},
|
||||
w: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "w");
|
||||
a(d.value, w, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, false, "Configurable");
|
||||
a(d.enumerable, false, "Enumerable");
|
||||
a(d.writable, true, "Writable");
|
||||
},
|
||||
d: function (a) {
|
||||
var d = getOwnPropertyDescriptor(o, "df");
|
||||
a(d.value, df, "Value");
|
||||
a(d.get, undefined, "Get");
|
||||
a(d.set, undefined, "Set");
|
||||
a(d.configurable, true, "Configurable");
|
||||
a(d.enumerable, false, "Enumerable");
|
||||
a(d.writable, true, "Writable");
|
||||
|
||||
d = getOwnPropertyDescriptor(o, "dfgs");
|
||||
a(d.value, undefined, "GS Value");
|
||||
a(d.get, dfg, "GS Get");
|
||||
a(d.set, dfs, "GS Set");
|
||||
a(d.configurable, true, "GS Configurable");
|
||||
a(d.enumerable, false, "GS Enumerable");
|
||||
a(d.writable, undefined, "GS Writable");
|
||||
},
|
||||
Options: {
|
||||
v: function (a) {
|
||||
var x = {}, d = t(x, { foo: true });
|
||||
a.deep(
|
||||
d,
|
||||
{ configurable: true, enumerable: false, writable: true, value: x, foo: true },
|
||||
"No descriptor"
|
||||
);
|
||||
d = t("c", "foo", { marko: "elo" });
|
||||
a.deep(
|
||||
d,
|
||||
{
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: "foo",
|
||||
marko: "elo"
|
||||
},
|
||||
"Descriptor"
|
||||
);
|
||||
},
|
||||
gs: function (a) {
|
||||
var gFn = function () {}, sFn = function () {}, d;
|
||||
d = t.gs(gFn, sFn, { foo: true });
|
||||
a.deep(
|
||||
d, { configurable: true, enumerable: false, get: gFn, set: sFn, foo: true },
|
||||
"No descriptor"
|
||||
);
|
||||
d = t.gs(null, sFn, { foo: true });
|
||||
a.deep(
|
||||
d,
|
||||
{ configurable: true, enumerable: false, get: undefined, set: sFn, foo: true },
|
||||
"No descriptor: Just set"
|
||||
);
|
||||
d = t.gs(gFn, { foo: true });
|
||||
a.deep(
|
||||
d,
|
||||
{ configurable: true, enumerable: false, get: gFn, set: undefined, foo: true },
|
||||
"No descriptor: Just get"
|
||||
);
|
||||
|
||||
d = t.gs("e", gFn, sFn, { bar: true });
|
||||
a.deep(
|
||||
d, { configurable: false, enumerable: true, get: gFn, set: sFn, bar: true },
|
||||
"Descriptor"
|
||||
);
|
||||
d = t.gs("e", null, sFn, { bar: true });
|
||||
a.deep(
|
||||
d,
|
||||
{ configurable: false, enumerable: true, get: undefined, set: sFn, bar: true },
|
||||
"Descriptor: Just set"
|
||||
);
|
||||
d = t.gs("e", gFn, { bar: true });
|
||||
a.deep(
|
||||
d,
|
||||
{ configurable: false, enumerable: true, get: gFn, set: undefined, bar: true },
|
||||
"Descriptor: Just get"
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
import { OperatorFunction, TimestampProvider, Timestamp } from '../types';
|
||||
import { dateTimestampProvider } from '../scheduler/dateTimestampProvider';
|
||||
import { map } from './map';
|
||||
|
||||
/**
|
||||
* Attaches a timestamp to each item emitted by an observable indicating when it was emitted
|
||||
*
|
||||
* The `timestamp` operator maps the *source* observable stream to an object of type
|
||||
* `{value: T, timestamp: R}`. The properties are generically typed. The `value` property contains the value
|
||||
* and type of the *source* observable. The `timestamp` is generated by the schedulers `now` function. By
|
||||
* default, it uses the `asyncScheduler` which simply returns `Date.now()` (milliseconds since 1970/01/01
|
||||
* 00:00:00:000) and therefore is of type `number`.
|
||||
*
|
||||
* 
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* In this example there is a timestamp attached to the document's click events
|
||||
*
|
||||
* ```ts
|
||||
* import { fromEvent, timestamp } from 'rxjs';
|
||||
*
|
||||
* const clickWithTimestamp = fromEvent(document, 'click').pipe(
|
||||
* timestamp()
|
||||
* );
|
||||
*
|
||||
* // Emits data of type { value: PointerEvent, timestamp: number }
|
||||
* clickWithTimestamp.subscribe(data => {
|
||||
* console.log(data);
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param timestampProvider An object with a `now()` method used to get the current timestamp.
|
||||
* @return A function that returns an Observable that attaches a timestamp to
|
||||
* each item emitted by the source Observable indicating when it was emitted.
|
||||
*/
|
||||
export function timestamp<T>(timestampProvider: TimestampProvider = dateTimestampProvider): OperatorFunction<T, Timestamp<T>> {
|
||||
return map((value: T) => ({ value, timestamp: timestampProvider.now() }));
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/** @prettier */
|
||||
import { MonoTypeOperatorFunction, SchedulerLike } from '../types';
|
||||
/**
|
||||
* Re-emits all notifications from source Observable with specified scheduler.
|
||||
*
|
||||
* <span class="informal">Ensure a specific scheduler is used, from outside of an Observable.</span>
|
||||
*
|
||||
* `observeOn` is an operator that accepts a scheduler as a first parameter, which will be used to reschedule
|
||||
* notifications emitted by the source Observable. It might be useful, if you do not have control over
|
||||
* internal scheduler of a given Observable, but want to control when its values are emitted nevertheless.
|
||||
*
|
||||
* Returned Observable emits the same notifications (nexted values, complete and error events) as the source Observable,
|
||||
* but rescheduled with provided scheduler. Note that this doesn't mean that source Observables internal
|
||||
* scheduler will be replaced in any way. Original scheduler still will be used, but when the source Observable emits
|
||||
* notification, it will be immediately scheduled again - this time with scheduler passed to `observeOn`.
|
||||
* An anti-pattern would be calling `observeOn` on Observable that emits lots of values synchronously, to split
|
||||
* that emissions into asynchronous chunks. For this to happen, scheduler would have to be passed into the source
|
||||
* Observable directly (usually into the operator that creates it). `observeOn` simply delays notifications a
|
||||
* little bit more, to ensure that they are emitted at expected moments.
|
||||
*
|
||||
* As a matter of fact, `observeOn` accepts second parameter, which specifies in milliseconds with what delay notifications
|
||||
* will be emitted. The main difference between {@link delay} operator and `observeOn` is that `observeOn`
|
||||
* will delay all notifications - including error notifications - while `delay` will pass through error
|
||||
* from source Observable immediately when it is emitted. In general it is highly recommended to use `delay` operator
|
||||
* for any kind of delaying of values in the stream, while using `observeOn` to specify which scheduler should be used
|
||||
* for notification emissions in general.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* Ensure values in subscribe are called just before browser repaint
|
||||
*
|
||||
* ```ts
|
||||
* import { interval, observeOn, animationFrameScheduler } from 'rxjs';
|
||||
*
|
||||
* const someDiv = document.createElement('div');
|
||||
* someDiv.style.cssText = 'width: 200px;background: #09c';
|
||||
* document.body.appendChild(someDiv);
|
||||
* const intervals = interval(10); // Intervals are scheduled
|
||||
* // with async scheduler by default...
|
||||
* intervals.pipe(
|
||||
* observeOn(animationFrameScheduler) // ...but we will observe on animationFrame
|
||||
* ) // scheduler to ensure smooth animation.
|
||||
* .subscribe(val => {
|
||||
* someDiv.style.height = val + 'px';
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @see {@link delay}
|
||||
*
|
||||
* @param scheduler Scheduler that will be used to reschedule notifications from source Observable.
|
||||
* @param delay Number of milliseconds that states with what delay every notification should be rescheduled.
|
||||
* @return A function that returns an Observable that emits the same
|
||||
* notifications as the source Observable, but with provided scheduler.
|
||||
*/
|
||||
export declare function observeOn<T>(scheduler: SchedulerLike, delay?: number): MonoTypeOperatorFunction<T>;
|
||||
//# sourceMappingURL=observeOn.d.ts.map
|
||||
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var floor = require('./floor');
|
||||
|
||||
var msPerDay = require('../helpers/timeConstants').msPerDay;
|
||||
|
||||
// https://262.ecma-international.org/5.1/#sec-15.9.1.2
|
||||
|
||||
module.exports = function Day(t) {
|
||||
return floor(t / msPerDay);
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
/* c8 ignore start */
|
||||
// 64 KiB (same size chrome slice theirs blob into Uint8array's)
|
||||
const POOL_SIZE = 65536
|
||||
|
||||
if (!globalThis.ReadableStream) {
|
||||
// `node:stream/web` got introduced in v16.5.0 as experimental
|
||||
// and it's preferred over the polyfilled version. So we also
|
||||
// suppress the warning that gets emitted by NodeJS for using it.
|
||||
try {
|
||||
const process = require('node:process')
|
||||
const { emitWarning } = process
|
||||
try {
|
||||
process.emitWarning = () => {}
|
||||
Object.assign(globalThis, require('node:stream/web'))
|
||||
process.emitWarning = emitWarning
|
||||
} catch (error) {
|
||||
process.emitWarning = emitWarning
|
||||
throw error
|
||||
}
|
||||
} catch (error) {
|
||||
// fallback to polyfill implementation
|
||||
Object.assign(globalThis, require('web-streams-polyfill/dist/ponyfill.es2018.js'))
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Don't use node: prefix for this, require+node: is not supported until node v14.14
|
||||
// Only `import()` can use prefix in 12.20 and later
|
||||
const { Blob } = require('buffer')
|
||||
if (Blob && !Blob.prototype.stream) {
|
||||
Blob.prototype.stream = function name (params) {
|
||||
let position = 0
|
||||
const blob = this
|
||||
|
||||
return new ReadableStream({
|
||||
type: 'bytes',
|
||||
async pull (ctrl) {
|
||||
const chunk = blob.slice(position, Math.min(blob.size, position + POOL_SIZE))
|
||||
const buffer = await chunk.arrayBuffer()
|
||||
position += buffer.byteLength
|
||||
ctrl.enqueue(new Uint8Array(buffer))
|
||||
|
||||
if (position === blob.size) {
|
||||
ctrl.close()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (error) {}
|
||||
/* c8 ignore end */
|
||||
@@ -0,0 +1,27 @@
|
||||
var util = require("util");
|
||||
module.exports = CSVError;
|
||||
function CSVError(err, index, extra) {
|
||||
Error.call(this, "");
|
||||
this.err = err;
|
||||
this.line = index;
|
||||
this.extra = extra;
|
||||
this.message = "Error: " + err + ". JSON Line number: " + index + (extra ? " near: " + extra : "");
|
||||
this.name = "CSV Error";
|
||||
}
|
||||
util.inherits(CSVError, Error);
|
||||
|
||||
CSVError.prototype.toString = function() {
|
||||
return JSON.stringify([this.err, this.line, this.extra]);
|
||||
};
|
||||
|
||||
CSVError.column_mismatched = function(index, extra) {
|
||||
return new CSVError("column_mismatched", index, extra);
|
||||
};
|
||||
|
||||
CSVError.unclosed_quote = function(index, extra) {
|
||||
return new CSVError("unclosed_quote", index, extra);
|
||||
};
|
||||
|
||||
CSVError.fromArray = function(arr) {
|
||||
return new CSVError(arr[0], arr[1], arr[2]);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
var convert = require('./convert'),
|
||||
func = convert('orderBy', require('../orderBy'));
|
||||
|
||||
func.placeholder = require('./placeholder');
|
||||
module.exports = func;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"intervalProvider.js","sourceRoot":"","sources":["../../../../src/internal/scheduler/intervalProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAea,QAAA,gBAAgB,GAAqB;IAGhD,WAAW,EAAX,UAAY,OAAmB,EAAE,OAAgB;QAAE,cAAO;aAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;YAAP,6BAAO;;QAChD,IAAA,QAAQ,GAAK,wBAAgB,SAArB,CAAsB;QACtC,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,EAAE;YACzB,OAAO,QAAQ,CAAC,WAAW,OAApB,QAAQ,iBAAa,OAAO,EAAE,OAAO,UAAK,IAAI,IAAE;SACxD;QACD,OAAO,WAAW,8BAAC,OAAO,EAAE,OAAO,UAAK,IAAI,IAAE;IAChD,CAAC;IACD,aAAa,EAAb,UAAc,MAAM;QACV,IAAA,QAAQ,GAAK,wBAAgB,SAArB,CAAsB;QACtC,OAAO,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,aAAa,KAAI,aAAa,CAAC,CAAC,MAAa,CAAC,CAAC;IACnE,CAAC;IACD,QAAQ,EAAE,SAAS;CACpB,CAAC"}
|
||||
@@ -0,0 +1,966 @@
|
||||
/* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */
|
||||
/* vim: set ts=2: */
|
||||
/*jshint -W041 */
|
||||
var SSF = ({});
|
||||
var make_ssf = function make_ssf(SSF){
|
||||
SSF.version = '0.11.2';
|
||||
function _strrev(x) { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; }
|
||||
function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; }
|
||||
function pad0(v,d){var t=""+v; return t.length>=d?t:fill('0',d-t.length)+t;}
|
||||
function pad_(v,d){var t=""+v;return t.length>=d?t:fill(' ',d-t.length)+t;}
|
||||
function rpad_(v,d){var t=""+v; return t.length>=d?t:t+fill(' ',d-t.length);}
|
||||
function pad0r1(v,d){var t=""+Math.round(v); return t.length>=d?t:fill('0',d-t.length)+t;}
|
||||
function pad0r2(v,d){var t=""+v; return t.length>=d?t:fill('0',d-t.length)+t;}
|
||||
var p2_32 = Math.pow(2,32);
|
||||
function pad0r(v,d){if(v>p2_32||v<-p2_32) return pad0r1(v,d); var i = Math.round(v); return pad0r2(i,d); }
|
||||
function isgeneral(s, i) { i = i || 0; return s.length >= 7 + i && (s.charCodeAt(i)|32) === 103 && (s.charCodeAt(i+1)|32) === 101 && (s.charCodeAt(i+2)|32) === 110 && (s.charCodeAt(i+3)|32) === 101 && (s.charCodeAt(i+4)|32) === 114 && (s.charCodeAt(i+5)|32) === 97 && (s.charCodeAt(i+6)|32) === 108; }
|
||||
var days = [
|
||||
['Sun', 'Sunday'],
|
||||
['Mon', 'Monday'],
|
||||
['Tue', 'Tuesday'],
|
||||
['Wed', 'Wednesday'],
|
||||
['Thu', 'Thursday'],
|
||||
['Fri', 'Friday'],
|
||||
['Sat', 'Saturday']
|
||||
];
|
||||
var months = [
|
||||
['J', 'Jan', 'January'],
|
||||
['F', 'Feb', 'February'],
|
||||
['M', 'Mar', 'March'],
|
||||
['A', 'Apr', 'April'],
|
||||
['M', 'May', 'May'],
|
||||
['J', 'Jun', 'June'],
|
||||
['J', 'Jul', 'July'],
|
||||
['A', 'Aug', 'August'],
|
||||
['S', 'Sep', 'September'],
|
||||
['O', 'Oct', 'October'],
|
||||
['N', 'Nov', 'November'],
|
||||
['D', 'Dec', 'December']
|
||||
];
|
||||
function init_table(t) {
|
||||
t[0]= 'General';
|
||||
t[1]= '0';
|
||||
t[2]= '0.00';
|
||||
t[3]= '#,##0';
|
||||
t[4]= '#,##0.00';
|
||||
t[9]= '0%';
|
||||
t[10]= '0.00%';
|
||||
t[11]= '0.00E+00';
|
||||
t[12]= '# ?/?';
|
||||
t[13]= '# ??/??';
|
||||
t[14]= 'm/d/yy';
|
||||
t[15]= 'd-mmm-yy';
|
||||
t[16]= 'd-mmm';
|
||||
t[17]= 'mmm-yy';
|
||||
t[18]= 'h:mm AM/PM';
|
||||
t[19]= 'h:mm:ss AM/PM';
|
||||
t[20]= 'h:mm';
|
||||
t[21]= 'h:mm:ss';
|
||||
t[22]= 'm/d/yy h:mm';
|
||||
t[37]= '#,##0 ;(#,##0)';
|
||||
t[38]= '#,##0 ;[Red](#,##0)';
|
||||
t[39]= '#,##0.00;(#,##0.00)';
|
||||
t[40]= '#,##0.00;[Red](#,##0.00)';
|
||||
t[45]= 'mm:ss';
|
||||
t[46]= '[h]:mm:ss';
|
||||
t[47]= 'mmss.0';
|
||||
t[48]= '##0.0E+0';
|
||||
t[49]= '@';
|
||||
t[56]= '"上午/下午 "hh"時"mm"分"ss"秒 "';
|
||||
}
|
||||
|
||||
var table_fmt = {};
|
||||
init_table(table_fmt);
|
||||
/* Defaults determined by systematically testing in Excel 2019 */
|
||||
|
||||
/* These formats appear to default to other formats in the table */
|
||||
var default_map = [];
|
||||
var defi = 0;
|
||||
|
||||
// 5 -> 37 ... 8 -> 40
|
||||
for(defi = 5; defi <= 8; ++defi) default_map[defi] = 32 + defi;
|
||||
|
||||
// 23 -> 0 ... 26 -> 0
|
||||
for(defi = 23; defi <= 26; ++defi) default_map[defi] = 0;
|
||||
|
||||
// 27 -> 14 ... 31 -> 14
|
||||
for(defi = 27; defi <= 31; ++defi) default_map[defi] = 14;
|
||||
// 50 -> 14 ... 58 -> 14
|
||||
for(defi = 50; defi <= 58; ++defi) default_map[defi] = 14;
|
||||
|
||||
// 59 -> 1 ... 62 -> 4
|
||||
for(defi = 59; defi <= 62; ++defi) default_map[defi] = defi - 58;
|
||||
// 67 -> 9 ... 68 -> 10
|
||||
for(defi = 67; defi <= 68; ++defi) default_map[defi] = defi - 58;
|
||||
// 72 -> 14 ... 75 -> 17
|
||||
for(defi = 72; defi <= 75; ++defi) default_map[defi] = defi - 58;
|
||||
|
||||
// 69 -> 12 ... 71 -> 14
|
||||
for(defi = 67; defi <= 68; ++defi) default_map[defi] = defi - 57;
|
||||
|
||||
// 76 -> 20 ... 78 -> 22
|
||||
for(defi = 76; defi <= 78; ++defi) default_map[defi] = defi - 56;
|
||||
|
||||
// 79 -> 45 ... 81 -> 47
|
||||
for(defi = 79; defi <= 81; ++defi) default_map[defi] = defi - 34;
|
||||
|
||||
// 82 -> 0 ... 65536 -> 0 (omitted)
|
||||
|
||||
/* These formats technically refer to Accounting formats with no equivalent */
|
||||
var default_str = [];
|
||||
|
||||
// 5 -- Currency, 0 decimal, black negative
|
||||
default_str[5] = default_str[63] = '"$"#,##0_);\\("$"#,##0\\)';
|
||||
// 6 -- Currency, 0 decimal, red negative
|
||||
default_str[6] = default_str[64] = '"$"#,##0_);[Red]\\("$"#,##0\\)';
|
||||
// 7 -- Currency, 2 decimal, black negative
|
||||
default_str[7] = default_str[65] = '"$"#,##0.00_);\\("$"#,##0.00\\)';
|
||||
// 8 -- Currency, 2 decimal, red negative
|
||||
default_str[8] = default_str[66] = '"$"#,##0.00_);[Red]\\("$"#,##0.00\\)';
|
||||
|
||||
// 41 -- Accounting, 0 decimal, No Symbol
|
||||
default_str[41] = '_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)';
|
||||
// 42 -- Accounting, 0 decimal, $ Symbol
|
||||
default_str[42] = '_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"_);_(@_)';
|
||||
// 43 -- Accounting, 2 decimal, No Symbol
|
||||
default_str[43] = '_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)';
|
||||
// 44 -- Accounting, 2 decimal, $ Symbol
|
||||
default_str[44] = '_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)';
|
||||
function frac(x, D, mixed) {
|
||||
var sgn = x < 0 ? -1 : 1;
|
||||
var B = x * sgn;
|
||||
var P_2 = 0, P_1 = 1, P = 0;
|
||||
var Q_2 = 1, Q_1 = 0, Q = 0;
|
||||
var A = Math.floor(B);
|
||||
while(Q_1 < D) {
|
||||
A = Math.floor(B);
|
||||
P = A * P_1 + P_2;
|
||||
Q = A * Q_1 + Q_2;
|
||||
if((B - A) < 0.00000005) break;
|
||||
B = 1 / (B - A);
|
||||
P_2 = P_1; P_1 = P;
|
||||
Q_2 = Q_1; Q_1 = Q;
|
||||
}
|
||||
if(Q > D) { if(Q_1 > D) { Q = Q_2; P = P_2; } else { Q = Q_1; P = P_1; } }
|
||||
if(!mixed) return [0, sgn * P, Q];
|
||||
var q = Math.floor(sgn * P/Q);
|
||||
return [q, sgn*P - q*Q, Q];
|
||||
}
|
||||
function parse_date_code(v,opts,b2) {
|
||||
if(v > 2958465 || v < 0) return null;
|
||||
var date = (v|0), time = Math.floor(86400 * (v - date)), dow=0;
|
||||
var dout=[];
|
||||
var out={D:date, T:time, u:86400*(v-date)-time,y:0,m:0,d:0,H:0,M:0,S:0,q:0};
|
||||
if(Math.abs(out.u) < 1e-6) out.u = 0;
|
||||
if(opts && opts.date1904) date += 1462;
|
||||
if(out.u > 0.9999) {
|
||||
out.u = 0;
|
||||
if(++time == 86400) { out.T = time = 0; ++date; ++out.D; }
|
||||
}
|
||||
if(date === 60) {dout = b2 ? [1317,10,29] : [1900,2,29]; dow=3;}
|
||||
else if(date === 0) {dout = b2 ? [1317,8,29] : [1900,1,0]; dow=6;}
|
||||
else {
|
||||
if(date > 60) --date;
|
||||
/* 1 = Jan 1 1900 in Gregorian */
|
||||
var d = new Date(1900, 0, 1);
|
||||
d.setDate(d.getDate() + date - 1);
|
||||
dout = [d.getFullYear(), d.getMonth()+1,d.getDate()];
|
||||
dow = d.getDay();
|
||||
if(date < 60) dow = (dow + 6) % 7;
|
||||
if(b2) dow = fix_hijri(d, dout);
|
||||
}
|
||||
out.y = dout[0]; out.m = dout[1]; out.d = dout[2];
|
||||
out.S = time % 60; time = Math.floor(time / 60);
|
||||
out.M = time % 60; time = Math.floor(time / 60);
|
||||
out.H = time;
|
||||
out.q = dow;
|
||||
return out;
|
||||
}
|
||||
SSF.parse_date_code = parse_date_code;
|
||||
var basedate = new Date(1899, 11, 31, 0, 0, 0);
|
||||
var dnthresh = basedate.getTime();
|
||||
var base1904 = new Date(1900, 2, 1, 0, 0, 0);
|
||||
function datenum_local(v, date1904) {
|
||||
var epoch = v.getTime();
|
||||
if(date1904) epoch -= 1461*24*60*60*1000;
|
||||
else if(v >= base1904) epoch += 24*60*60*1000;
|
||||
return (epoch - (dnthresh + (v.getTimezoneOffset() - basedate.getTimezoneOffset()) * 60000)) / (24 * 60 * 60 * 1000);
|
||||
}
|
||||
/* The longest 32-bit integer text is "-4294967296", exactly 11 chars */
|
||||
function general_fmt_int(v) { return v.toString(10); }
|
||||
SSF._general_int = general_fmt_int;
|
||||
|
||||
/* ECMA-376 18.8.30 numFmt*/
|
||||
/* Note: `toPrecision` uses standard form when prec > E and E >= -6 */
|
||||
var general_fmt_num = (function make_general_fmt_num() {
|
||||
var trailing_zeroes_and_decimal = /(?:\.0*|(\.\d*[1-9])0+)$/;
|
||||
function strip_decimal(o) {
|
||||
return (o.indexOf(".") == -1) ? o : o.replace(trailing_zeroes_and_decimal, "$1");
|
||||
}
|
||||
|
||||
/* General Exponential always shows 2 digits exp and trims the mantissa */
|
||||
var mantissa_zeroes_and_decimal = /(?:\.0*|(\.\d*[1-9])0+)[Ee]/;
|
||||
var exp_with_single_digit = /(E[+-])(\d)$/;
|
||||
function normalize_exp(o) {
|
||||
if(o.indexOf("E") == -1) return o;
|
||||
return o.replace(mantissa_zeroes_and_decimal,"$1E").replace(exp_with_single_digit,"$10$2");
|
||||
}
|
||||
|
||||
/* exponent >= -9 and <= 9 */
|
||||
function small_exp(v) {
|
||||
var w = (v<0?12:11);
|
||||
var o = strip_decimal(v.toFixed(12)); if(o.length <= w) return o;
|
||||
o = v.toPrecision(10); if(o.length <= w) return o;
|
||||
return v.toExponential(5);
|
||||
}
|
||||
|
||||
/* exponent >= 11 or <= -10 likely exponential */
|
||||
function large_exp(v) {
|
||||
var o = strip_decimal(v.toFixed(11));
|
||||
return (o.length > (v<0?12:11) || o === "0" || o === "-0") ? v.toPrecision(6) : o;
|
||||
}
|
||||
|
||||
function general_fmt_num_base(v) {
|
||||
var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o;
|
||||
|
||||
if(V >= -4 && V <= -1) o = v.toPrecision(10+V);
|
||||
else if(Math.abs(V) <= 9) o = small_exp(v);
|
||||
else if(V === 10) o = v.toFixed(10).substr(0,12);
|
||||
else o = large_exp(v);
|
||||
|
||||
return strip_decimal(normalize_exp(o.toUpperCase()));
|
||||
}
|
||||
|
||||
return general_fmt_num_base;
|
||||
})();
|
||||
SSF._general_num = general_fmt_num;
|
||||
|
||||
/*
|
||||
"General" rules:
|
||||
- text is passed through ("@")
|
||||
- booleans are rendered as TRUE/FALSE
|
||||
- "up to 11 characters" displayed for numbers
|
||||
- Default date format (code 14) used for Dates
|
||||
|
||||
TODO: technically the display depends on the width of the cell
|
||||
*/
|
||||
function general_fmt(v, opts) {
|
||||
switch(typeof v) {
|
||||
case 'string': return v;
|
||||
case 'boolean': return v ? "TRUE" : "FALSE";
|
||||
case 'number': return (v|0) === v ? v.toString(10) : general_fmt_num(v);
|
||||
case 'undefined': return "";
|
||||
case 'object':
|
||||
if(v == null) return "";
|
||||
if(v instanceof Date) return format(14, datenum_local(v, opts && opts.date1904), opts);
|
||||
}
|
||||
throw new Error("unsupported value in General format: " + v);
|
||||
}
|
||||
SSF._general = general_fmt;
|
||||
function fix_hijri(date, o) {
|
||||
/* TODO: properly adjust y/m/d and */
|
||||
o[0] -= 581;
|
||||
var dow = date.getDay();
|
||||
if(date < 60) dow = (dow + 6) % 7;
|
||||
return dow;
|
||||
}
|
||||
var THAI_DIGITS = "\u0E50\u0E51\u0E52\u0E53\u0E54\u0E55\u0E56\u0E57\u0E58\u0E59".split("");
|
||||
/*jshint -W086 */
|
||||
function write_date(type, fmt, val, ss0) {
|
||||
var o="", ss=0, tt=0, y = val.y, out, outl = 0;
|
||||
switch(type) {
|
||||
case 98: /* 'b' buddhist year */
|
||||
y = val.y + 543;
|
||||
/* falls through */
|
||||
case 121: /* 'y' year */
|
||||
switch(fmt.length) {
|
||||
case 1: case 2: out = y % 100; outl = 2; break;
|
||||
default: out = y % 10000; outl = 4; break;
|
||||
} break;
|
||||
case 109: /* 'm' month */
|
||||
switch(fmt.length) {
|
||||
case 1: case 2: out = val.m; outl = fmt.length; break;
|
||||
case 3: return months[val.m-1][1];
|
||||
case 5: return months[val.m-1][0];
|
||||
default: return months[val.m-1][2];
|
||||
} break;
|
||||
case 100: /* 'd' day */
|
||||
switch(fmt.length) {
|
||||
case 1: case 2: out = val.d; outl = fmt.length; break;
|
||||
case 3: return days[val.q][0];
|
||||
default: return days[val.q][1];
|
||||
} break;
|
||||
case 104: /* 'h' 12-hour */
|
||||
switch(fmt.length) {
|
||||
case 1: case 2: out = 1+(val.H+11)%12; outl = fmt.length; break;
|
||||
default: throw 'bad hour format: ' + fmt;
|
||||
} break;
|
||||
case 72: /* 'H' 24-hour */
|
||||
switch(fmt.length) {
|
||||
case 1: case 2: out = val.H; outl = fmt.length; break;
|
||||
default: throw 'bad hour format: ' + fmt;
|
||||
} break;
|
||||
case 77: /* 'M' minutes */
|
||||
switch(fmt.length) {
|
||||
case 1: case 2: out = val.M; outl = fmt.length; break;
|
||||
default: throw 'bad minute format: ' + fmt;
|
||||
} break;
|
||||
case 115: /* 's' seconds */
|
||||
if(fmt != 's' && fmt != 'ss' && fmt != '.0' && fmt != '.00' && fmt != '.000') throw 'bad second format: ' + fmt;
|
||||
if(val.u === 0 && (fmt == "s" || fmt == "ss")) return pad0(val.S, fmt.length);
|
||||
if(ss0 >= 2) tt = ss0 === 3 ? 1000 : 100;
|
||||
else tt = ss0 === 1 ? 10 : 1;
|
||||
ss = Math.round((tt)*(val.S + val.u));
|
||||
if(ss >= 60*tt) ss = 0;
|
||||
if(fmt === 's') return ss === 0 ? "0" : ""+ss/tt;
|
||||
o = pad0(ss,2 + ss0);
|
||||
if(fmt === 'ss') return o.substr(0,2);
|
||||
return "." + o.substr(2,fmt.length-1);
|
||||
case 90: /* 'Z' absolute time */
|
||||
switch(fmt) {
|
||||
case '[h]': case '[hh]': out = val.D*24+val.H; break;
|
||||
case '[m]': case '[mm]': out = (val.D*24+val.H)*60+val.M; break;
|
||||
case '[s]': case '[ss]': out = ((val.D*24+val.H)*60+val.M)*60+Math.round(val.S+val.u); break;
|
||||
default: throw 'bad abstime format: ' + fmt;
|
||||
} outl = fmt.length === 3 ? 1 : 2; break;
|
||||
case 101: /* 'e' era */
|
||||
out = y; outl = 1; break;
|
||||
}
|
||||
var outstr = outl > 0 ? pad0(out, outl) : "";
|
||||
return outstr;
|
||||
}
|
||||
/*jshint +W086 */
|
||||
function commaify(s) {
|
||||
var w = 3;
|
||||
if(s.length <= w) return s;
|
||||
var j = (s.length % w), o = s.substr(0,j);
|
||||
for(; j!=s.length; j+=w) o+=(o.length > 0 ? "," : "") + s.substr(j,w);
|
||||
return o;
|
||||
}
|
||||
var write_num = (function make_write_num(){
|
||||
var pct1 = /%/g;
|
||||
function write_num_pct(type, fmt, val){
|
||||
var sfmt = fmt.replace(pct1,""), mul = fmt.length - sfmt.length;
|
||||
return write_num(type, sfmt, val * Math.pow(10,2*mul)) + fill("%",mul);
|
||||
}
|
||||
function write_num_cm(type, fmt, val){
|
||||
var idx = fmt.length - 1;
|
||||
while(fmt.charCodeAt(idx-1) === 44) --idx;
|
||||
return write_num(type, fmt.substr(0,idx), val / Math.pow(10,3*(fmt.length-idx)));
|
||||
}
|
||||
function write_num_exp(fmt, val){
|
||||
var o;
|
||||
var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1;
|
||||
if(fmt.match(/^#+0.0E\+0$/)) {
|
||||
if(val == 0) return "0.0E+0";
|
||||
else if(val < 0) return "-" + write_num_exp(fmt, -val);
|
||||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E');
|
||||
var ee = Math.floor(Math.log(val)*Math.LOG10E)%period;
|
||||
if(ee < 0) ee += period;
|
||||
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period);
|
||||
if(o.indexOf("e") === -1) {
|
||||
var fakee = Math.floor(Math.log(val)*Math.LOG10E);
|
||||
if(o.indexOf(".") === -1) o = o.charAt(0) + "." + o.substr(1) + "E+" + (fakee - o.length+ee);
|
||||
else o += "E+" + (fakee - ee);
|
||||
while(o.substr(0,2) === "0.") {
|
||||
o = o.charAt(0) + o.substr(2,period) + "." + o.substr(2+period);
|
||||
o = o.replace(/^0+([1-9])/,"$1").replace(/^0+\./,"0.");
|
||||
}
|
||||
o = o.replace(/\+-/,"-");
|
||||
}
|
||||
o = o.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/,function($$,$1,$2,$3) { return $1 + $2 + $3.substr(0,(period+ee)%period) + "." + $3.substr(ee) + "E"; });
|
||||
} else o = val.toExponential(idx);
|
||||
if(fmt.match(/E\+00$/) && o.match(/e[+-]\d$/)) o = o.substr(0,o.length-1) + "0" + o.charAt(o.length-1);
|
||||
if(fmt.match(/E\-/) && o.match(/e\+/)) o = o.replace(/e\+/,"e");
|
||||
return o.replace("e","E");
|
||||
}
|
||||
var frac1 = /# (\?+)( ?)\/( ?)(\d+)/;
|
||||
function write_num_f1(r, aval, sign) {
|
||||
var den = parseInt(r[4],10), rr = Math.round(aval * den), base = Math.floor(rr/den);
|
||||
var myn = (rr - base*den), myd = den;
|
||||
return sign + (base === 0 ? "" : ""+base) + " " + (myn === 0 ? fill(" ", r[1].length + 1 + r[4].length) : pad_(myn,r[1].length) + r[2] + "/" + r[3] + pad0(myd,r[4].length));
|
||||
}
|
||||
function write_num_f2(r, aval, sign) {
|
||||
return sign + (aval === 0 ? "" : ""+aval) + fill(" ", r[1].length + 2 + r[4].length);
|
||||
}
|
||||
var dec1 = /^#*0*\.([0#]+)/;
|
||||
var closeparen = /\).*[0#]/;
|
||||
var phone = /\(###\) ###\\?-####/;
|
||||
function hashq(str) {
|
||||
var o = "", cc;
|
||||
for(var i = 0; i != str.length; ++i) switch((cc=str.charCodeAt(i))) {
|
||||
case 35: break;
|
||||
case 63: o+= " "; break;
|
||||
case 48: o+= "0"; break;
|
||||
default: o+= String.fromCharCode(cc);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function rnd(val, d) { var dd = Math.pow(10,d); return ""+(Math.round(val * dd)/dd); }
|
||||
function dec(val, d) {
|
||||
var _frac = val - Math.floor(val), dd = Math.pow(10,d);
|
||||
if (d < ('' + Math.round(_frac * dd)).length) return 0;
|
||||
return Math.round(_frac * dd);
|
||||
}
|
||||
function carry(val, d) {
|
||||
if (d < ('' + Math.round((val-Math.floor(val))*Math.pow(10,d))).length) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
function flr(val) {
|
||||
if(val < 2147483647 && val > -2147483648) return ""+(val >= 0 ? (val|0) : (val-1|0));
|
||||
return ""+Math.floor(val);
|
||||
}
|
||||
function write_num_flt(type, fmt, val) {
|
||||
if(type.charCodeAt(0) === 40 && !fmt.match(closeparen)) {
|
||||
var ffmt = fmt.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,"");
|
||||
if(val >= 0) return write_num_flt('n', ffmt, val);
|
||||
return '(' + write_num_flt('n', ffmt, -val) + ')';
|
||||
}
|
||||
if(fmt.charCodeAt(fmt.length - 1) === 44) return write_num_cm(type, fmt, val);
|
||||
if(fmt.indexOf('%') !== -1) return write_num_pct(type, fmt, val);
|
||||
if(fmt.indexOf('E') !== -1) return write_num_exp(fmt, val);
|
||||
if(fmt.charCodeAt(0) === 36) return "$"+write_num_flt(type,fmt.substr(fmt.charAt(1)==' '?2:1),val);
|
||||
var o;
|
||||
var r, ri, ff, aval = Math.abs(val), sign = val < 0 ? "-" : "";
|
||||
if(fmt.match(/^00+$/)) return sign + pad0r(aval,fmt.length);
|
||||
if(fmt.match(/^[#?]+$/)) {
|
||||
o = pad0r(val,0); if(o === "0") o = "";
|
||||
return o.length > fmt.length ? o : hashq(fmt.substr(0,fmt.length-o.length)) + o;
|
||||
}
|
||||
if((r = fmt.match(frac1))) return write_num_f1(r, aval, sign);
|
||||
if(fmt.match(/^#+0+$/)) return sign + pad0r(aval,fmt.length - fmt.indexOf("0"));
|
||||
if((r = fmt.match(dec1))) {
|
||||
o = rnd(val, r[1].length).replace(/^([^\.]+)$/,"$1."+hashq(r[1])).replace(/\.$/,"."+hashq(r[1])).replace(/\.(\d*)$/,function($$, $1) { return "." + $1 + fill("0", hashq(r[1]).length-$1.length); });
|
||||
return fmt.indexOf("0.") !== -1 ? o : o.replace(/^0\./,".");
|
||||
}
|
||||
fmt = fmt.replace(/^#+([0.])/, "$1");
|
||||
if((r = fmt.match(/^(0*)\.(#*)$/))) {
|
||||
return sign + rnd(aval, r[2].length).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^(-?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":".");
|
||||
}
|
||||
if((r = fmt.match(/^#{1,3},##0(\.?)$/))) return sign + commaify(pad0r(aval,0));
|
||||
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) {
|
||||
return val < 0 ? "-" + write_num_flt(type, fmt, -val) : commaify(""+(Math.floor(val) + carry(val, r[1].length))) + "." + pad0(dec(val, r[1].length),r[1].length);
|
||||
}
|
||||
if((r = fmt.match(/^#,#*,#0/))) return write_num_flt(type,fmt.replace(/^#,#*,/,""),val);
|
||||
if((r = fmt.match(/^([0#]+)(\\?-([0#]+))+$/))) {
|
||||
o = _strrev(write_num_flt(type, fmt.replace(/[\\-]/g,""), val));
|
||||
ri = 0;
|
||||
return _strrev(_strrev(fmt.replace(/\\/g,"")).replace(/[0#]/g,function(x){return ri<o.length?o.charAt(ri++):x==='0'?'0':"";}));
|
||||
}
|
||||
if(fmt.match(phone)) {
|
||||
o = write_num_flt(type, "##########", val);
|
||||
return "(" + o.substr(0,3) + ") " + o.substr(3, 3) + "-" + o.substr(6);
|
||||
}
|
||||
var oa = "";
|
||||
if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))) {
|
||||
ri = Math.min(r[4].length,7);
|
||||
ff = frac(aval, Math.pow(10,ri)-1, false);
|
||||
o = "" + sign;
|
||||
oa = write_num("n", r[1], ff[1]);
|
||||
if(oa.charAt(oa.length-1) == " ") oa = oa.substr(0,oa.length-1) + "0";
|
||||
o += oa + r[2] + "/" + r[3];
|
||||
oa = rpad_(ff[2],ri);
|
||||
if(oa.length < r[4].length) oa = hashq(r[4].substr(r[4].length-oa.length)) + oa;
|
||||
o += oa;
|
||||
return o;
|
||||
}
|
||||
if((r = fmt.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/))) {
|
||||
ri = Math.min(Math.max(r[1].length, r[4].length),7);
|
||||
ff = frac(aval, Math.pow(10,ri)-1, true);
|
||||
return sign + (ff[0]||(ff[1] ? "" : "0")) + " " + (ff[1] ? pad_(ff[1],ri) + r[2] + "/" + r[3] + rpad_(ff[2],ri): fill(" ", 2*ri+1 + r[2].length + r[3].length));
|
||||
}
|
||||
if((r = fmt.match(/^[#0?]+$/))) {
|
||||
o = pad0r(val, 0);
|
||||
if(fmt.length <= o.length) return o;
|
||||
return hashq(fmt.substr(0,fmt.length-o.length)) + o;
|
||||
}
|
||||
if((r = fmt.match(/^([#0?]+)\.([#0]+)$/))) {
|
||||
o = "" + val.toFixed(Math.min(r[2].length,10)).replace(/([^0])0+$/,"$1");
|
||||
ri = o.indexOf(".");
|
||||
var lres = fmt.indexOf(".") - ri, rres = fmt.length - o.length - lres;
|
||||
return hashq(fmt.substr(0,lres) + o + fmt.substr(fmt.length-rres));
|
||||
}
|
||||
if((r = fmt.match(/^00,000\.([#0]*0)$/))) {
|
||||
ri = dec(val, r[1].length);
|
||||
return val < 0 ? "-" + write_num_flt(type, fmt, -val) : commaify(flr(val)).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function($$) { return "00," + ($$.length < 3 ? pad0(0,3-$$.length) : "") + $$; }) + "." + pad0(ri,r[1].length);
|
||||
}
|
||||
switch(fmt) {
|
||||
case "###,##0.00": return write_num_flt(type, "#,##0.00", val);
|
||||
case "###,###":
|
||||
case "##,###":
|
||||
case "#,###": var x = commaify(pad0r(aval,0)); return x !== "0" ? sign + x : "";
|
||||
case "###,###.00": return write_num_flt(type, "###,##0.00",val).replace(/^0\./,".");
|
||||
case "#,###.00": return write_num_flt(type, "#,##0.00",val).replace(/^0\./,".");
|
||||
default:
|
||||
}
|
||||
throw new Error("unsupported format |" + fmt + "|");
|
||||
}
|
||||
function write_num_cm2(type, fmt, val){
|
||||
var idx = fmt.length - 1;
|
||||
while(fmt.charCodeAt(idx-1) === 44) --idx;
|
||||
return write_num(type, fmt.substr(0,idx), val / Math.pow(10,3*(fmt.length-idx)));
|
||||
}
|
||||
function write_num_pct2(type, fmt, val){
|
||||
var sfmt = fmt.replace(pct1,""), mul = fmt.length - sfmt.length;
|
||||
return write_num(type, sfmt, val * Math.pow(10,2*mul)) + fill("%",mul);
|
||||
}
|
||||
function write_num_exp2(fmt, val){
|
||||
var o;
|
||||
var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1;
|
||||
if(fmt.match(/^#+0.0E\+0$/)) {
|
||||
if(val == 0) return "0.0E+0";
|
||||
else if(val < 0) return "-" + write_num_exp2(fmt, -val);
|
||||
var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E');
|
||||
var ee = Math.floor(Math.log(val)*Math.LOG10E)%period;
|
||||
if(ee < 0) ee += period;
|
||||
o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period);
|
||||
if(!o.match(/[Ee]/)) {
|
||||
var fakee = Math.floor(Math.log(val)*Math.LOG10E);
|
||||
if(o.indexOf(".") === -1) o = o.charAt(0) + "." + o.substr(1) + "E+" + (fakee - o.length+ee);
|
||||
else o += "E+" + (fakee - ee);
|
||||
o = o.replace(/\+-/,"-");
|
||||
}
|
||||
o = o.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/,function($$,$1,$2,$3) { return $1 + $2 + $3.substr(0,(period+ee)%period) + "." + $3.substr(ee) + "E"; });
|
||||
} else o = val.toExponential(idx);
|
||||
if(fmt.match(/E\+00$/) && o.match(/e[+-]\d$/)) o = o.substr(0,o.length-1) + "0" + o.charAt(o.length-1);
|
||||
if(fmt.match(/E\-/) && o.match(/e\+/)) o = o.replace(/e\+/,"e");
|
||||
return o.replace("e","E");
|
||||
}
|
||||
function write_num_int(type, fmt, val) {
|
||||
if(type.charCodeAt(0) === 40 && !fmt.match(closeparen)) {
|
||||
var ffmt = fmt.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,"");
|
||||
if(val >= 0) return write_num_int('n', ffmt, val);
|
||||
return '(' + write_num_int('n', ffmt, -val) + ')';
|
||||
}
|
||||
if(fmt.charCodeAt(fmt.length - 1) === 44) return write_num_cm2(type, fmt, val);
|
||||
if(fmt.indexOf('%') !== -1) return write_num_pct2(type, fmt, val);
|
||||
if(fmt.indexOf('E') !== -1) return write_num_exp2(fmt, val);
|
||||
if(fmt.charCodeAt(0) === 36) return "$"+write_num_int(type,fmt.substr(fmt.charAt(1)==' '?2:1),val);
|
||||
var o;
|
||||
var r, ri, ff, aval = Math.abs(val), sign = val < 0 ? "-" : "";
|
||||
if(fmt.match(/^00+$/)) return sign + pad0(aval,fmt.length);
|
||||
if(fmt.match(/^[#?]+$/)) {
|
||||
o = (""+val); if(val === 0) o = "";
|
||||
return o.length > fmt.length ? o : hashq(fmt.substr(0,fmt.length-o.length)) + o;
|
||||
}
|
||||
if((r = fmt.match(frac1))) return write_num_f2(r, aval, sign);
|
||||
if(fmt.match(/^#+0+$/)) return sign + pad0(aval,fmt.length - fmt.indexOf("0"));
|
||||
if((r = fmt.match(dec1))) {
|
||||
o = (""+val).replace(/^([^\.]+)$/,"$1."+hashq(r[1])).replace(/\.$/,"."+hashq(r[1]));
|
||||
o = o.replace(/\.(\d*)$/,function($$, $1) {
|
||||
return "." + $1 + fill("0", hashq(r[1]).length-$1.length); });
|
||||
return fmt.indexOf("0.") !== -1 ? o : o.replace(/^0\./,".");
|
||||
}
|
||||
fmt = fmt.replace(/^#+([0.])/, "$1");
|
||||
if((r = fmt.match(/^(0*)\.(#*)$/))) {
|
||||
return sign + (""+aval).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^(-?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":".");
|
||||
}
|
||||
if((r = fmt.match(/^#{1,3},##0(\.?)$/))) return sign + commaify((""+aval));
|
||||
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) {
|
||||
return val < 0 ? "-" + write_num_int(type, fmt, -val) : commaify((""+val)) + "." + fill('0',r[1].length);
|
||||
}
|
||||
if((r = fmt.match(/^#,#*,#0/))) return write_num_int(type,fmt.replace(/^#,#*,/,""),val);
|
||||
if((r = fmt.match(/^([0#]+)(\\?-([0#]+))+$/))) {
|
||||
o = _strrev(write_num_int(type, fmt.replace(/[\\-]/g,""), val));
|
||||
ri = 0;
|
||||
return _strrev(_strrev(fmt.replace(/\\/g,"")).replace(/[0#]/g,function(x){return ri<o.length?o.charAt(ri++):x==='0'?'0':"";}));
|
||||
}
|
||||
if(fmt.match(phone)) {
|
||||
o = write_num_int(type, "##########", val);
|
||||
return "(" + o.substr(0,3) + ") " + o.substr(3, 3) + "-" + o.substr(6);
|
||||
}
|
||||
var oa = "";
|
||||
if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))) {
|
||||
ri = Math.min(r[4].length,7);
|
||||
ff = frac(aval, Math.pow(10,ri)-1, false);
|
||||
o = "" + sign;
|
||||
oa = write_num("n", r[1], ff[1]);
|
||||
if(oa.charAt(oa.length-1) == " ") oa = oa.substr(0,oa.length-1) + "0";
|
||||
o += oa + r[2] + "/" + r[3];
|
||||
oa = rpad_(ff[2],ri);
|
||||
if(oa.length < r[4].length) oa = hashq(r[4].substr(r[4].length-oa.length)) + oa;
|
||||
o += oa;
|
||||
return o;
|
||||
}
|
||||
if((r = fmt.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/))) {
|
||||
ri = Math.min(Math.max(r[1].length, r[4].length),7);
|
||||
ff = frac(aval, Math.pow(10,ri)-1, true);
|
||||
return sign + (ff[0]||(ff[1] ? "" : "0")) + " " + (ff[1] ? pad_(ff[1],ri) + r[2] + "/" + r[3] + rpad_(ff[2],ri): fill(" ", 2*ri+1 + r[2].length + r[3].length));
|
||||
}
|
||||
if((r = fmt.match(/^[#0?]+$/))) {
|
||||
o = "" + val;
|
||||
if(fmt.length <= o.length) return o;
|
||||
return hashq(fmt.substr(0,fmt.length-o.length)) + o;
|
||||
}
|
||||
if((r = fmt.match(/^([#0]+)\.([#0]+)$/))) {
|
||||
o = "" + val.toFixed(Math.min(r[2].length,10)).replace(/([^0])0+$/,"$1");
|
||||
ri = o.indexOf(".");
|
||||
var lres = fmt.indexOf(".") - ri, rres = fmt.length - o.length - lres;
|
||||
return hashq(fmt.substr(0,lres) + o + fmt.substr(fmt.length-rres));
|
||||
}
|
||||
if((r = fmt.match(/^00,000\.([#0]*0)$/))) {
|
||||
return val < 0 ? "-" + write_num_int(type, fmt, -val) : commaify(""+val).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function($$) { return "00," + ($$.length < 3 ? pad0(0,3-$$.length) : "") + $$; }) + "." + pad0(0,r[1].length);
|
||||
}
|
||||
switch(fmt) {
|
||||
case "###,###":
|
||||
case "##,###":
|
||||
case "#,###": var x = commaify(""+aval); return x !== "0" ? sign + x : "";
|
||||
default:
|
||||
if(fmt.match(/\.[0#?]*$/)) return write_num_int(type, fmt.slice(0,fmt.lastIndexOf(".")), val) + hashq(fmt.slice(fmt.lastIndexOf(".")));
|
||||
}
|
||||
throw new Error("unsupported format |" + fmt + "|");
|
||||
}
|
||||
return function write_num(type, fmt, val) {
|
||||
return (val|0) === val ? write_num_int(type, fmt, val) : write_num_flt(type, fmt, val);
|
||||
};})();
|
||||
function split_fmt(fmt) {
|
||||
var out = [];
|
||||
var in_str = false/*, cc*/;
|
||||
for(var i = 0, j = 0; i < fmt.length; ++i) switch((/*cc=*/fmt.charCodeAt(i))) {
|
||||
case 34: /* '"' */
|
||||
in_str = !in_str; break;
|
||||
case 95: case 42: case 92: /* '_' '*' '\\' */
|
||||
++i; break;
|
||||
case 59: /* ';' */
|
||||
out[out.length] = fmt.substr(j,i-j);
|
||||
j = i+1;
|
||||
}
|
||||
out[out.length] = fmt.substr(j);
|
||||
if(in_str === true) throw new Error("Format |" + fmt + "| unterminated string ");
|
||||
return out;
|
||||
}
|
||||
SSF._split = split_fmt;
|
||||
var abstime = /\[[HhMmSs\u0E0A\u0E19\u0E17]*\]/;
|
||||
function fmt_is_date(fmt) {
|
||||
var i = 0, /*cc = 0,*/ c = "", o = "";
|
||||
while(i < fmt.length) {
|
||||
switch((c = fmt.charAt(i))) {
|
||||
case 'G': if(isgeneral(fmt, i)) i+= 6; i++; break;
|
||||
case '"': for(;(/*cc=*/fmt.charCodeAt(++i)) !== 34 && i < fmt.length;){/*empty*/} ++i; break;
|
||||
case '\\': i+=2; break;
|
||||
case '_': i+=2; break;
|
||||
case '@': ++i; break;
|
||||
case 'B': case 'b':
|
||||
if(fmt.charAt(i+1) === "1" || fmt.charAt(i+1) === "2") return true;
|
||||
/* falls through */
|
||||
case 'M': case 'D': case 'Y': case 'H': case 'S': case 'E':
|
||||
/* falls through */
|
||||
case 'm': case 'd': case 'y': case 'h': case 's': case 'e': case 'g': return true;
|
||||
case 'A': case 'a': case '上':
|
||||
if(fmt.substr(i, 3).toUpperCase() === "A/P") return true;
|
||||
if(fmt.substr(i, 5).toUpperCase() === "AM/PM") return true;
|
||||
if(fmt.substr(i, 5).toUpperCase() === "上午/下午") return true;
|
||||
++i; break;
|
||||
case '[':
|
||||
o = c;
|
||||
while(fmt.charAt(i++) !== ']' && i < fmt.length) o += fmt.charAt(i);
|
||||
if(o.match(abstime)) return true;
|
||||
break;
|
||||
case '.':
|
||||
/* falls through */
|
||||
case '0': case '#':
|
||||
while(i < fmt.length && ("0#?.,E+-%".indexOf(c=fmt.charAt(++i)) > -1 || (c=='\\' && fmt.charAt(i+1) == "-" && "0#".indexOf(fmt.charAt(i+2))>-1))){/* empty */}
|
||||
break;
|
||||
case '?': while(fmt.charAt(++i) === c){/* empty */} break;
|
||||
case '*': ++i; if(fmt.charAt(i) == ' ' || fmt.charAt(i) == '*') ++i; break;
|
||||
case '(': case ')': ++i; break;
|
||||
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
|
||||
while(i < fmt.length && "0123456789".indexOf(fmt.charAt(++i)) > -1){/* empty */} break;
|
||||
case ' ': ++i; break;
|
||||
default: ++i; break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
SSF.is_date = fmt_is_date;
|
||||
function eval_fmt(fmt, v, opts, flen) {
|
||||
var out = [], o = "", i = 0, c = "", lst='t', dt, j, cc;
|
||||
var hr='H';
|
||||
/* Tokenize */
|
||||
while(i < fmt.length) {
|
||||
switch((c = fmt.charAt(i))) {
|
||||
case 'G': /* General */
|
||||
if(!isgeneral(fmt, i)) throw new Error('unrecognized character ' + c + ' in ' +fmt);
|
||||
out[out.length] = {t:'G', v:'General'}; i+=7; break;
|
||||
case '"': /* Literal text */
|
||||
for(o="";(cc=fmt.charCodeAt(++i)) !== 34 && i < fmt.length;) o += String.fromCharCode(cc);
|
||||
out[out.length] = {t:'t', v:o}; ++i; break;
|
||||
case '\\': var w = fmt.charAt(++i), t = (w === "(" || w === ")") ? w : 't';
|
||||
out[out.length] = {t:t, v:w}; ++i; break;
|
||||
case '_': out[out.length] = {t:'t', v:" "}; i+=2; break;
|
||||
case '@': /* Text Placeholder */
|
||||
out[out.length] = {t:'T', v:v}; ++i; break;
|
||||
case 'B': case 'b':
|
||||
if(fmt.charAt(i+1) === "1" || fmt.charAt(i+1) === "2") {
|
||||
if(dt==null) { dt=parse_date_code(v, opts, fmt.charAt(i+1) === "2"); if(dt==null) return ""; }
|
||||
out[out.length] = {t:'X', v:fmt.substr(i,2)}; lst = c; i+=2; break;
|
||||
}
|
||||
/* falls through */
|
||||
case 'M': case 'D': case 'Y': case 'H': case 'S': case 'E':
|
||||
c = c.toLowerCase();
|
||||
/* falls through */
|
||||
case 'm': case 'd': case 'y': case 'h': case 's': case 'e': case 'g':
|
||||
if(v < 0) return "";
|
||||
if(dt==null) { dt=parse_date_code(v, opts); if(dt==null) return ""; }
|
||||
o = c; while(++i < fmt.length && fmt.charAt(i).toLowerCase() === c) o+=c;
|
||||
if(c === 'm' && lst.toLowerCase() === 'h') c = 'M';
|
||||
if(c === 'h') c = hr;
|
||||
out[out.length] = {t:c, v:o}; lst = c; break;
|
||||
case 'A': case 'a': case '上':
|
||||
var q={t:c, v:c};
|
||||
if(dt==null) dt=parse_date_code(v, opts);
|
||||
if(fmt.substr(i, 3).toUpperCase() === "A/P") { if(dt!=null) q.v = dt.H >= 12 ? "P" : "A"; q.t = 'T'; hr='h';i+=3;}
|
||||
else if(fmt.substr(i,5).toUpperCase() === "AM/PM") { if(dt!=null) q.v = dt.H >= 12 ? "PM" : "AM"; q.t = 'T'; i+=5; hr='h'; }
|
||||
else if(fmt.substr(i,5).toUpperCase() === "上午/下午") { if(dt!=null) q.v = dt.H >= 12 ? "下午" : "上午"; q.t = 'T'; i+=5; hr='h'; }
|
||||
else { q.t = "t"; ++i; }
|
||||
if(dt==null && q.t === 'T') return "";
|
||||
out[out.length] = q; lst = c; break;
|
||||
case '[':
|
||||
o = c;
|
||||
while(fmt.charAt(i++) !== ']' && i < fmt.length) o += fmt.charAt(i);
|
||||
if(o.slice(-1) !== ']') throw 'unterminated "[" block: |' + o + '|';
|
||||
if(o.match(abstime)) {
|
||||
if(dt==null) { dt=parse_date_code(v, opts); if(dt==null) return ""; }
|
||||
out[out.length] = {t:'Z', v:o.toLowerCase()};
|
||||
lst = o.charAt(1);
|
||||
} else if(o.indexOf("$") > -1) {
|
||||
o = (o.match(/\$([^-\[\]]*)/)||[])[1]||"$";
|
||||
if(!fmt_is_date(fmt)) out[out.length] = {t:'t',v:o};
|
||||
}
|
||||
break;
|
||||
/* Numbers */
|
||||
case '.':
|
||||
if(dt != null) {
|
||||
o = c; while(++i < fmt.length && (c=fmt.charAt(i)) === "0") o += c;
|
||||
out[out.length] = {t:'s', v:o}; break;
|
||||
}
|
||||
/* falls through */
|
||||
case '0': case '#':
|
||||
o = c; while(++i < fmt.length && "0#?.,E+-%".indexOf(c=fmt.charAt(i)) > -1) o += c;
|
||||
out[out.length] = {t:'n', v:o}; break;
|
||||
case '?':
|
||||
o = c; while(fmt.charAt(++i) === c) o+=c;
|
||||
out[out.length] = {t:c, v:o}; lst = c; break;
|
||||
case '*': ++i; if(fmt.charAt(i) == ' ' || fmt.charAt(i) == '*') ++i; break; // **
|
||||
case '(': case ')': out[out.length] = {t:(flen===1?'t':c), v:c}; ++i; break;
|
||||
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
|
||||
o = c; while(i < fmt.length && "0123456789".indexOf(fmt.charAt(++i)) > -1) o+=fmt.charAt(i);
|
||||
out[out.length] = {t:'D', v:o}; break;
|
||||
case ' ': out[out.length] = {t:c, v:c}; ++i; break;
|
||||
case '$': out[out.length] = {t:'t', v:'$'}; ++i; break;
|
||||
default:
|
||||
if(",$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP".indexOf(c) === -1) throw new Error('unrecognized character ' + c + ' in ' + fmt);
|
||||
out[out.length] = {t:'t', v:c}; ++i; break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scan for date/time parts */
|
||||
var bt = 0, ss0 = 0, ssm;
|
||||
for(i=out.length-1, lst='t'; i >= 0; --i) {
|
||||
switch(out[i].t) {
|
||||
case 'h': case 'H': out[i].t = hr; lst='h'; if(bt < 1) bt = 1; break;
|
||||
case 's':
|
||||
if((ssm=out[i].v.match(/\.0+$/))) ss0=Math.max(ss0,ssm[0].length-1);
|
||||
if(bt < 3) bt = 3;
|
||||
/* falls through */
|
||||
case 'd': case 'y': case 'M': case 'e': lst=out[i].t; break;
|
||||
case 'm': if(lst === 's') { out[i].t = 'M'; if(bt < 2) bt = 2; } break;
|
||||
case 'X': /*if(out[i].v === "B2");*/
|
||||
break;
|
||||
case 'Z':
|
||||
if(bt < 1 && out[i].v.match(/[Hh]/)) bt = 1;
|
||||
if(bt < 2 && out[i].v.match(/[Mm]/)) bt = 2;
|
||||
if(bt < 3 && out[i].v.match(/[Ss]/)) bt = 3;
|
||||
}
|
||||
}
|
||||
/* time rounding depends on presence of minute / second / usec fields */
|
||||
switch(bt) {
|
||||
case 0: break;
|
||||
case 1:
|
||||
if(dt.u >= 0.5) { dt.u = 0; ++dt.S; }
|
||||
if(dt.S >= 60) { dt.S = 0; ++dt.M; }
|
||||
if(dt.M >= 60) { dt.M = 0; ++dt.H; }
|
||||
break;
|
||||
case 2:
|
||||
if(dt.u >= 0.5) { dt.u = 0; ++dt.S; }
|
||||
if(dt.S >= 60) { dt.S = 0; ++dt.M; }
|
||||
break;
|
||||
}
|
||||
|
||||
/* replace fields */
|
||||
var nstr = "", jj;
|
||||
for(i=0; i < out.length; ++i) {
|
||||
switch(out[i].t) {
|
||||
case 't': case 'T': case ' ': case 'D': break;
|
||||
case 'X': out[i].v = ""; out[i].t = ";"; break;
|
||||
case 'd': case 'm': case 'y': case 'h': case 'H': case 'M': case 's': case 'e': case 'b': case 'Z':
|
||||
out[i].v = write_date(out[i].t.charCodeAt(0), out[i].v, dt, ss0);
|
||||
out[i].t = 't'; break;
|
||||
case 'n': case '?':
|
||||
jj = i+1;
|
||||
while(out[jj] != null && (
|
||||
(c=out[jj].t) === "?" || c === "D" ||
|
||||
((c === " " || c === "t") && out[jj+1] != null && (out[jj+1].t === '?' || out[jj+1].t === "t" && out[jj+1].v === '/')) ||
|
||||
(out[i].t === '(' && (c === ' ' || c === 'n' || c === ')')) ||
|
||||
(c === 't' && (out[jj].v === '/' || out[jj].v === ' ' && out[jj+1] != null && out[jj+1].t == '?'))
|
||||
)) {
|
||||
out[i].v += out[jj].v;
|
||||
out[jj] = {v:"", t:";"}; ++jj;
|
||||
}
|
||||
nstr += out[i].v;
|
||||
i = jj-1; break;
|
||||
case 'G': out[i].t = 't'; out[i].v = general_fmt(v,opts); break;
|
||||
}
|
||||
}
|
||||
var vv = "", myv, ostr;
|
||||
if(nstr.length > 0) {
|
||||
if(nstr.charCodeAt(0) == 40) /* '(' */ {
|
||||
myv = (v<0&&nstr.charCodeAt(0) === 45 ? -v : v);
|
||||
ostr = write_num('n', nstr, myv);
|
||||
} else {
|
||||
myv = (v<0 && flen > 1 ? -v : v);
|
||||
ostr = write_num('n', nstr, myv);
|
||||
if(myv < 0 && out[0] && out[0].t == 't') {
|
||||
ostr = ostr.substr(1);
|
||||
out[0].v = "-" + out[0].v;
|
||||
}
|
||||
}
|
||||
jj=ostr.length-1;
|
||||
var decpt = out.length;
|
||||
for(i=0; i < out.length; ++i) if(out[i] != null && out[i].t != 't' && out[i].v.indexOf(".") > -1) { decpt = i; break; }
|
||||
var lasti=out.length;
|
||||
if(decpt === out.length && ostr.indexOf("E") === -1) {
|
||||
for(i=out.length-1; i>= 0;--i) {
|
||||
if(out[i] == null || 'n?'.indexOf(out[i].t) === -1) continue;
|
||||
if(jj>=out[i].v.length-1) { jj -= out[i].v.length; out[i].v = ostr.substr(jj+1, out[i].v.length); }
|
||||
else if(jj < 0) out[i].v = "";
|
||||
else { out[i].v = ostr.substr(0, jj+1); jj = -1; }
|
||||
out[i].t = 't';
|
||||
lasti = i;
|
||||
}
|
||||
if(jj>=0 && lasti<out.length) out[lasti].v = ostr.substr(0,jj+1) + out[lasti].v;
|
||||
}
|
||||
else if(decpt !== out.length && ostr.indexOf("E") === -1) {
|
||||
jj = ostr.indexOf(".")-1;
|
||||
for(i=decpt; i>= 0; --i) {
|
||||
if(out[i] == null || 'n?'.indexOf(out[i].t) === -1) continue;
|
||||
j=out[i].v.indexOf(".")>-1&&i===decpt?out[i].v.indexOf(".")-1:out[i].v.length-1;
|
||||
vv = out[i].v.substr(j+1);
|
||||
for(; j>=0; --j) {
|
||||
if(jj>=0 && (out[i].v.charAt(j) === "0" || out[i].v.charAt(j) === "#")) vv = ostr.charAt(jj--) + vv;
|
||||
}
|
||||
out[i].v = vv;
|
||||
out[i].t = 't';
|
||||
lasti = i;
|
||||
}
|
||||
if(jj>=0 && lasti<out.length) out[lasti].v = ostr.substr(0,jj+1) + out[lasti].v;
|
||||
jj = ostr.indexOf(".")+1;
|
||||
for(i=decpt; i<out.length; ++i) {
|
||||
if(out[i] == null || ('n?('.indexOf(out[i].t) === -1 && i !== decpt)) continue;
|
||||
j=out[i].v.indexOf(".")>-1&&i===decpt?out[i].v.indexOf(".")+1:0;
|
||||
vv = out[i].v.substr(0,j);
|
||||
for(; j<out[i].v.length; ++j) {
|
||||
if(jj<ostr.length) vv += ostr.charAt(jj++);
|
||||
}
|
||||
out[i].v = vv;
|
||||
out[i].t = 't';
|
||||
lasti = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i=0; i<out.length; ++i) if(out[i] != null && 'n?'.indexOf(out[i].t)>-1) {
|
||||
myv = (flen >1 && v < 0 && i>0 && out[i-1].v === "-" ? -v:v);
|
||||
out[i].v = write_num(out[i].t, out[i].v, myv);
|
||||
out[i].t = 't';
|
||||
}
|
||||
var retval = "";
|
||||
for(i=0; i !== out.length; ++i) if(out[i] != null) retval += out[i].v;
|
||||
return retval;
|
||||
}
|
||||
SSF._eval = eval_fmt;
|
||||
var cfregex = /\[[=<>]/;
|
||||
var cfregex2 = /\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/;
|
||||
function chkcond(v, rr) {
|
||||
if(rr == null) return false;
|
||||
var thresh = parseFloat(rr[2]);
|
||||
switch(rr[1]) {
|
||||
case "=": if(v == thresh) return true; break;
|
||||
case ">": if(v > thresh) return true; break;
|
||||
case "<": if(v < thresh) return true; break;
|
||||
case "<>": if(v != thresh) return true; break;
|
||||
case ">=": if(v >= thresh) return true; break;
|
||||
case "<=": if(v <= thresh) return true; break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function choose_fmt(f, v) {
|
||||
var fmt = split_fmt(f);
|
||||
var l = fmt.length, lat = fmt[l-1].indexOf("@");
|
||||
if(l<4 && lat>-1) --l;
|
||||
if(fmt.length > 4) throw new Error("cannot find right format for |" + fmt.join("|") + "|");
|
||||
if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"];
|
||||
switch(fmt.length) {
|
||||
case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break;
|
||||
case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break;
|
||||
case 3: fmt = lat>-1 ? [fmt[0], fmt[1], fmt[0], fmt[2]] : [fmt[0], fmt[1], fmt[2], "@"]; break;
|
||||
case 4: break;
|
||||
}
|
||||
var ff = v > 0 ? fmt[0] : v < 0 ? fmt[1] : fmt[2];
|
||||
if(fmt[0].indexOf("[") === -1 && fmt[1].indexOf("[") === -1) return [l, ff];
|
||||
if(fmt[0].match(cfregex) != null || fmt[1].match(cfregex) != null) {
|
||||
var m1 = fmt[0].match(cfregex2);
|
||||
var m2 = fmt[1].match(cfregex2);
|
||||
return chkcond(v, m1) ? [l, fmt[0]] : chkcond(v, m2) ? [l, fmt[1]] : [l, fmt[m1 != null && m2 != null ? 2 : 1]];
|
||||
}
|
||||
return [l, ff];
|
||||
}
|
||||
function format(fmt,v,o) {
|
||||
if(o == null) o = {};
|
||||
var sfmt = "";
|
||||
switch(typeof fmt) {
|
||||
case "string":
|
||||
if(fmt == "m/d/yy" && o.dateNF) sfmt = o.dateNF;
|
||||
else sfmt = fmt;
|
||||
break;
|
||||
case "number":
|
||||
if(fmt == 14 && o.dateNF) sfmt = o.dateNF;
|
||||
else sfmt = (o.table != null ? (o.table) : table_fmt)[fmt];
|
||||
if(sfmt == null) sfmt = (o.table && o.table[default_map[fmt]]) || table_fmt[default_map[fmt]];
|
||||
if(sfmt == null) sfmt = default_str[fmt] || "General";
|
||||
break;
|
||||
}
|
||||
if(isgeneral(sfmt,0)) return general_fmt(v, o);
|
||||
if(v instanceof Date) v = datenum_local(v, o.date1904);
|
||||
var f = choose_fmt(sfmt, v);
|
||||
if(isgeneral(f[1])) return general_fmt(v, o);
|
||||
if(v === true) v = "TRUE"; else if(v === false) v = "FALSE";
|
||||
else if(v === "" || v == null) return "";
|
||||
return eval_fmt(f[1], v, o, f[0]);
|
||||
}
|
||||
function load_entry(fmt, idx) {
|
||||
if(typeof idx != 'number') {
|
||||
idx = +idx || -1;
|
||||
for(var i = 0; i < 0x0188; ++i) {
|
||||
if(table_fmt[i] == undefined) { if(idx < 0) idx = i; continue; }
|
||||
if(table_fmt[i] == fmt) { idx = i; break; }
|
||||
}
|
||||
if(idx < 0) idx = 0x187;
|
||||
}
|
||||
table_fmt[idx] = fmt;
|
||||
return idx;
|
||||
}
|
||||
SSF.load = load_entry;
|
||||
SSF._table = table_fmt;
|
||||
SSF.get_table = function get_table() { return table_fmt; };
|
||||
SSF.load_table = function load_table(tbl) {
|
||||
for(var i=0; i!=0x0188; ++i)
|
||||
if(tbl[i] !== undefined) load_entry(tbl[i], i);
|
||||
};
|
||||
SSF.init_table = init_table;
|
||||
SSF.format = format;
|
||||
};
|
||||
make_ssf(SSF);
|
||||
/*global module */
|
||||
if(typeof module !== 'undefined' && typeof DO_NOT_EXPORT_SSF === 'undefined') module.exports = SSF;
|
||||
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./async').safe;
|
||||
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
lazyLightningCss: ()=>lazyLightningCss,
|
||||
lightningcss: ()=>lightningcss,
|
||||
loadPostcss: ()=>loadPostcss,
|
||||
loadPostcssImport: ()=>loadPostcssImport
|
||||
});
|
||||
const _packageJson = /*#__PURE__*/ _interopRequireDefault(require("../../../../package.json"));
|
||||
const _browserslist = /*#__PURE__*/ _interopRequireDefault(require("browserslist"));
|
||||
const _index = require("../../../../peers/index");
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
function lazyLightningCss() {
|
||||
// TODO: Make this lazy/bundled
|
||||
return require("lightningcss");
|
||||
}
|
||||
let lightningCss;
|
||||
function loadLightningCss() {
|
||||
if (lightningCss) {
|
||||
return lightningCss;
|
||||
}
|
||||
// Try to load a local version first
|
||||
try {
|
||||
return lightningCss = require("lightningcss");
|
||||
} catch {}
|
||||
return lightningCss = lazyLightningCss();
|
||||
}
|
||||
async function lightningcss(shouldMinify, result) {
|
||||
let css = loadLightningCss();
|
||||
try {
|
||||
let transformed = css.transform({
|
||||
filename: result.opts.from || "input.css",
|
||||
code: Buffer.from(result.css, "utf-8"),
|
||||
minify: shouldMinify,
|
||||
sourceMap: !!result.map,
|
||||
inputSourceMap: result.map ? result.map.toString() : undefined,
|
||||
targets: css.browserslistToTargets((0, _browserslist.default)(_packageJson.default.browserslist)),
|
||||
drafts: {
|
||||
nesting: true
|
||||
}
|
||||
});
|
||||
return Object.assign(result, {
|
||||
css: transformed.code.toString("utf8"),
|
||||
map: result.map ? Object.assign(result.map, {
|
||||
toString () {
|
||||
return transformed.map.toString();
|
||||
}
|
||||
}) : result.map
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Unable to use Lightning CSS. Using raw version instead.");
|
||||
console.error(err);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
function loadPostcss() {
|
||||
// Try to load a local `postcss` version first
|
||||
try {
|
||||
return require("postcss");
|
||||
} catch {}
|
||||
return (0, _index.lazyPostcss)();
|
||||
}
|
||||
function loadPostcssImport() {
|
||||
// Try to load a local `postcss-import` version first
|
||||
try {
|
||||
return require("postcss-import");
|
||||
} catch {}
|
||||
return (0, _index.lazyPostcssImport)();
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import type {SplitWords} from './split-words';
|
||||
|
||||
/**
|
||||
CamelCase options.
|
||||
|
||||
@see {@link CamelCase}
|
||||
*/
|
||||
export type CamelCaseOptions = {
|
||||
/**
|
||||
Whether to preserved consecutive uppercase letter.
|
||||
|
||||
@default true
|
||||
*/
|
||||
preserveConsecutiveUppercase?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
Convert an array of words to camel-case.
|
||||
*/
|
||||
type CamelCaseFromArray<
|
||||
Words extends string[],
|
||||
Options extends CamelCaseOptions,
|
||||
OutputString extends string = '',
|
||||
> = Words extends [
|
||||
infer FirstWord extends string,
|
||||
...infer RemainingWords extends string[],
|
||||
]
|
||||
? Options['preserveConsecutiveUppercase'] extends true
|
||||
? `${Capitalize<FirstWord>}${CamelCaseFromArray<RemainingWords, Options>}`
|
||||
: `${Capitalize<Lowercase<FirstWord>>}${CamelCaseFromArray<RemainingWords, Options>}`
|
||||
: OutputString;
|
||||
|
||||
/**
|
||||
Convert a string literal to camel-case.
|
||||
|
||||
This can be useful when, for example, converting some kebab-cased command-line flags or a snake-cased database result.
|
||||
|
||||
By default, consecutive uppercase letter are preserved. See {@link CamelCaseOptions.preserveConsecutiveUppercase preserveConsecutiveUppercase} option to change this behaviour.
|
||||
|
||||
@example
|
||||
```
|
||||
import type {CamelCase} from 'type-fest';
|
||||
|
||||
// Simple
|
||||
|
||||
const someVariable: CamelCase<'foo-bar'> = 'fooBar';
|
||||
|
||||
// Advanced
|
||||
|
||||
type CamelCasedProperties<T> = {
|
||||
[K in keyof T as CamelCase<K>]: T[K]
|
||||
};
|
||||
|
||||
interface RawOptions {
|
||||
'dry-run': boolean;
|
||||
'full_family_name': string;
|
||||
foo: number;
|
||||
BAR: string;
|
||||
QUZ_QUX: number;
|
||||
'OTHER-FIELD': boolean;
|
||||
}
|
||||
|
||||
const dbResult: CamelCasedProperties<RawOptions> = {
|
||||
dryRun: true,
|
||||
fullFamilyName: 'bar.js',
|
||||
foo: 123,
|
||||
bar: 'foo',
|
||||
quzQux: 6,
|
||||
otherField: false
|
||||
};
|
||||
```
|
||||
|
||||
@category Change case
|
||||
@category Template literal
|
||||
*/
|
||||
export type CamelCase<Type, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Type extends string
|
||||
? string extends Type
|
||||
? Type
|
||||
: Uncapitalize<CamelCaseFromArray<SplitWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, Options>>
|
||||
: Type;
|
||||
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./async').fast;
|
||||
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,20 @@
|
||||
import { isFunction } from './isFunction';
|
||||
export function hasLift(source) {
|
||||
return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
||||
}
|
||||
export function operate(init) {
|
||||
return function (source) {
|
||||
if (hasLift(source)) {
|
||||
return source.lift(function (liftedSource) {
|
||||
try {
|
||||
return init(liftedSource, this);
|
||||
}
|
||||
catch (err) {
|
||||
this.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
throw new TypeError('Unable to lift unknown Observable type');
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=lift.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ColdObservable.js","sourceRoot":"","sources":["../../../../src/internal/testing/ColdObservable.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;IAAuC,kCAAa;IAQlD,wBAAmB,QAAuB,EAAE,SAAoB;QAAhE,YACE,kBAAM,UAA+B,UAA2B;YAC9D,IAAM,UAAU,GAAsB,IAAW,CAAC;YAClD,IAAM,KAAK,GAAG,UAAU,CAAC,kBAAkB,EAAE,CAAC;YAC9C,IAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;YACxC,YAAY,CAAC,GAAG,CACd,IAAI,YAAY,CAAC;gBACf,UAAU,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;YACzC,CAAC,CAAC,CACH,CAAC;YACF,UAAU,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;YACxC,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC,SAEH;QAdkB,cAAQ,GAAR,QAAQ,CAAe;QAPnC,mBAAa,GAAsB,EAAE,CAAC;QAoB3C,KAAI,CAAC,SAAS,GAAG,SAAS,CAAC;;IAC7B,CAAC;IAED,yCAAgB,GAAhB,UAAiB,UAA2B;QAC1C,IAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,EAAE,CAAC,EAAE,EAAE;YACvC,IAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACjC,UAAU,CAAC,GAAG,CACZ,IAAI,CAAC,SAAS,CAAC,QAAQ,CACrB,UAAC,KAAK;gBACE,IAAA,KAAyD,KAAM,EAAlD,YAAY,0BAAA,EAAgB,WAAW,gBAAW,CAAC;gBACtE,mBAAmB,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;YACjD,CAAC,EACD,OAAO,CAAC,KAAK,EACb,EAAE,OAAO,SAAA,EAAE,UAAU,YAAA,EAAE,CACxB,CACF,CAAC;SACH;IACH,CAAC;IACH,qBAAC;AAAD,CAAC,AAxCD,CAAuC,UAAU,GAwChD;;AACD,WAAW,CAAC,cAAc,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC"}
|
||||
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
SemVer: require('./semver.js'),
|
||||
Range: require('./range.js'),
|
||||
Comparator: require('./comparator.js'),
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"empty.js","sourceRoot":"","sources":["../../../../src/internal/observable/empty.ts"],"names":[],"mappings":";;;AAAA,4CAA2C;AAiE9B,QAAA,KAAK,GAAG,IAAI,uBAAU,CAAQ,UAAC,UAAU,IAAK,OAAA,UAAU,CAAC,QAAQ,EAAE,EAArB,CAAqB,CAAC,CAAC;AAOlF,SAAgB,KAAK,CAAC,SAAyB;IAC7C,OAAO,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAK,CAAC;AACvD,CAAC;AAFD,sBAEC;AAED,SAAS,cAAc,CAAC,SAAwB;IAC9C,OAAO,IAAI,uBAAU,CAAQ,UAAC,UAAU,IAAK,OAAA,SAAS,CAAC,QAAQ,CAAC,cAAM,OAAA,UAAU,CAAC,QAAQ,EAAE,EAArB,CAAqB,CAAC,EAA/C,CAA+C,CAAC,CAAC;AAChG,CAAC"}
|
||||
@@ -0,0 +1,2 @@
|
||||
var convert = require('./convert');
|
||||
module.exports = convert(require('../collection'));
|
||||
Reference in New Issue
Block a user