김대선

00시 00분 자동으로 데이터를 받아와서 datas 폴더에 년.월.시간 형식으로 저장

Showing 189 changed files with 4732 additions and 7 deletions
const express = require('express')
const schedule = require('node-schedule')
const fs = require('fs')
const functions = require('./function')
const app = express();
const server = app.listen(3000,()=>{
const host = server.address().address
const port = server.address().port
console.log("app listening at http://%s:%s", host, port)
})
const readData = async () =>{
const data = []
let title = ""
let tags = []
let url = ""
const today = new Date()
const string = fs.readFileSync(`./datas/${today.getFullYear()}.${today.getMonth()}.${today.getDate()}`, 'utf-8', 'r')
const stringArray = string.split('\n')
const size = stringArray.length
for(let i = 0 ; i < size; i++){
if( i % 3 == 0){
title = stringArray[i].replace("title : ", "")
}
else if( i % 3 == 1){
tags = stringArray[i].replace("tags : ", "").split(",")
}
else if ( i % 3 == 2){
url = stringArray[i].replace("url : ", "")
data.push({
title : title,
tags : tags,
url : url
})
}
}
console.log(data)
}
app.get('/', async (req, res)=>{
const save = async()=> {
try {
let string = ""
let data = await functions.getKakaoData()
let temp = ""
......@@ -46,6 +71,30 @@ app.get('/', async (req, res)=>{
temp = "url : " + i.url
string = string + temp + "\n"
}
const today = new Date()
fs.writeFile(`./datas/${today.getFullYear()}.${today.getMonth()}.${today.getDate()}`, string, 'utf-8', (err)=>{
if(err){
save()
}
else console.log("저장완료!")
})
} catch (error) {
console.log(error)
save()
}
}
const saveData = schedule.scheduleJob('0 0 0 * * *', save)
const server = app.listen(3000,()=>{
const host = server.address().address
const port = server.address().port
console.log("app listening at http://%s:%s", host, port)
})
app.get('/', async (req, res)=>{
res.send(string)
})
\ No newline at end of file
......
This diff is collapsed. Click to expand it.
......@@ -27,7 +27,8 @@ const makeObject = (array)=>{
else if (tempData.length == 4){
result.push({
title : tempData[0],
url : tempData[3]
url : tempData[3],
tags : []
})
}
}
......
......@@ -180,6 +180,18 @@
"node": ">= 0.8"
}
},
"node_modules/call-bind": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
"dependencies": {
"function-bind": "^1.1.1",
"get-intrinsic": "^1.0.2"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/cheerio": {
"version": "1.0.0-rc.9",
"resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.9.tgz",
......@@ -262,6 +274,18 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"node_modules/cron-parser": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/cron-parser/-/cron-parser-3.5.0.tgz",
"integrity": "sha512-wyVZtbRs6qDfFd8ap457w3XVntdvqcwBGxBoTvJQH9KGVKL/fB+h2k3C8AqiVxvUQKN1Ps/Ns46CNViOpVDhfQ==",
"dependencies": {
"is-nan": "^1.3.2",
"luxon": "^1.26.0"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/css-select": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/css-select/-/css-select-4.1.2.tgz",
......@@ -304,6 +328,17 @@
"node": ">=0.10.0"
}
},
"node_modules/define-properties": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
"integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==",
"dependencies": {
"object-keys": "^1.0.12"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
......@@ -570,6 +605,24 @@
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"node_modules/function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
"node_modules/get-intrinsic": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
"dependencies": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.1"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-stream": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
......@@ -603,6 +656,28 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dependencies": {
"function-bind": "^1.1.1"
},
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/has-symbols": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz",
"integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/htmlparser2": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-6.1.0.tgz",
......@@ -721,6 +796,21 @@
"node": ">= 0.10"
}
},
"node_modules/is-nan": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.2.tgz",
"integrity": "sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==",
"dependencies": {
"call-bind": "^1.0.0",
"define-properties": "^1.1.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/is-plain-object": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz",
......@@ -748,6 +838,19 @@
"node": ">=8"
}
},
"node_modules/long-timeout": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/long-timeout/-/long-timeout-0.1.1.tgz",
"integrity": "sha1-lyHXiLR+C8taJMLivuGg2lXatRQ="
},
"node_modules/luxon": {
"version": "1.27.0",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.27.0.tgz",
"integrity": "sha512-VKsFsPggTA0DvnxtJdiExAucKdAnwbCCNlMM5ENvHlxubqWd0xhZcdb4XgZ7QFNhaRhilXCFxHuoObP5BNA4PA==",
"engines": {
"node": "*"
}
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
......@@ -847,6 +950,19 @@
"node": "4.x || >=6.0.0"
}
},
"node_modules/node-schedule": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/node-schedule/-/node-schedule-2.0.0.tgz",
"integrity": "sha512-cHc9KEcfiuXxYDU+HjsBVo2FkWL1jRAUoczFoMIzRBpOA4p/NRHuuLs85AWOLgKsHtSPjN8csvwIxc2SqMv+CQ==",
"dependencies": {
"cron-parser": "^3.1.0",
"long-timeout": "0.1.1",
"sorted-array-functions": "^1.3.0"
},
"engines": {
"node": ">=6"
}
},
"node_modules/nth-check": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.0.0.tgz",
......@@ -858,6 +974,14 @@
"url": "https://github.com/fb55/nth-check?sponsor=1"
}
},
"node_modules/object-keys": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",
"integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
......@@ -1196,6 +1320,11 @@
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
},
"node_modules/sorted-array-functions": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/sorted-array-functions/-/sorted-array-functions-1.3.0.tgz",
"integrity": "sha512-2sqgzeFlid6N4Z2fUQ1cvFmTOLRi/sEDzSQ0OKYchqgoPmQBVyM3959qYx3fpS6Esef80KjmpgPeEr028dP3OA=="
},
"node_modules/source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
......
{
"root": true,
"extends": "@ljharb",
"rules": {
"func-name-matching": 0,
"id-length": 0,
"new-cap": [2, {
"capIsNewExceptions": [
"GetIntrinsic",
],
}],
"no-magic-numbers": 0,
"operator-linebreak": [2, "before"],
},
}
# 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/call-bind
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']
{
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"lines": 86,
"statements": 85.93,
"functions": 82.43,
"branches": 76.06,
"exclude": [
"coverage",
"test"
]
}
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.0.2](https://github.com/ljharb/call-bind/compare/v1.0.1...v1.0.2) - 2021-01-11
### Commits
- [Fix] properly include the receiver in the bound length [`dbae7bc`](https://github.com/ljharb/call-bind/commit/dbae7bc676c079a0d33c0a43e9ef92cb7b01345d)
## [v1.0.1](https://github.com/ljharb/call-bind/compare/v1.0.0...v1.0.1) - 2021-01-08
### Commits
- [Tests] migrate tests to Github Actions [`b6db284`](https://github.com/ljharb/call-bind/commit/b6db284c36f8ccd195b88a6764fe84b7223a0da1)
- [meta] do not publish github action workflow files [`ec7fe46`](https://github.com/ljharb/call-bind/commit/ec7fe46e60cfa4764ee943d2755f5e5a366e578e)
- [Fix] preserve original function’s length when possible [`adbceaa`](https://github.com/ljharb/call-bind/commit/adbceaa3cac4b41ea78bb19d7ccdbaaf7e0bdadb)
- [Tests] gather coverage data on every job [`d69e23c`](https://github.com/ljharb/call-bind/commit/d69e23cc65f101ba1d4c19bb07fa8eb0ec624be8)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` [`2fd3586`](https://github.com/ljharb/call-bind/commit/2fd3586c5d47b335364c14293114c6b625ae1f71)
- [Deps] update `get-intrinsic` [`f23e931`](https://github.com/ljharb/call-bind/commit/f23e9318cc271c2add8bb38cfded85ee7baf8eee)
- [Deps] update `get-intrinsic` [`72d9f44`](https://github.com/ljharb/call-bind/commit/72d9f44e184465ba8dd3fb48260bbcff234985f2)
- [meta] fix FUNDING.yml [`e723573`](https://github.com/ljharb/call-bind/commit/e723573438c5a68dcec31fb5d96ea6b7e4a93be8)
- [eslint] ignore coverage output [`15e76d2`](https://github.com/ljharb/call-bind/commit/15e76d28a5f43e504696401e5b31ebb78ee1b532)
- [meta] add Automatic Rebase and Require Allow Edits workflows [`8fa4dab`](https://github.com/ljharb/call-bind/commit/8fa4dabb23ba3dd7bb92c9571c1241c08b56e4b6)
## v1.0.0 - 2020-10-30
### Commits
- Initial commit [`306cf98`](https://github.com/ljharb/call-bind/commit/306cf98c7ec9e7ef66b653ec152277ac1381eb50)
- Tests [`e10d0bb`](https://github.com/ljharb/call-bind/commit/e10d0bbdadc7a10ecedc9a1c035112d3e368b8df)
- Implementation [`43852ed`](https://github.com/ljharb/call-bind/commit/43852eda0f187327b7fad2423ca972149a52bd65)
- npm init [`408f860`](https://github.com/ljharb/call-bind/commit/408f860b773a2f610805fd3613d0d71bac1b6249)
- [meta] add Automatic Rebase and Require Allow Edits workflows [`fb349b2`](https://github.com/ljharb/call-bind/commit/fb349b2e48defbec8b5ec8a8395cc8f69f220b13)
- [meta] add `auto-changelog` [`c4001fc`](https://github.com/ljharb/call-bind/commit/c4001fc43031799ef908211c98d3b0fb2b60fde4)
- [meta] add "funding"; create `FUNDING.yml` [`d4d6d29`](https://github.com/ljharb/call-bind/commit/d4d6d2974a14bc2e98830468eda7fe6d6a776717)
- [Tests] add `npm run lint` [`dedfb98`](https://github.com/ljharb/call-bind/commit/dedfb98bd0ecefb08ddb9a94061bd10cde4332af)
- Only apps should have lockfiles [`54ac776`](https://github.com/ljharb/call-bind/commit/54ac77653db45a7361dc153d2f478e743f110650)
- [meta] add `safe-publish-latest` [`9ea8e43`](https://github.com/ljharb/call-bind/commit/9ea8e435b950ce9b705559cd651039f9bf40140f)
MIT License
Copyright (c) 2020 Jordan Harband
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.
# call-bind
Robustly `.call.bind()` a function.
'use strict';
var GetIntrinsic = require('get-intrinsic');
var callBind = require('./');
var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));
module.exports = function callBoundIntrinsic(name, allowMissing) {
var intrinsic = GetIntrinsic(name, !!allowMissing);
if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) {
return callBind(intrinsic);
}
return intrinsic;
};
'use strict';
var bind = require('function-bind');
var GetIntrinsic = require('get-intrinsic');
var $apply = GetIntrinsic('%Function.prototype.apply%');
var $call = GetIntrinsic('%Function.prototype.call%');
var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true);
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
var $max = GetIntrinsic('%Math.max%');
if ($defineProperty) {
try {
$defineProperty({}, 'a', { value: 1 });
} catch (e) {
// IE 8 has a broken defineProperty
$defineProperty = null;
}
}
module.exports = function callBind(originalFunction) {
var func = $reflectApply(bind, $call, arguments);
if ($gOPD && $defineProperty) {
var desc = $gOPD(func, 'length');
if (desc.configurable) {
// original length, plus the receiver, minus any additional arguments (after the receiver)
$defineProperty(
func,
'length',
{ value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) }
);
}
}
return func;
};
var applyBind = function applyBind() {
return $reflectApply(bind, $apply, arguments);
};
if ($defineProperty) {
$defineProperty(module.exports, 'apply', { value: applyBind });
} else {
module.exports.apply = applyBind;
}
{
"name": "call-bind",
"version": "1.0.2",
"description": "Robustly `.call.bind()` a function",
"main": "index.js",
"exports": {
".": [
{
"default": "./index.js"
},
"./index.js"
],
"./callBound": [
{
"default": "./callBound.js"
},
"./callBound.js"
],
"./package.json": "./package.json"
},
"scripts": {
"prepublish": "safe-publish-latest",
"lint": "eslint --ext=.js,.mjs .",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/*'",
"test": "npm run tests-only",
"posttest": "aud --production",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/ljharb/call-bind.git"
},
"keywords": [
"javascript",
"ecmascript",
"es",
"js",
"callbind",
"callbound",
"call",
"bind",
"bound",
"call-bind",
"call-bound",
"function",
"es-abstract"
],
"author": "Jordan Harband <ljharb@gmail.com>",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/ljharb/call-bind/issues"
},
"homepage": "https://github.com/ljharb/call-bind#readme",
"devDependencies": {
"@ljharb/eslint-config": "^17.3.0",
"aud": "^1.1.3",
"auto-changelog": "^2.2.1",
"eslint": "^7.17.0",
"nyc": "^10.3.2",
"safe-publish-latest": "^1.1.4",
"tape": "^5.1.1"
},
"dependencies": {
"function-bind": "^1.1.1",
"get-intrinsic": "^1.0.2"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
}
}
'use strict';
var test = require('tape');
var callBound = require('../callBound');
test('callBound', function (t) {
// static primitive
t.equal(callBound('Array.length'), Array.length, 'Array.length yields itself');
t.equal(callBound('%Array.length%'), Array.length, '%Array.length% yields itself');
// static non-function object
t.equal(callBound('Array.prototype'), Array.prototype, 'Array.prototype yields itself');
t.equal(callBound('%Array.prototype%'), Array.prototype, '%Array.prototype% yields itself');
t.equal(callBound('Array.constructor'), Array.constructor, 'Array.constructor yields itself');
t.equal(callBound('%Array.constructor%'), Array.constructor, '%Array.constructor% yields itself');
// static function
t.equal(callBound('Date.parse'), Date.parse, 'Date.parse yields itself');
t.equal(callBound('%Date.parse%'), Date.parse, '%Date.parse% yields itself');
// prototype primitive
t.equal(callBound('Error.prototype.message'), Error.prototype.message, 'Error.prototype.message yields itself');
t.equal(callBound('%Error.prototype.message%'), Error.prototype.message, '%Error.prototype.message% yields itself');
// prototype function
t.notEqual(callBound('Object.prototype.toString'), Object.prototype.toString, 'Object.prototype.toString does not yield itself');
t.notEqual(callBound('%Object.prototype.toString%'), Object.prototype.toString, '%Object.prototype.toString% does not yield itself');
t.equal(callBound('Object.prototype.toString')(true), Object.prototype.toString.call(true), 'call-bound Object.prototype.toString calls into the original');
t.equal(callBound('%Object.prototype.toString%')(true), Object.prototype.toString.call(true), 'call-bound %Object.prototype.toString% calls into the original');
t['throws'](
function () { callBound('does not exist'); },
SyntaxError,
'nonexistent intrinsic throws'
);
t['throws'](
function () { callBound('does not exist', true); },
SyntaxError,
'allowMissing arg still throws for unknown intrinsic'
);
/* globals WeakRef: false */
t.test('real but absent intrinsic', { skip: typeof WeakRef !== 'undefined' }, function (st) {
st['throws'](
function () { callBound('WeakRef'); },
TypeError,
'real but absent intrinsic throws'
);
st.equal(callBound('WeakRef', true), undefined, 'allowMissing arg avoids exception');
st.end();
});
t.end();
});
'use strict';
var callBind = require('../');
var bind = require('function-bind');
var test = require('tape');
/*
* older engines have length nonconfigurable
* in io.js v3, it is configurable except on bound functions, hence the .bind()
*/
var functionsHaveConfigurableLengths = !!(
Object.getOwnPropertyDescriptor
&& Object.getOwnPropertyDescriptor(bind.call(function () {}), 'length').configurable
);
test('callBind', function (t) {
var sentinel = { sentinel: true };
var func = function (a, b) {
// eslint-disable-next-line no-invalid-this
return [this, a, b];
};
t.equal(func.length, 2, 'original function length is 2');
t.deepEqual(func(), [undefined, undefined, undefined], 'unbound func with too few args');
t.deepEqual(func(1, 2), [undefined, 1, 2], 'unbound func with right args');
t.deepEqual(func(1, 2, 3), [undefined, 1, 2], 'unbound func with too many args');
var bound = callBind(func);
t.equal(bound.length, func.length + 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
t.deepEqual(bound(), [undefined, undefined, undefined], 'bound func with too few args');
t.deepEqual(bound(1, 2), [1, 2, undefined], 'bound func with right args');
t.deepEqual(bound(1, 2, 3), [1, 2, 3], 'bound func with too many args');
var boundR = callBind(func, sentinel);
t.equal(boundR.length, func.length, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
t.deepEqual(boundR(), [sentinel, undefined, undefined], 'bound func with receiver, with too few args');
t.deepEqual(boundR(1, 2), [sentinel, 1, 2], 'bound func with receiver, with right args');
t.deepEqual(boundR(1, 2, 3), [sentinel, 1, 2], 'bound func with receiver, with too many args');
var boundArg = callBind(func, sentinel, 1);
t.equal(boundArg.length, func.length - 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
t.deepEqual(boundArg(), [sentinel, 1, undefined], 'bound func with receiver and arg, with too few args');
t.deepEqual(boundArg(2), [sentinel, 1, 2], 'bound func with receiver and arg, with right arg');
t.deepEqual(boundArg(2, 3), [sentinel, 1, 2], 'bound func with receiver and arg, with too many args');
t.test('callBind.apply', function (st) {
var aBound = callBind.apply(func);
st.deepEqual(aBound(sentinel), [sentinel, undefined, undefined], 'apply-bound func with no args');
st.deepEqual(aBound(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');
st.deepEqual(aBound(sentinel, [1, 2], 4), [sentinel, 1, 2], 'apply-bound func with right args');
var aBoundArg = callBind.apply(func);
st.deepEqual(aBoundArg(sentinel, [1, 2, 3], 4), [sentinel, 1, 2], 'apply-bound func with too many args');
st.deepEqual(aBoundArg(sentinel, [1, 2], 4), [sentinel, 1, 2], 'apply-bound func with right args');
st.deepEqual(aBoundArg(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');
var aBoundR = callBind.apply(func, sentinel);
st.deepEqual(aBoundR([1, 2, 3], 4), [sentinel, 1, 2], 'apply-bound func with receiver and too many args');
st.deepEqual(aBoundR([1, 2], 4), [sentinel, 1, 2], 'apply-bound func with receiver and right args');
st.deepEqual(aBoundR([1], 4), [sentinel, 1, undefined], 'apply-bound func with receiver and too few args');
st.end();
});
t.end();
});
{
"rules": {
"eol-last": ["error", "always"],
"quotes": ["error", "single"],
"semi": ["error", "always"]
},
"overrides": [
{
"files": ["test/**.js"],
"parserOptions": {
"ecmaVersion": 6
}
}
]
}
language: node_js
node_js:
- '10'
- '12'
- '14'
- '15'
The MIT License (MIT)
Copyright (c) 2014-2016 Harri Siirak
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.
cron-parser
================
[![Build Status](https://travis-ci.com/harrisiirak/cron-parser.svg?branch=master)](https://travis-ci.com/harrisiirak/cron-parser)
[![NPM version](https://badge.fury.io/js/cron-parser.png)](http://badge.fury.io/js/cron-parser)
Node.js library for parsing and manipulating crontab instructions. It includes support for timezones and DST transitions.
__Compatibility__
Node >= 0.8
Typescript <= 4.2
Setup
========
```bash
npm install cron-parser
```
Supported format
========
```
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31, L)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, optional)
```
Supports mixed use of ranges and range increments (L and W characters are not supported currently). See tests for examples.
Usage
========
Simple expression.
```javascript
var parser = require('cron-parser');
try {
var interval = parser.parseExpression('*/2 * * * *');
console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
console.log('Date: ', interval.next().toString()); // Sat Dec 29 2012 00:44:00 GMT+0200 (EET)
console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:42:00 GMT+0200 (EET)
console.log('Date: ', interval.prev().toString()); // Sat Dec 29 2012 00:40:00 GMT+0200 (EET)
} catch (err) {
console.log('Error: ' + err.message);
}
```
Iteration with limited timespan. Also returns ES6 compatible iterator (when iterator flag is set to true).
```javascript
var parser = require('cron-parser');
var options = {
currentDate: new Date('Wed, 26 Dec 2012 12:38:53 UTC'),
endDate: new Date('Wed, 26 Dec 2012 14:40:00 UTC'),
iterator: true
};
try {
var interval = parser.parseExpression('*/22 * * * *', options);
while (true) {
try {
var obj = interval.next();
console.log('value:', obj.value.toString(), 'done:', obj.done);
} catch (e) {
break;
}
}
// value: Wed Dec 26 2012 14:44:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 15:00:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 15:22:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 15:44:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 16:00:00 GMT+0200 (EET) done: false
// value: Wed Dec 26 2012 16:22:00 GMT+0200 (EET) done: true
} catch (err) {
console.log('Error: ' + err.message);
}
```
Timezone support
```javascript
var parser = require('cron-parser');
var options = {
currentDate: '2016-03-27 00:00:01',
tz: 'Europe/Athens'
};
try {
var interval = parser.parseExpression('0 * * * *', options);
console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 01:00:00 GMT+0200
console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 02:00:00 GMT+0200
console.log('Date: ', interval.next().toString()); // Date: Sun Mar 27 2016 04:00:00 GMT+0300 (Notice DST transition)
} catch (err) {
console.log('Error: ' + err.message);
}
```
Manipulation
```javascript
var parser = require('cron-parser');
var interval = parser.parseExpression('0 7 * * 0-4');
var fields = JSON.parse(JSON.stringify(interval.fields)); // Fields is immutable
fields.hour = [8];
fields.minute = [29];
fields.dayOfWeek = [1,3,4,5,6,7];
var modifiedInterval = parser.fieldsToExpression(fields);
var cronString = modifiedInterval.stringify();
console.log(cronString); // "29 8 * * 1,3-7"
```
Options
========
* *currentDate* - Start date of the iteration
* *endDate* - End date of the iteration
`currentDate` and `endDate` accept `string`, `integer` and `Date` as input.
In case of using `string` as input, not every string format accepted
by the `Date` constructor will work correctly. The supported formats are: [`ISO8601`](http://momentjs.com/docs/#/parsing/string/) and the older
[`ASP.NET JSON Date`](http://momentjs.com/docs/#/parsing/asp-net-json-date/) format. The reason being that those are the formats accepted by the
[`moment`](http://momentjs.com) library which is being used to handle dates.
Using `Date` as an input can be problematic specially when using the `tz` option. The issue being that, when creating a new `Date` object without
any timezone information, it will be created in the timezone of the system that is running the code. This (most of times) won't be what the user
will be expecting. Using one of the supported `string` formats will solve the issue(see timezone example).
* *iterator* - Return ES6 compatible iterator object
* *utc* - Enable UTC
* *tz* - Timezone string. It won't be used in case `utc` is enabled
{
"name": "cron-parser",
"repo": "harrisiirak/cron-parser",
"description": "Node.js library for parsing crontab instructions",
"version": "2.13.0",
"keywords": ["cron", "crontab", "parser"],
"dependencies": {},
"development": {},
"main": "lib/parser.js",
"scripts": ["lib/parser.js", "lib/expression.js", "lib/date.js", "lib/field_compactor.js", "lib/field_stringify.js"]
}
'use strict';
var luxon = require('luxon');
CronDate.prototype.addYear = function() {
this._date = this._date.plus({ years: 1 });
};
CronDate.prototype.addMonth = function() {
this._date = this._date.plus({ months: 1 }).startOf('month');
};
CronDate.prototype.addDay = function() {
this._date = this._date.plus({ days: 1 }).startOf('day');
};
CronDate.prototype.addHour = function() {
var prev = this._date;
this._date = this._date.plus({ hours: 1 }).startOf('hour');
if (this._date <= prev) {
this._date = this._date.plus({ hours: 1 });
}
};
CronDate.prototype.addMinute = function() {
var prev = this._date;
this._date = this._date.plus({ minutes: 1 }).startOf('minute');
if (this._date < prev) {
this._date = this._date.plus({ hours: 1 });
}
};
CronDate.prototype.addSecond = function() {
var prev = this._date;
this._date = this._date.plus({ seconds: 1 }).startOf('second');
if (this._date < prev) {
this._date = this._date.plus({ hours: 1 });
}
};
CronDate.prototype.subtractYear = function() {
this._date = this._date.minus({ years: 1 });
};
CronDate.prototype.subtractMonth = function() {
this._date = this._date
.minus({ months: 1 })
.endOf('month')
.startOf('second');
};
CronDate.prototype.subtractDay = function() {
this._date = this._date
.minus({ days: 1 })
.endOf('day')
.startOf('second');
};
CronDate.prototype.subtractHour = function() {
var prev = this._date;
this._date = this._date
.minus({ hours: 1 })
.endOf('hour')
.startOf('second');
if (this._date >= prev) {
this._date = this._date.minus({ hours: 1 });
}
};
CronDate.prototype.subtractMinute = function() {
var prev = this._date;
this._date = this._date.minus({ minutes: 1 })
.endOf('minute')
.startOf('second');
if (this._date > prev) {
this._date = this._date.minus({ hours: 1 });
}
};
CronDate.prototype.subtractSecond = function() {
var prev = this._date;
this._date = this._date
.minus({ seconds: 1 })
.startOf('second');
if (this._date > prev) {
this._date = this._date.minus({ hours: 1 });
}
};
CronDate.prototype.getDate = function() {
return this._date.day;
};
CronDate.prototype.getFullYear = function() {
return this._date.year;
};
CronDate.prototype.getDay = function() {
var weekday = this._date.weekday;
return weekday == 7 ? 0 : weekday;
};
CronDate.prototype.getMonth = function() {
return this._date.month - 1;
};
CronDate.prototype.getHours = function() {
return this._date.hour;
};
CronDate.prototype.getMinutes = function() {
return this._date.minute;
};
CronDate.prototype.getSeconds = function() {
return this._date.second;
};
CronDate.prototype.getMilliseconds = function() {
return this._date.millisecond;
};
CronDate.prototype.getTime = function() {
return this._date.valueOf();
};
CronDate.prototype.getUTCDate = function() {
return this._getUTC().day;
};
CronDate.prototype.getUTCFullYear = function() {
return this._getUTC().year;
};
CronDate.prototype.getUTCDay = function() {
var weekday = this._getUTC().weekday;
return weekday == 7 ? 0 : weekday;
};
CronDate.prototype.getUTCMonth = function() {
return this._getUTC().month - 1;
};
CronDate.prototype.getUTCHours = function() {
return this._getUTC().hour;
};
CronDate.prototype.getUTCMinutes = function() {
return this._getUTC().minute;
};
CronDate.prototype.getUTCSeconds = function() {
return this._getUTC().second;
};
CronDate.prototype.toISOString = function() {
return this._date.toUTC().toISO();
};
CronDate.prototype.toJSON = function() {
return this._date.toJSON();
};
CronDate.prototype.setDate = function(d) {
this._date = this._date.set({ day: d });
};
CronDate.prototype.setFullYear = function(y) {
this._date = this._date.set({ year: y });
};
CronDate.prototype.setDay = function(d) {
this._date = this._date.set({ weekday: d });
};
CronDate.prototype.setMonth = function(m) {
this._date = this._date.set({ month: m + 1 });
};
CronDate.prototype.setHours = function(h) {
this._date = this._date.set({ hour: h });
};
CronDate.prototype.setMinutes = function(m) {
this._date = this._date.set({ minute: m });
};
CronDate.prototype.setSeconds = function(s) {
this._date = this._date.set({ second: s });
};
CronDate.prototype.setMilliseconds = function(s) {
this._date = this._date.set({ millisecond: s });
};
CronDate.prototype._getUTC = function() {
return this._date.toUTC();
};
CronDate.prototype.toString = function() {
return this.toDate().toString();
};
CronDate.prototype.toDate = function() {
return this._date.toJSDate();
};
CronDate.prototype.isLastDayOfMonth = function() {
//next day
var newDate = this._date.plus({ days: 1 }).startOf('day');
return this._date.month !== newDate.month;
};
function CronDate (timestamp, tz) {
var dateOpts = { zone: tz };
if (!timestamp) {
this._date = luxon.DateTime.local();
} else if (timestamp instanceof CronDate) {
this._date = timestamp._date;
} else if (timestamp instanceof Date) {
this._date = luxon.DateTime.fromJSDate(timestamp, dateOpts);
} else if (typeof timestamp === 'number') {
this._date = luxon.DateTime.fromMillis(timestamp, dateOpts);
} else if (typeof timestamp === 'string') {
this._date = luxon.DateTime.fromISO(timestamp, dateOpts);
this._date.isValid || (this._date = luxon.DateTime.fromRFC2822(timestamp, dateOpts));
this._date.isValid || (this._date = luxon.DateTime.fromSQL(timestamp, dateOpts));
// RFC2822-like format without the required timezone offset (used in tests)
this._date.isValid || (this._date = luxon.DateTime.fromFormat(timestamp, 'EEE, d MMM yyyy HH:mm:ss', dateOpts));
}
if (!this._date || !this._date.isValid) {
throw new Error('CronDate: unhandled timestamp: ' + JSON.stringify(timestamp));
}
if (tz && tz !== this._date.zoneName) {
this._date = this._date.setZone(tz);
}
}
module.exports = CronDate;
This diff is collapsed. Click to expand it.
'use strict';
function buildRange(item) {
return {
start: item,
count: 1
};
}
function completeRangeWithItem(range, item) {
range.end = item;
range.step = item - range.start;
range.count = 2;
}
function finalizeCurrentRange(results, currentRange, currentItemRange) {
if (currentRange) {
// Two elements do not form a range so split them into 2 single elements
if (currentRange.count === 2) {
results.push(buildRange(currentRange.start));
results.push(buildRange(currentRange.end));
} else {
results.push(currentRange);
}
}
if (currentItemRange) {
results.push(currentItemRange);
}
}
function compactField(arr) {
var results = [];
var currentRange = undefined;
for (var i = 0; i < arr.length; i++) {
var currentItem = arr[i];
if (typeof currentItem !== 'number') {
// String elements can't form a range
finalizeCurrentRange(results, currentRange, buildRange(currentItem));
currentRange = undefined;
} else if (!currentRange) {
// Start a new range
currentRange = buildRange(currentItem);
} else if (currentRange.count === 1) {
// Guess that the current item starts a range
completeRangeWithItem(currentRange, currentItem);
} else {
if (currentRange.step === currentItem - currentRange.end) {
// We found another item that matches the current range
currentRange.count++;
currentRange.end = currentItem;
} else if (currentRange.count === 2) { // The current range can't be continued
// Break the first item of the current range into a single element, and try to start a new range with the second item
results.push(buildRange(currentRange.start));
currentRange = buildRange(currentRange.end);
completeRangeWithItem(currentRange, currentItem);
} else {
// Persist the current range and start a new one with current item
finalizeCurrentRange(results, currentRange);
currentRange = buildRange(currentItem);
}
}
}
finalizeCurrentRange(results, currentRange);
return results;
}
module.exports = compactField;
'use strict';
var compactField = require('./field_compactor');
function stringifyField(arr, min, max) {
var ranges = compactField(arr);
if (ranges.length === 1) {
var singleRange = ranges[0];
var step = singleRange.step;
if (step === 1 && singleRange.start === min && singleRange.end === max) {
return '*';
}
if (step !== 1 && singleRange.start === min && singleRange.end === max - step + 1) {
return '*/' + step;
}
}
var resultArr = [];
for (var i = 0, l = ranges.length; i < l; ++i) {
var range = ranges[i];
if (range.count === 1) {
resultArr.push(range.start);
} else {
var step = range.step;
if (step === 1) {
resultArr.push(range.start + '-' + range.end);
} else {
if (range.end === max - step + 1) {
resultArr.push(range.start + '/' + step);
} else {
resultArr.push(range.start + '-' + range.end + '/' + step);
}
}
}
}
return resultArr.join(',');
}
module.exports = stringifyField;
'use strict';
var CronExpression = require('./expression');
function CronParser() {}
/**
* Parse crontab entry
*
* @private
* @param {String} entry Crontab file entry/line
*/
CronParser._parseEntry = function _parseEntry (entry) {
var atoms = entry.split(' ');
if (atoms.length === 6) {
return {
interval: CronExpression.parse(entry)
};
} else if (atoms.length > 6) {
return {
interval: CronExpression.parse(
atoms.slice(0, 6).join(' ')
),
command: atoms.slice(6, atoms.length)
};
} else {
throw new Error('Invalid entry: ' + entry);
}
};
/**
* Wrapper for CronExpression.parser method
*
* @public
* @param {String} expression Input expression
* @param {Object} [options] Parsing options
* @return {Object}
*/
CronParser.parseExpression = function parseExpression (expression, options) {
return CronExpression.parse(expression, options);
};
/**
* Wrapper for CronExpression.fieldsToExpression method
*
* @public
* @param {Object} fields Input fields
* @param {Object} [options] Parsing options
* @return {Object}
*/
CronParser.fieldsToExpression = function fieldsToExpression (fields, options) {
return CronExpression.fieldsToExpression(fields, options);
};
/**
* Parse content string
*
* @public
* @param {String} data Crontab content
* @return {Object}
*/
CronParser.parseString = function parseString (data) {
var blocks = data.split('\n');
var response = {
variables: {},
expressions: [],
errors: {}
};
for (var i = 0, c = blocks.length; i < c; i++) {
var block = blocks[i];
var matches = null;
var entry = block.trim(); // Remove surrounding spaces
if (entry.length > 0) {
if (entry.match(/^#/)) { // Comment
continue;
} else if ((matches = entry.match(/^(.*)=(.*)$/))) { // Variable
response.variables[matches[1]] = matches[2];
} else { // Expression?
var result = null;
try {
result = CronParser._parseEntry('0 ' + entry);
response.expressions.push(result.interval);
} catch (err) {
response.errors[entry] = err;
}
}
}
}
return response;
};
/**
* Parse crontab file
*
* @public
* @param {String} filePath Path to file
* @param {Function} callback
*/
CronParser.parseFile = function parseFile (filePath, callback) {
require('fs').readFile(filePath, function(err, data) {
if (err) {
callback(err);
return;
}
return callback(null, CronParser.parseString(data.toString()));
});
};
module.exports = CronParser;
{
"name": "cron-parser",
"version": "3.5.0",
"description": "Node.js library for parsing crontab instructions",
"main": "lib/parser.js",
"types": "index.d.ts",
"typesVersions": {
"<4.1": {
"*": [
"types/ts3/*"
]
}
},
"directories": {
"test": "test"
},
"scripts": {
"test:tsd": "tsd",
"test:unit": "TZ=UTC tap ./test/*.js",
"test:cover": "TZ=UTC tap --coverage-report=html ./test/*.js",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"test": "npm run lint && npm run test:unit && npm run test:tsd"
},
"repository": {
"type": "git",
"url": "https://github.com/harrisiirak/cron-parser.git"
},
"keywords": [
"cron",
"crontab",
"parser"
],
"author": "Harri Siirak",
"contributors": [
"Nicholas Clawson",
"Daniel Prentis <daniel@salsitasoft.com>",
"Renault John Lecoultre",
"Richard Astbury <richard.astbury@gmail.com>",
"Meaglin Wasabi <Meaglin.wasabi@gmail.com>",
"Mike Kusold <hello@mikekusold.com>",
"Alex Kit <alex.kit@atmajs.com>",
"Santiago Gimeno <santiago.gimeno@gmail.com>",
"Daniel <darc.tec@gmail.com>",
"Christian Steininger <christian.steininger.cs@gmail.com>",
"Mykola Piskovyi <m.piskovyi@gmail.com>",
"Brian Vaughn <brian.david.vaughn@gmail.com>",
"Nicholas Clawson <nickclaw@gmail.com>",
"Yasuhiroki <yasuhiroki.duck@gmail.com>",
"Nicholas Clawson <nickclaw@gmail.com>",
"Brendan Warkentin <faazshift@gmail.com>",
"Charlie Fish <fishcharlie.code@gmail.com>",
"Ian Graves <ian+diskimage@iangrav.es>",
"Andy Thompson <me@andytson.com>",
"Regev Brody <regevbr@gmail.com>"
],
"license": "MIT",
"dependencies": {
"is-nan": "^1.3.2",
"luxon": "^1.26.0"
},
"devDependencies": {
"eslint": "^7.24.0",
"sinon": "^10.0.0",
"tap": "^15.0.3",
"tsd": "^0.14.0"
},
"engines": {
"node": ">=0.8"
},
"browser": {
"fs": false
},
"tap": {
"check-coverage": false
},
"tsd": {
"directory": "test",
"compilerOptions": {
"lib": [
"es2017",
"dom"
]
}
}
}
var util = require('util');
var test = require('tap').test;
var expression = require('../lib/expression');
test('expression 31 of month', function(t) {
try {
var interval = expression.parse('0 0 31 * *');
var i;
var d;
for (i = 0; i < 20; ++i) {
d = interval.next();
}
t.end();
} catch (err) {
t.error(err, 'Interval parse error');
}
});
var util = require('util');
var test = require('tap').test;
var CronExpression = require('../lib/expression');
var CronDate = require('../lib/date');
test('parse expression as UTC', function(t) {
try {
var options = {
utc: true
};
var interval = CronExpression.parse('0 0 10 * * *', options);
var date = interval.next();
t.equal(date.getUTCHours(), 10, 'Correct UTC hour value');
interval = CronExpression.parse('0 */5 * * * *', options);
var date = interval.next(), now = new Date();
now.setMinutes(now.getMinutes() + 5 - (now.getMinutes() % 5));
t.equal(date.getHours(), now.getUTCHours(), 'Correct local time for 5 minute interval');
} catch (err) {
t.error(err, 'UTC parse error');
}
t.end();
});
# Comment line (ignore)
ENV1="test1"
ENV2="test2"
*/10 * * * * /path/to/exe
*/10 * * * * /path/to/exe
0 09-18 * * 1-5 /path/to/exe
\ No newline at end of file
// empty around comma
var test = require('tap').test;
var CronExpression = require('../lib/expression');
const options = {
utc: true
};
test('both empty around comma', function (t) {
t.throws(function () {
CronExpression.parse('*/10 * * * * ,', options);
}, new Error('Invalid list value format'));
t.end();
});
test('one side empty around comma', function (t) {
t.throws(function () {
CronExpression.parse('*/10 * * * * ,2', options);
}, new Error('Invalid list value format'));
t.end();
});
This diff is collapsed. Click to expand it.
'use strict';
var test = require('tap').test;
var compactField = require('../lib/field_compactor');
test('compact field - empty array', function(t) {
try {
var result = compactField([]);
t.same(result, []);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - single element array', function(t) {
try {
var result = compactField([1]);
t.same(result, [{
start: 1,
count: 1
}]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - 2 elements array', function(t) {
try {
var result = compactField([1, 2]);
t.same(result, [
{
start: 1,
count: 1
},
{
start: 2,
count: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - 2 elements array big step', function(t) {
try {
var result = compactField([1, 5]);
t.same(result, [
{
start: 1,
count: 1
},
{
start: 5,
count: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - 3 elements array 1 step', function(t) {
try {
var result = compactField([1, 2, 3]);
t.same(result, [
{
start: 1,
end: 3,
count: 3,
step: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - 3 elements array 1 step, dangling extra at end', function(t) {
try {
var result = compactField([1, 2, 3, 5]);
t.same(result, [
{
start: 1,
end: 3,
count: 3,
step: 1
},
{
start: 5,
count: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - 3 elements array 1 step, dangling extra at end and beginning', function(t) {
try {
var result = compactField([1, 4, 5, 6, 9]);
t.same(result, [
{
start: 1,
count: 1
},
{
start: 4,
end: 6,
count: 3,
step: 1
},
{
start: 9,
count: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - 2 ranges with dangling in the middle', function(t) {
try {
var result = compactField([1, 2, 3, 6, 9, 11, 13]);
t.same(result, [
{
start: 1,
end: 3,
count: 3,
step: 1
},
{
start: 6,
count: 1
},
{
start: 9,
end: 13,
count: 3,
step: 2
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - with chars', function(t) {
try {
var result = compactField(['L', 'W']);
t.same(result, [
{
start: 'L',
count: 1
},
{
start: 'W',
count: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - with chars and range', function(t) {
try {
var result = compactField([1, 'L', 'W']);
t.same(result, [
{
start: 1,
count: 1,
},
{
start: 'L',
count: 1
},
{
start: 'W',
count: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - with chars and range (v2)', function(t) {
try {
var result = compactField([1, 2, 'L', 'W']);
t.same(result, [
{
start: 1,
count: 1,
},
{
start: 2,
count: 1,
},
{
start: 'L',
count: 1
},
{
start: 'W',
count: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
test('compact field - with chars and range (v3)', function(t) {
try {
var result = compactField([1, 2, 3, 'L', 'W']);
t.same(result, [
{
start: 1,
end: 3,
count: 3,
step: 1
},
{
start: 'L',
count: 1
},
{
start: 'W',
count: 1
}
]);
} catch (err) {
t.error(err, 'compact field error');
}
t.end();
});
'use strict';
var test = require('tap').test;
var stringifyField = require('../lib/field_stringify');
test('stringify astrix', function (t) {
try {
var str = stringifyField([1, 2, 3, 4], 1, 4);
t.equal(str, '*');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify astrix step', function (t) {
try {
var str = stringifyField([0, 2, 4, 6], 0, 7);
t.equal(str, '*/2');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify single value', function (t) {
try {
var str = stringifyField([2], 0, 7);
t.equal(str, '2');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify multiple single values', function (t) {
try {
var str = stringifyField([2, 5, 9], 0, 7);
t.equal(str, '2,5,9');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify range', function (t) {
try {
var str = stringifyField([2, 3, 4], 0, 7);
t.equal(str, '2-4');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify range step', function (t) {
try {
var str = stringifyField([2, 4, 6], 0, 8);
t.equal(str, '2-6/2');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify semi range step', function (t) {
try {
var str = stringifyField([4, 6, 8], 0, 9);
t.equal(str, '4/2');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify multi types', function (t) {
try {
var str = stringifyField([1, 2, 4, 5, 6, 7, 8, 9, 10, 20, 25, 30, 35, 57], 0, 59);
t.equal(str, '1,2,4-10,20-35/5,57');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
var test = require('tap').test;
var CronExpression = require('../lib/expression');
test('Fields are exposed', function(t){
try {
var interval = CronExpression.parse('0 1 2 3 * 1-3,5');
t.ok(interval, 'Interval parsed');
CronExpression.map.forEach(function(field) {
interval.fields[field] = [];
t.throws(function() {
interval.fields[field].push(-1);
}, /Cannot add property .*?, object is not extensible/, field + ' is frozen');
delete interval.fields[field];
});
interval.fields.dummy = [];
t.same(interval.fields.dummy, undefined, 'Fields is frozen');
t.same(interval.fields.second, [0], 'Second matches');
t.same(interval.fields.minute, [1], 'Minute matches');
t.same(interval.fields.hour, [2], 'Hour matches');
t.same(interval.fields.dayOfMonth, [3], 'Day of month matches');
t.same(interval.fields.month, [1,2,3,4,5,6,7,8,9,10,11,12], 'Month matches');
t.same(interval.fields.dayOfWeek, [1,2,3,5], 'Day of week matches');
} catch (err) {
t.error(err, 'Interval parse error');
}
t.end();
});
var util = require('util');
var sinon = require('sinon');
var test = require('tap').test;
var CronExpression = require('../lib/expression');
test('increment_on_first_itereation', function(t) {
try {
var clock = sinon.useFakeTimers();
var fake_now = new Date('Tue Feb 21 2017 16:45:00');
clock.tick(fake_now.getTime());
var interval = CronExpression.parse('* * * * *');
t.ok(interval, 'Interval parsed');
var next = interval.next();
t.ok(next, 'Found next scheduled interval');
// Make sure next has incremented in 1 minute
t.equal(fake_now.getTime() + 60000, next.getTime());
clock.restore();
t.end();
} catch (err) {
t.error(err, 'Interval parse error');
}
});
import {expectAssignable, expectError, expectNotAssignable, expectType} from 'tsd';
import {
CronDate,
CronExpression,
CronFields, DateType,
parseExpression,
parseFile, ParserOptions,
parseString,
fieldsToExpression,
StringResult
} from '../types/ts3';
const interval = parseExpression('0 1 2 3 * 1-3,5');
const intervalIterator = parseExpression('0 1 2 3 * 1-3,5', {iterator: true});
expectType<readonly number[]>(interval.fields.second);
expectType<readonly number[]>(interval.fields.minute);
expectType<readonly number[]>(interval.fields.hour);
expectType<readonly (number | 'L')[]>(interval.fields.dayOfMonth);
expectType<readonly number[]>(interval.fields.month);
expectType<readonly number[]>(interval.fields.dayOfWeek);
expectError(interval.fields = interval.fields);
expectError(interval.fields.second = []);
expectError(interval.fields.second.push(1));
expectError(interval.fields.minute = []);
expectError(interval.fields.minute.push(1));
expectError(interval.fields.hour = []);
expectError(interval.fields.hour.push(1));
expectError(interval.fields.dayOfMonth = []);
expectError(interval.fields.dayOfMonth.push(1));
expectError(interval.fields.month = []);
expectError(interval.fields.month.push(1));
expectError(interval.fields.dayOfWeek = []);
expectError(interval.fields.dayOfWeek.push(1));
expectAssignable<typeof interval.fields.second[0]>(0);
expectAssignable<typeof interval.fields.second[0]>(59);
expectAssignable<typeof interval.fields.minute[0]>(0);
expectAssignable<typeof interval.fields.minute[0]>(59);
expectAssignable<typeof interval.fields.hour[0]>(0);
expectAssignable<typeof interval.fields.hour[0]>(23);
expectAssignable<typeof interval.fields.dayOfMonth[0]>(1);
expectAssignable<typeof interval.fields.dayOfMonth[0]>(31);
expectAssignable<typeof interval.fields.dayOfMonth[0]>('L');
expectAssignable<typeof interval.fields.month[0]>(1);
expectAssignable<typeof interval.fields.month[0]>(12);
expectAssignable<typeof interval.fields.dayOfWeek[0]>(0);
expectAssignable<typeof interval.fields.dayOfWeek[0]>(7);
const parseOptions: ParserOptions<true> = {
currentDate: 'f',
startDate: 4,
endDate: new Date(),
iterator: true,
utc: true,
tz: 'f',
nthDayOfWeek: 5,
}
expectAssignable<{
currentDate?: string | number | Date
startDate?: string | number | Date
endDate?: string | number | Date
iterator?: boolean
utc?: boolean
tz?: string
nthDayOfWeek?: number
}>(parseOptions)
expectType<CronExpression>(parseExpression('0 1 2 3 * 1-3,5'))
expectType<CronExpression<true>>(parseExpression('0 1 2 3 * 1-3,5', parseOptions))
const fields: CronFields = {
second: [1, 1],
minute: [1],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
}
expectType<CronExpression>(fieldsToExpression(fields))
expectType<CronExpression<true>>(fieldsToExpression(fields, parseOptions))
expectType<string>(fieldsToExpression(fields).stringify())
expectType<string>(fieldsToExpression(fields, parseOptions).stringify())
expectType<string>(fieldsToExpression(fields, parseOptions).stringify(true))
expectType<void>(parseFile('path', (err: any, data: StringResult) => console.log(data)))
expectType<StringResult>(parseString('path'))
const stringResult = parseString('path');
expectType<{
variables: Record<string, string>,
expressions: CronExpression[],
errors: Record<string, any>,
}>(stringResult)
expectType<CronFields>(interval.fields)
expectType<CronDate>(interval.next())
expectType<CronDate>(interval.prev())
expectType<boolean>(interval.hasNext())
expectType<boolean>(interval.hasPrev())
expectType<string>(interval.stringify())
expectType<string>(interval.stringify(true))
expectType<void>(interval.reset())
expectType<void>(interval.reset("Sdf"))
expectType<void>(interval.reset(5))
expectType<void>(interval.reset(new Date()))
expectType<CronDate[]>(interval.iterate(5))
expectType<CronDate[]>(interval.iterate(5, (item: CronDate, i: number) => {}))
expectAssignable<DateType>(new Date())
expectAssignable<DateType>(5)
expectAssignable<DateType>("SDf")
expectType<IteratorResult<CronDate, CronDate>>(intervalIterator.next())
expectType<IteratorResult<CronDate, CronDate>>(intervalIterator.prev())
expectType<IteratorResult<CronDate, CronDate>[]>(intervalIterator.iterate(5))
expectType<IteratorResult<CronDate, CronDate>[]>(intervalIterator.iterate(5, (item: IteratorResult<CronDate, CronDate>, i: number) => {}))
import {expectAssignable, expectError, expectNotAssignable, expectType} from 'tsd';
import {
CronDate,
CronExpression,
CronFields, DateType,
parseExpression,
parseFile, ParserOptions,
parseString,
fieldsToExpression,
StringResult
} from '../index';
const interval = parseExpression('0 1 2 3 * 1-3,5');
const intervalIterator = parseExpression('0 1 2 3 * 1-3,5', {iterator: true});
expectError(interval.fields = interval.fields);
expectError(interval.fields.second = []);
expectError(interval.fields.second.push(1));
expectError(interval.fields.minute = []);
expectError(interval.fields.minute.push(1));
expectError(interval.fields.hour = []);
expectError(interval.fields.hour.push(1));
expectError(interval.fields.dayOfMonth = []);
expectError(interval.fields.dayOfMonth.push(1));
expectError(interval.fields.month = []);
expectError(interval.fields.month.push(1));
expectError(interval.fields.dayOfWeek = []);
expectError(interval.fields.dayOfWeek.push(1));
expectAssignable<typeof interval.fields.second[0]>(0);
expectAssignable<typeof interval.fields.second[0]>(59);
expectNotAssignable<typeof interval.fields.second[0]>(-1);
expectNotAssignable<typeof interval.fields.second[0]>(60);
expectAssignable<typeof interval.fields.minute[0]>(0);
expectAssignable<typeof interval.fields.minute[0]>(59);
expectNotAssignable<typeof interval.fields.minute[0]>(-1);
expectNotAssignable<typeof interval.fields.minute[0]>(60);
expectAssignable<typeof interval.fields.hour[0]>(0);
expectAssignable<typeof interval.fields.hour[0]>(23);
expectNotAssignable<typeof interval.fields.hour[0]>(-1);
expectNotAssignable<typeof interval.fields.hour[0]>(24);
expectAssignable<typeof interval.fields.dayOfMonth[0]>(1);
expectAssignable<typeof interval.fields.dayOfMonth[0]>(31);
expectAssignable<typeof interval.fields.dayOfMonth[0]>('L');
expectNotAssignable<typeof interval.fields.dayOfMonth[0]>(0);
expectNotAssignable<typeof interval.fields.dayOfMonth[0]>(32);
expectAssignable<typeof interval.fields.month[0]>(1);
expectAssignable<typeof interval.fields.month[0]>(12);
expectNotAssignable<typeof interval.fields.month[0]>(0);
expectNotAssignable<typeof interval.fields.month[0]>(13);
expectAssignable<typeof interval.fields.dayOfWeek[0]>(0);
expectAssignable<typeof interval.fields.dayOfWeek[0]>(7);
expectNotAssignable<typeof interval.fields.dayOfWeek[0]>(-1);
expectNotAssignable<typeof interval.fields.dayOfWeek[0]>(8);
const parseOptions: ParserOptions<true> = {
currentDate: 'f',
startDate: 4,
endDate: new Date(),
iterator: true,
utc: true,
tz: 'f',
nthDayOfWeek: 5,
}
expectAssignable<{
currentDate?: string | number | Date
startDate?: string | number | Date
endDate?: string | number | Date
iterator?: boolean
utc?: boolean
tz?: string
nthDayOfWeek?: number
}>(parseOptions)
expectType<CronExpression>(parseExpression('0 1 2 3 * 1-3,5'))
expectType<CronExpression<true>>(parseExpression('0 1 2 3 * 1-3,5', parseOptions))
const fields: CronFields = {
second: [1, 1],
minute: [1],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
}
expectType<CronExpression>(fieldsToExpression(fields))
expectType<CronExpression<true>>(fieldsToExpression(fields, parseOptions))
expectType<string>(fieldsToExpression(fields).stringify())
expectType<string>(fieldsToExpression(fields, parseOptions).stringify())
expectType<string>(fieldsToExpression(fields, parseOptions).stringify(true))
expectType<void>(parseFile('path', (err: any, data: StringResult) => console.log(data)))
expectType<StringResult>(parseString('path'))
const stringResult = parseString('path');
expectType<{
variables: Record<string, string>,
expressions: CronExpression[],
errors: Record<string, any>,
}>(stringResult)
expectType<CronFields>(interval.fields)
expectType<CronDate>(interval.next())
expectType<CronDate>(interval.prev())
expectType<boolean>(interval.hasNext())
expectType<boolean>(interval.hasPrev())
expectType<string>(interval.stringify())
expectType<string>(interval.stringify(true))
expectType<void>(interval.reset())
expectType<void>(interval.reset("Sdf"))
expectType<void>(interval.reset(5))
expectType<void>(interval.reset(new Date()))
expectType<CronDate[]>(interval.iterate(5))
expectType<CronDate[]>(interval.iterate(5, (item: CronDate, i: number) => {}))
expectAssignable<DateType>(new Date())
expectAssignable<DateType>(5)
expectAssignable<DateType>("SDf")
expectType<IteratorResult<CronDate, CronDate>>(intervalIterator.next())
expectType<IteratorResult<CronDate, CronDate>>(intervalIterator.prev())
expectType<IteratorResult<CronDate, CronDate>[]>(intervalIterator.iterate(5))
expectType<IteratorResult<CronDate, CronDate>[]>(intervalIterator.iterate(5, (item: IteratorResult<CronDate, CronDate>, i: number) => {}))
var util = require('util');
var test = require('tap').test;
var expression = require('../lib/expression');
test('leap year', function(t) {
try {
var interval = expression.parse('0 0 29 2 *');
var i;
var d;
for (i = 0; i < 20; ++i) {
d = interval.next();
}
t.end();
} catch (err) {
t.error(err, 'Interval parse error');
}
});
var test = require('tap').test;
var CronParser = require('../lib/parser');
// Globals
test('load crontab file', function(t) {
CronParser.parseFile(__dirname + '/crontab.example', function(err, result) {
t.error(err, 'File read error');
t.ok(result, 'Crontab parsed parsed');
t.equal(Object.keys(result.variables).length, 2, 'variables length matches');
t.equal(Object.keys(result.errors).length, 0, 'errors length matches');
t.equal(result.expressions.length, 3, 'expressions length matches');
// Parse expressions
var next = null;
t.equal(result.expressions[0].hasNext(), true);
next = result.expressions[0].next();
t.ok(next, 'first date');
next = result.expressions[1].next();
t.ok(next, 'second date');
next = result.expressions[2].next();
t.ok(next, 'third date');
t.end();
});
});
test('no next date', function(t) {
var options = {
currentDate: new Date(2014, 0, 1),
endDate: new Date(2014, 0, 1)
};
try {
var interval = CronParser.parseExpression('* * 2 * *', options);
t.equal(interval.hasNext(), false);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
var luxon = require('luxon');
var test = require('tap').test;
var CronDate = require('../lib/date');
test('parse cron date formats with local timezone', (t) => {
// Some tests need the local offset to be compatible without invoking timezone management.
// Local offset is dependent on what the system being tested on is
var offset = new Date().getTimezoneOffset();
var offsetHours = Math.abs(Math.floor(offset/60));
var offsetMinutes = offset % 60;
var offsetSign = offset < 0 ? '-' : '+';
var expectedTime = new Date(2021, 0, 4, 10, 0, 0).toString();
test('undefined date', (t) => {
const realDate = new Date();
var d = new CronDate();
t.equal(d.toDate().toString(), realDate.toString());
t.end();
});
test('JS Date', (t) => {
var d = new CronDate(new Date(2021, 0, 4, 10, 0, 0));
t.equal(d.toDate().toString(), expectedTime);
t.end();
});
test('ISO 8601', (t) => {
var d = new CronDate('2021-01-04T10:00:00');
t.equal(d.toDate().toString(), expectedTime);
t.end();
});
test('ISO 8601 date', (t) => {
var d = new CronDate('2021-01-04');
var expectedTime = new Date(2021, 0, 4, 0, 0, 0).toString();
t.equal(d.toDate().toString(), expectedTime);
t.end();
});
test('RFC2822', (t) => {
var offsetString = offsetSign + String(offsetHours).padStart(2, 0) + String(offsetMinutes).padStart(2, 0);
var d = new CronDate('Mon, 4 Jan 2021 10:00:00 ' + offsetString);
t.equal(d.toDate().toString(), expectedTime);
t.end();
});
test('RFC2822-like without timezone offset', (t) => {
var d = new CronDate('Mon, 4 Jan 2021 10:00:00');
t.equal(d.toDate().toString(), expectedTime);
t.end();
});
test('SQL', (t) => {
var d = new CronDate('2021-01-04 10:00:00');
t.equal(d.toDate().toString(), expectedTime);
t.end();
});
test('milliseconds', (t) => {
var d = new CronDate(new Date('2021-01-04 10:00:00').valueOf());
t.equal(d.toDate().toString(), expectedTime);
t.end();
});
test('CronDate', (t) => {
var date = new CronDate('Mon, 4 Jan 2021 10:00:00');
var d = new CronDate(date);
t.equal(d.toDate().toString(), expectedTime);
t.end();
});
test('invalid', (t) => {
t.throws(() => {
var d = new CronDate('2021-01-4 10:00:00');
});
t.end();
});
t.end();
});
test('parse cron date formats with another timezone', (t) => {
test('ISO 8601 without offset', (t) => {
// implies format already in timezone
var d = new CronDate('2021-01-04T10:00:00', 'Europe/Athens');
t.equal(d.toISOString(), '2021-01-04T08:00:00.000Z');
t.end();
});
test('ISO 8601 with non-local offset', (t) => {
var d = new CronDate('2021-01-04T10:00:00+01:00', 'Europe/Athens');
t.equal(d.toISOString(), '2021-01-04T09:00:00.000Z');
t.end();
});
test('RFC2822 with non-local offset', (t) => {
var d = new CronDate('Mon, 4 Jan 2021 10:00:00 +0100', 'Europe/Athens');
t.equal(d.toISOString(), '2021-01-04T09:00:00.000Z');
t.end();
});
test('milliseconds', (t) => {
var date = luxon.DateTime.fromISO('2021-01-04T11:00:00.000+02:00').valueOf();
var d = new CronDate(date, 'Europe/Athens');
t.equal(d.toISOString(), '2021-01-04T09:00:00.000Z');
t.end();
});
test('CronDate with same timezone', (t) => {
var date = new CronDate('Mon, 4 Jan 2021 10:00:00', 'Europe/Athens');
var d = new CronDate(date);
t.equal(d.toISOString(), '2021-01-04T08:00:00.000Z');
t.end();
});
test('CronDate with different timezone', (t) => {
var date = new CronDate('Mon, 4 Jan 2021 10:00:00', 'America/New_York');
var d = new CronDate(date, 'Europe/Athens');
t.equal(d.toISOString(), '2021-01-04T15:00:00.000Z');
t.end();
});
t.end('crondate input should');
});
var util = require('util');
var test = require('tap').test;
var CronParser = require('../lib/parser');
test('parse cron with last day in a month', function(t) {
var options = {
currentDate: new Date(2014, 0, 1),
endDate: new Date(2014, 10, 1)
};
try {
var interval = CronParser.parseExpression('0 0 L * *', options);
t.equal(interval.hasNext(), true);
for (i = 0; i < 10; ++i) {
var next = interval.next();
t.ok(next, 'has a date');
}
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('parse cron with last day in feb', function(t) {
var options = {
currentDate: new Date(2016, 0, 1),
endDate: new Date(2016, 10, 1)
};
try {
var interval = CronParser.parseExpression('0 0 6-20/2,L 2 *', options);
t.equal(interval.hasNext(), true);
var next = null;
var items = 9;
var i = 0;
while(interval.hasNext()) {
next = interval.next();
i += 1;
t.ok(next, 'has a date');
}
//leap year
t.equal(next.getDate(), 29);
t.equal(i, items);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('parse cron with last day in feb', function(t) {
var options = {
currentDate: new Date(2014, 0, 1),
endDate: new Date(2014, 10, 1)
};
try {
var interval = CronParser.parseExpression('0 0 1,3,6-10,L 2 *', options);
t.equal(interval.hasNext(), true);
var next = null;
while(interval.hasNext()) {
next = interval.next();
t.ok(next, 'has a date');
}
//common year
t.equal(next.getDate(), 28);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
var test = require('tap').test;
var CronExpression = require('../lib/expression');
test('prev should match correctly (issue #98) when milliseconds are greater than 0', function(t) {
var options = {
currentDate: new Date('2017-06-13T18:21:25.002Z')
};
var interval = CronExpression.parse('*/5 * * * * *', options);
var prev = interval.prev();
t.equal(prev.getSeconds(), 25);
t.end();
});
test('prev should match correctly (issue #98) when milliseconds are equal to 0', function(t) {
var interval = CronExpression.parse('59 59 23 * * *',{
currentDate : new Date('2012-12-26 14:38:53')
});
[25, 24, 23, 22].forEach(function(date) {
var prev = interval.prev();
t.equal(prev.getFullYear(), 2012);
t.equal(prev.getMonth(), 11);
t.equal(prev.getDate(), date);
t.equal(prev.getHours(), 23);
t.equal(prev.getMinutes(), 59);
t.equal(prev.getSeconds(), 59);
});
t.end();
});
'use strict';
var test = require('tap').test;
var CronParser = require('../lib/parser');
test('stringify cron expression all stars no seconds', function (t) {
try {
var expected = '0 * * * * *';
var interval = CronParser.parseExpression('* * * * *', {});
var str = interval.stringify(true);
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify(true);
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression all stars no seconds (discard seconds)', function (t) {
try {
var expected = '* * * * *';
var interval = CronParser.parseExpression('* * * * *', {});
var str = interval.stringify();
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify();
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression all stars with seconds', function (t) {
try {
var expected = '* * * * * *';
var interval = CronParser.parseExpression('* * * * * *', {});
var str = interval.stringify(true);
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify(true);
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression all stars with seconds (discard seconds)', function (t) {
try {
var expected = '* * * * *';
var interval = CronParser.parseExpression('* * * * * *', {});
var str = interval.stringify();
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify();
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression', function (t) {
try {
var expected = '0 1,2,4-10,20-35/5,57 * * * *';
var interval = CronParser.parseExpression('1,2,4-10,20-35/5,57 * * * *', {});
var str = interval.stringify(true);
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify(true);
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression (discard seconds)', function (t) {
try {
var expected = '1,2,4-10,20-35/5,57 * * * *';
var interval = CronParser.parseExpression('1,2,4-10,20-35/5,57 * * * *', {});
var str = interval.stringify();
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify();
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression with star range step', function (t) {
try {
var expected = '0 */5 */2 * * *';
var interval = CronParser.parseExpression('*/5 */2 */1 * *', {});
var str = interval.stringify(true);
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify(true);
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression with star range step (discard seconds)', function (t) {
try {
var expected = '*/5 */2 * * *';
var interval = CronParser.parseExpression('*/5 */2 */1 * *', {});
var str = interval.stringify();
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify();
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression with semi range step', function (t) {
try {
var expected = '0 5/5 * * * *';
var interval = CronParser.parseExpression('5/5 * * * *', {});
var str = interval.stringify(true);
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify(true);
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression with semi range step (discard seconds)', function (t) {
try {
var expected = '5/5 * * * *';
var interval = CronParser.parseExpression('5/5 * * * *', {});
var str = interval.stringify();
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify();
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression with L', function (t) {
try {
var expected = '0 * * 1,4-10,L * *';
var interval = CronParser.parseExpression('* * 1,4-10,L * *', {});
var str = interval.stringify(true);
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify(true);
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify cron expression with L (discard seconds)', function (t) {
try {
var expected = '* * 1,4-10,L * *';
var interval = CronParser.parseExpression('* * 1,4-10,L * *', {});
var str = interval.stringify();
t.equal(str, expected);
str = CronParser.fieldsToExpression(interval.fields).stringify();
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify from fields out of order', function (t) {
try {
var expected = '1-5 1 1 1 1 1';
var str = CronParser.fieldsToExpression({
second: [5,2,1,4,3],
minute: [1],
hour: [1],
month: [1],
dayOfMonth: [1],
dayOfWeek: [1],
}).stringify(true);
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('stringify from fields out of order (discard seconds)', function (t) {
try {
var expected = '1 1 1 1 1';
var str = CronParser.fieldsToExpression({
second: [5,2,1,4,3],
minute: [1],
hour: [1],
month: [1],
dayOfMonth: [1],
dayOfWeek: [1],
}).stringify();
t.equal(str, expected);
} catch (err) {
t.error(err, 'Parse read error');
}
t.end();
});
test('validation error - missing seconds', function (t) {
t.throws(function () {
CronParser.fieldsToExpression({
minute: [1],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
});
}, new Error('Validation error, Field second is missing'));
t.end();
});
test('validation error - empty seconds', function (t) {
t.throws(function () {
CronParser.fieldsToExpression({
second: [],
minute: [1],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
});
}, new Error('Validation error, Field second contains no values'));
t.end();
});
test('validation error - missing values - empty array', function (t) {
t.throws(function () {
CronParser.fieldsToExpression({
second: [1],
minute: [],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
});
}, new Error('Validation error, Field minute contains no values'));
t.end();
});
test('validation error - missing values', function (t) {
t.throws(function () {
CronParser.fieldsToExpression({
second: [1],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
});
}, new Error('Validation error, Field minute is missing'));
t.end();
});
test('validation error - range error', function (t) {
t.throws(function () {
CronParser.fieldsToExpression({
second: [-1, 1, 0],
minute: [1],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
});
}, new Error('Constraint error, got value -1 expected range 0-59'));
t.end();
});
test('validation error - bad chars error', function (t) {
t.throws(function () {
CronParser.fieldsToExpression({
second: [0, 'R'],
minute: [1],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
});
}, new Error('Constraint error, got value R expected range 0-59'));
t.end();
});
test('validation error - duplicates', function (t) {
t.throws(function () {
CronParser.fieldsToExpression({
second: [1, 1],
minute: [1],
hour: [1],
dayOfMonth: [1],
month: [1],
dayOfWeek: [1],
});
}, new Error('Validation error, Field second contains duplicate values'));
t.end();
});
This diff is collapsed. Click to expand it.
export type DateType = Date | number | string
export interface CronDate {
addYear(): void
addMonth(): void
addDay(): void
addHour(): void
addMinute(): void
addSecond(): void
subtractYear(): void
subtractMonth(): void
subtractDay(): void
subtractHour(): void
subtractMinute(): void
subtractSecond(): void
getDate(): number
getFullYear(): number
getDay(): number
getMonth(): number
getHours(): number
getMinutes(): number
getSeconds(): number
getMilliseconds(): number
getTime(): number
getUTCDate(): number
getUTCFullYear(): number
getUTCDay(): number
getUTCMonth(): number
getUTCHours(): number
getUTCMinutes(): number
getUTCSeconds(): number
toISOString(): string
toJSON(): string
setDate(d: number): void
setFullYear(y: number): void
setDay(d: number): void
setMonth(m: number): void
setHours(h: number): void
setMinutes(m: number): void
setSeconds(s: number): void
setMilliseconds(s: number): void
getTime(): number
toString(): string
toDate(): Date
isLastDayOfMonth(): boolean
}
export interface ParserOptions<IsIterable extends boolean = false> {
currentDate?: DateType
startDate?: DateType
endDate?: DateType
utc?: boolean
tz?: string
nthDayOfWeek?: number
iterator?: IsIterable
}
type IteratorResultOrCronDate<IsIterable extends boolean> = IsIterable extends true
? IteratorResult<CronDate, CronDate>
: CronDate;
export interface ICronExpression<CronFields, IsIterable extends boolean> {
readonly fields: CronFields;
/** Find next suitable date */
next(): IteratorResultOrCronDate<IsIterable>
/** Find previous suitable date */
prev(): IteratorResultOrCronDate<IsIterable>
/** Check if next suitable date exists */
hasNext(): boolean
/** Check if previous suitable date exists */
hasPrev(): boolean
/** Iterate over expression iterator */
iterate(steps: number, callback?: (item: IteratorResultOrCronDate<IsIterable>, i: number) => void): IteratorResultOrCronDate<IsIterable>[]
/** Reset expression iterator state */
reset(resetDate?: string | number | Date): void
stringify(includeSeconds?: boolean): string
}
export interface IStringResult<CronFields> {
variables: Record<string, string>,
expressions: ICronExpression<CronFields, false>[],
errors: Record<string, any>,
}
import {
CronDate,
DateType,
ICronExpression,
IStringResult,
ParserOptions,
} from './common';
type BuildRangeTuple<Current extends [...number[]], Count extends number> =
Current["length"] extends Count
? Current
: BuildRangeTuple<[number, ...Current], Count>
type RangeTuple<Count extends number> = BuildRangeTuple<[], Count>
type BuildRange<Current extends number, End extends number, Accu extends [...number[]]> =
Accu["length"] extends End
? Current
: BuildRange<Current | Accu["length"], End, [number, ...Accu]>
type Range<StartInclusive extends number, EndExclusive extends number> = BuildRange<StartInclusive, EndExclusive, RangeTuple<StartInclusive>>
export type SixtyRange = Range<0, 30> | Range<30, 60>; // Typescript restriction on recursion depth
export type HourRange = Range<0, 24>;
export type DayOfTheMonthRange = Range<1, 32> | 'L';
export type MonthRange = Range<1, 13>;
export type DayOfTheWeekRange = Range<0, 8>;
export type CronFields = {
readonly second: readonly SixtyRange[];
readonly minute: readonly SixtyRange[];
readonly hour: readonly HourRange[];
readonly dayOfMonth: readonly DayOfTheMonthRange[];
readonly month: readonly MonthRange[];
readonly dayOfWeek: readonly DayOfTheWeekRange[];
}
export {ParserOptions, CronDate, DateType}
export type CronExpression<IsIterable extends boolean = false> = ICronExpression<CronFields, IsIterable>
export type StringResult = IStringResult<CronFields>
export function parseExpression<IsIterable extends boolean = false>(expression: string, options?: ParserOptions<IsIterable>): CronExpression<IsIterable>;
export function fieldsToExpression<IsIterable extends boolean = false>(fields: CronFields, options?: ParserOptions<IsIterable>): CronExpression<IsIterable>;
export function parseFile(filePath: string, callback: (err: any, data: StringResult) => any): void;
export function parseString(data: string): StringResult;
import {
CronDate,
DateType,
ICronExpression,
IStringResult,
ParserOptions,
} from '../common';
export type CronFields = {
readonly second: readonly number[];
readonly minute: readonly number[];
readonly hour: readonly number[];
readonly dayOfMonth: readonly (number | 'L')[];
readonly month: readonly number[];
readonly dayOfWeek: readonly number[];
}
export {ParserOptions, CronDate, DateType}
export type CronExpression<IsIterable extends boolean = false> = ICronExpression<CronFields, IsIterable>
export type StringResult = IStringResult<CronFields>
export function parseExpression<IsIterable extends boolean = false>(expression: string, options?: ParserOptions<IsIterable>): CronExpression<IsIterable>;
export function fieldsToExpression<IsIterable extends boolean = false>(fields: CronFields, options?: ParserOptions<IsIterable>): CronExpression<IsIterable>;
export function parseFile(filePath: string, callback: (err: any, data: StringResult) => any): void;
export function parseString(data: string): StringResult;
root = true
[*]
indent_style = tab;
insert_final_newline = true;
quote_type = auto;
space_after_anonymous_functions = true;
space_after_control_statements = true;
spaces_around_operators = true;
trim_trailing_whitespace = true;
spaces_in_brackets = false;
end_of_line = lf;
{
"root": true,
"extends": "@ljharb",
"rules": {
"id-length": [2, { "min": 1, "max": 35 }],
"max-lines-per-function": [2, 100],
"max-params": [2, 4],
"max-statements": [2, 13]
}
}
{
"es3": true,
"additionalRules": [],
"requireSemicolons": true,
"disallowMultipleSpaces": true,
"disallowIdentifierNames": [],
"requireCurlyBraces": {
"allExcept": [],
"keywords": ["if", "else", "for", "while", "do", "try", "catch"]
},
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"],
"disallowSpaceAfterKeywords": [],
"disallowSpaceBeforeComma": true,
"disallowSpaceAfterComma": false,
"disallowSpaceBeforeSemicolon": true,
"disallowNodeTypes": [
"DebuggerStatement",
"LabeledStatement",
"SwitchCase",
"SwitchStatement",
"WithStatement"
],
"requireObjectKeysOnNewLine": { "allExcept": ["sameLine"] },
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true },
"requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true },
"requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true },
"requireSpaceBetweenArguments": true,
"disallowSpacesInsideParentheses": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowQuotedKeysInObjects": { "allExcept": ["reserved"] },
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"requireSpaceAfterPrefixUnaryOperators": [],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforePostfixUnaryOperators": [],
"disallowSpaceBeforeBinaryOperators": [],
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"disallowSpaceAfterBinaryOperators": [],
"disallowImplicitTypeConversion": ["binary", "string"],
"disallowKeywords": ["with", "eval"],
"requireKeywordsOnNewLine": [],
"disallowKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"excludeFiles": ["node_modules/**", "vendor/**"],
"disallowMultipleLineStrings": true,
"requireDotNotation": { "allExcept": ["keywords"] },
"requireParenthesesAroundIIFE": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": {
"escape": true,
"mark": "'"
},
"disallowOperatorBeforeLineBreak": [],
"requireSpaceBeforeKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"finally",
"while",
"with",
"return"
],
"validateAlignedFunctionParameters": {
"lineBreakAfterOpeningBraces": true,
"lineBreakBeforeClosingBraces": true
},
"requirePaddingNewLinesBeforeExport": true,
"validateNewlineAfterArrayElements": {
"maximum": 3
},
"requirePaddingNewLinesAfterUseStrict": true,
"disallowArrowFunctions": true,
"disallowMultiLineTernary": true,
"validateOrderInObjectKeys": "asc-insensitive",
"disallowIdenticalDestructuringNames": true,
"disallowNestedTernaries": { "maxLevel": 1 },
"requireSpaceAfterComma": { "allExcept": ["trailing"] },
"requireAlignedMultilineParams": false,
"requireSpacesInGenerator": {
"afterStar": true
},
"disallowSpacesInGenerator": {
"beforeStar": true
},
"disallowVar": false,
"requireArrayDestructuring": false,
"requireEnhancedObjectLiterals": false,
"requireObjectDestructuring": false,
"requireEarlyReturn": false,
"requireCapitalizedConstructorsNew": {
"allExcept": ["Function", "String", "Object", "Symbol", "Number", "Date", "RegExp", "Error", "Boolean", "Array"]
},
"requireImportAlphabetized": false,
"requireSpaceBeforeObjectValues": true,
"requireSpaceBeforeDestructuredValues": true,
"disallowSpacesInsideTemplateStringPlaceholders": true,
"disallowArrayDestructuringReturn": false,
"requireNewlineBeforeSingleStatementsInIf": false,
"disallowUnusedVariables": true,
"requireSpacesInsideImportedObjectBraces": true,
"requireUseStrict": true
}
language: node_js
os:
- linux
node_js:
- "10.8"
- "9.11"
- "8.11"
- "7.10"
- "6.14"
- "5.12"
- "4.9"
- "iojs-v3.3"
- "iojs-v2.5"
- "iojs-v1.8"
- "0.12"
- "0.10"
- "0.8"
before_install:
- 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac'
- 'nvm install-latest-npm'
install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
script:
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
- 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi'
- 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi'
- 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi'
sudo: false
env:
- TEST=true
matrix:
fast_finish: true
include:
- node_js: "lts/*"
env: PRETEST=true
- node_js: "lts/*"
env: POSTTEST=true
- node_js: "4"
env: COVERAGE=true
- node_js: "10.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.13"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.12"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.11"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.11"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v3.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v3.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v3.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "0.11"
env: TEST=true ALLOW_FAILURE=true
- node_js: "0.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "0.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "0.4"
env: TEST=true ALLOW_FAILURE=true
allow_failures:
- os: osx
- env: TEST=true ALLOW_FAILURE=true
- env: COVERAGE=true
1.1.3 / 2018-08-14
=================
* [Refactor] use a for loop instead of `foreach` to make for smaller bundle sizes
* [Robustness] cache `Array.prototype.concat` and `Object.defineProperty`
* [Deps] update `object-keys`
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `nsp`, `tape`, `jscs`; remove unused eccheck script + dep
* [Tests] use pretest/posttest for linting/security
* [Tests] fix npm upgrades on older nodes
1.1.2 / 2015-10-14
=================
* [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG
* [Deps] Update `object-keys`
* [Dev Deps] update `jscs`, `tape`, `eslint`, `@ljharb/eslint-config`, `nsp`
* [Tests] up to `io.js` `v3.3`, `node` `v4.2`
1.1.1 / 2015-07-21
=================
* [Deps] Update `object-keys`
* [Dev Deps] Update `tape`, `eslint`
* [Tests] Test on `io.js` `v2.4`
1.1.0 / 2015-07-01
=================
* [New] Add support for symbol-valued properties.
* [Dev Deps] Update `nsp`, `eslint`
* [Tests] Test up to `io.js` `v2.3`
1.0.3 / 2015-05-30
=================
* Using a more reliable check for supported property descriptors.
1.0.2 / 2015-05-23
=================
* Test up to `io.js` `v2.0`
* Update `tape`, `jscs`, `nsp`, `eslint`, `object-keys`, `editorconfig-tools`, `covert`
1.0.1 / 2015-01-06
=================
* Update `object-keys` to fix ES3 support
1.0.0 / 2015-01-04
=================
* v1.0.0
The MIT License (MIT)
Copyright (C) 2015 Jordan Harband
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.
\ No newline at end of file
#define-properties <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
[![Build Status][travis-svg]][travis-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
[![browser support][testling-svg]][testling-url]
Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.
Existing properties are not overridden. Accepts a map of property names to a predicate that, when true, force-overrides.
## Example
```js
var define = require('define-properties');
var assert = require('assert');
var obj = define({ a: 1, b: 2 }, {
a: 10,
b: 20,
c: 30
});
assert(obj.a === 1);
assert(obj.b === 2);
assert(obj.c === 30);
if (define.supportsDescriptors) {
assert.deepEqual(Object.keys(obj), ['a', 'b']);
assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'c'), {
configurable: true,
enumerable: false,
value: 30,
writable: false
});
}
```
Then, with predicates:
```js
var define = require('define-properties');
var assert = require('assert');
var obj = define({ a: 1, b: 2, c: 3 }, {
a: 10,
b: 20,
c: 30
}, {
a: function () { return false; },
b: function () { return true; }
});
assert(obj.a === 1);
assert(obj.b === 20);
assert(obj.c === 3);
if (define.supportsDescriptors) {
assert.deepEqual(Object.keys(obj), ['a', 'c']);
assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'b'), {
configurable: true,
enumerable: false,
value: 20,
writable: false
});
}
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/define-properties
[npm-version-svg]: http://versionbadg.es/ljharb/define-properties.svg
[travis-svg]: https://travis-ci.org/ljharb/define-properties.svg
[travis-url]: https://travis-ci.org/ljharb/define-properties
[deps-svg]: https://david-dm.org/ljharb/define-properties.svg
[deps-url]: https://david-dm.org/ljharb/define-properties
[dev-deps-svg]: https://david-dm.org/ljharb/define-properties/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/define-properties#info=devDependencies
[testling-svg]: https://ci.testling.com/ljharb/define-properties.png
[testling-url]: https://ci.testling.com/ljharb/define-properties
[npm-badge-png]: https://nodei.co/npm/define-properties.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/define-properties.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/define-properties.svg
[downloads-url]: http://npm-stat.com/charts.html?package=define-properties
'use strict';
var keys = require('object-keys');
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
var toStr = Object.prototype.toString;
var concat = Array.prototype.concat;
var origDefineProperty = Object.defineProperty;
var isFunction = function (fn) {
return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
};
var arePropertyDescriptorsSupported = function () {
var obj = {};
try {
origDefineProperty(obj, 'x', { enumerable: false, value: obj });
// eslint-disable-next-line no-unused-vars, no-restricted-syntax
for (var _ in obj) { // jscs:ignore disallowUnusedVariables
return false;
}
return obj.x === obj;
} catch (e) { /* this is IE 8. */
return false;
}
};
var supportsDescriptors = origDefineProperty && arePropertyDescriptorsSupported();
var defineProperty = function (object, name, value, predicate) {
if (name in object && (!isFunction(predicate) || !predicate())) {
return;
}
if (supportsDescriptors) {
origDefineProperty(object, name, {
configurable: true,
enumerable: false,
value: value,
writable: true
});
} else {
object[name] = value;
}
};
var defineProperties = function (object, map) {
var predicates = arguments.length > 2 ? arguments[2] : {};
var props = keys(map);
if (hasSymbols) {
props = concat.call(props, Object.getOwnPropertySymbols(map));
}
for (var i = 0; i < props.length; i += 1) {
defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
}
};
defineProperties.supportsDescriptors = !!supportsDescriptors;
module.exports = defineProperties;
{
"name": "define-properties",
"version": "1.1.3",
"author": "Jordan Harband",
"description": "Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.",
"license": "MIT",
"main": "index.js",
"scripts": {
"pretest": "npm run --silent lint",
"test": "npm run --silent tests-only",
"posttest": "npm run --silent security",
"tests-only": "node test/index.js",
"coverage": "covert test/*.js",
"coverage-quiet": "covert test/*.js --quiet",
"lint": "npm run --silent jscs && npm run --silent eslint",
"jscs": "jscs test/*.js *.js",
"eslint": "eslint test/*.js *.js",
"security": "nsp check"
},
"repository": {
"type": "git",
"url": "git://github.com/ljharb/define-properties.git"
},
"keywords": [
"Object.defineProperty",
"Object.defineProperties",
"object",
"property descriptor",
"descriptor",
"define",
"ES5"
],
"dependencies": {
"object-keys": "^1.0.12"
},
"devDependencies": {
"@ljharb/eslint-config": "^13.0.0",
"covert": "^1.1.0",
"eslint": "^5.3.0",
"jscs": "^3.0.7",
"nsp": "^3.2.1",
"tape": "^4.9.0"
},
"testling": {
"files": "test/index.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"
]
},
"engines": {
"node": ">= 0.4"
}
}
'use strict';
var define = require('../');
var test = require('tape');
var keys = require('object-keys');
var arePropertyDescriptorsSupported = function () {
var obj = { a: 1 };
try {
Object.defineProperty(obj, 'x', { value: obj });
return obj.x === obj;
} catch (e) { /* this is IE 8. */
return false;
}
};
var descriptorsSupported = !!Object.defineProperty && arePropertyDescriptorsSupported();
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
test('defineProperties', function (dt) {
dt.test('with descriptor support', { skip: !descriptorsSupported }, function (t) {
var getDescriptor = function (value) {
return {
configurable: true,
enumerable: false,
value: value,
writable: true
};
};
var obj = {
a: 1,
b: 2,
c: 3
};
t.deepEqual(keys(obj), ['a', 'b', 'c'], 'all literal-set keys start enumerable');
define(obj, {
b: 3,
c: 4,
d: 5
});
t.deepEqual(obj, {
a: 1,
b: 2,
c: 3
}, 'existing properties were not overridden');
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'd'), getDescriptor(5), 'new property "d" was added and is not enumerable');
t.deepEqual(['a', 'b', 'c'], keys(obj), 'new keys are not enumerable');
define(obj, {
a: 2,
b: 3,
c: 4
}, {
a: function () { return true; },
b: function () { return false; }
});
t.deepEqual(obj, {
b: 2,
c: 3
}, 'properties only overriden when predicate exists and returns true');
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'd'), getDescriptor(5), 'existing property "d" remained and is not enumerable');
t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'a'), getDescriptor(2), 'existing property "a" was overridden and is not enumerable');
t.deepEqual(['b', 'c'], keys(obj), 'overridden keys are not enumerable');
t.end();
});
dt.test('without descriptor support', { skip: descriptorsSupported }, function (t) {
var obj = {
a: 1,
b: 2,
c: 3
};
define(obj, {
b: 3,
c: 4,
d: 5
});
t.deepEqual(obj, {
a: 1,
b: 2,
c: 3,
d: 5
}, 'existing properties were not overridden, new properties were added');
define(obj, {
a: 2,
b: 3,
c: 4
}, {
a: function () { return true; },
b: function () { return false; }
});
t.deepEqual(obj, {
a: 2,
b: 2,
c: 3,
d: 5
}, 'properties only overriden when predicate exists and returns true');
t.end();
});
dt.end();
});
test('symbols', { skip: !hasSymbols }, function (t) {
var sym = Symbol('foo');
var obj = {};
var aValue = {};
var bValue = {};
var properties = { a: aValue };
properties[sym] = bValue;
define(obj, properties);
t.deepEqual(Object.keys(obj), [], 'object has no enumerable keys');
t.deepEqual(Object.getOwnPropertyNames(obj), ['a'], 'object has non-enumerable "a" key');
t.deepEqual(Object.getOwnPropertySymbols(obj), [sym], 'object has non-enumerable symbol key');
t.equal(obj.a, aValue, 'string keyed value is defined');
t.equal(obj[sym], bValue, 'symbol keyed value is defined');
t.end();
});
root = true
[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120
[CHANGELOG.md]
indent_style = space
indent_size = 2
[*.json]
max_line_length = off
[Makefile]
max_line_length = off
{
"root": true,
"extends": "@ljharb",
"rules": {
"func-name-matching": 0,
"indent": [2, 4],
"max-nested-callbacks": [2, 3],
"max-params": [2, 3],
"max-statements": [2, 20],
"no-new-func": [1],
"strict": [0]
}
}
{
"es3": true,
"additionalRules": [],
"requireSemicolons": true,
"disallowMultipleSpaces": true,
"disallowIdentifierNames": [],
"requireCurlyBraces": {
"allExcept": [],
"keywords": ["if", "else", "for", "while", "do", "try", "catch"]
},
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"],
"disallowSpaceAfterKeywords": [],
"disallowSpaceBeforeComma": true,
"disallowSpaceAfterComma": false,
"disallowSpaceBeforeSemicolon": true,
"disallowNodeTypes": [
"DebuggerStatement",
"ForInStatement",
"LabeledStatement",
"SwitchCase",
"SwitchStatement",
"WithStatement"
],
"requireObjectKeysOnNewLine": { "allExcept": ["sameLine"] },
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true },
"requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true },
"requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true },
"requireSpaceBetweenArguments": true,
"disallowSpacesInsideParentheses": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowQuotedKeysInObjects": { "allExcept": ["reserved"] },
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"requireSpaceAfterPrefixUnaryOperators": [],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforePostfixUnaryOperators": [],
"disallowSpaceBeforeBinaryOperators": [],
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"disallowSpaceAfterBinaryOperators": [],
"disallowImplicitTypeConversion": ["binary", "string"],
"disallowKeywords": ["with", "eval"],
"requireKeywordsOnNewLine": [],
"disallowKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"excludeFiles": ["node_modules/**", "vendor/**"],
"disallowMultipleLineStrings": true,
"requireDotNotation": { "allExcept": ["keywords"] },
"requireParenthesesAroundIIFE": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": {
"escape": true,
"mark": "'"
},
"disallowOperatorBeforeLineBreak": [],
"requireSpaceBeforeKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"finally",
"while",
"with",
"return"
],
"validateAlignedFunctionParameters": {
"lineBreakAfterOpeningBraces": true,
"lineBreakBeforeClosingBraces": true
},
"requirePaddingNewLinesBeforeExport": true,
"validateNewlineAfterArrayElements": {
"maximum": 8
},
"requirePaddingNewLinesAfterUseStrict": true,
"disallowArrowFunctions": true,
"disallowMultiLineTernary": true,
"validateOrderInObjectKeys": "asc-insensitive",
"disallowIdenticalDestructuringNames": true,
"disallowNestedTernaries": { "maxLevel": 1 },
"requireSpaceAfterComma": { "allExcept": ["trailing"] },
"requireAlignedMultilineParams": false,
"requireSpacesInGenerator": {
"afterStar": true
},
"disallowSpacesInGenerator": {
"beforeStar": true
},
"disallowVar": false,
"requireArrayDestructuring": false,
"requireEnhancedObjectLiterals": false,
"requireObjectDestructuring": false,
"requireEarlyReturn": false,
"requireCapitalizedConstructorsNew": {
"allExcept": ["Function", "String", "Object", "Symbol", "Number", "Date", "RegExp", "Error", "Boolean", "Array"]
},
"requireImportAlphabetized": false,
"requireSpaceBeforeObjectValues": true,
"requireSpaceBeforeDestructuredValues": true,
"disallowSpacesInsideTemplateStringPlaceholders": true,
"disallowArrayDestructuringReturn": false,
"requireNewlineBeforeSingleStatementsInIf": false,
"disallowUnusedVariables": true,
"requireSpacesInsideImportedObjectBraces": true,
"requireUseStrict": true
}
# gitignore
.DS_Store
.monitor
.*.swp
.nodemonignore
releases
*.log
*.err
fleet.json
public/browserify
bin/*.json
.bin
build
compile
.lock-wscript
coverage
node_modules
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
language: node_js
os:
- linux
node_js:
- "8.4"
- "7.10"
- "6.11"
- "5.12"
- "4.8"
- "iojs-v3.3"
- "iojs-v2.5"
- "iojs-v1.8"
- "0.12"
- "0.10"
- "0.8"
before_install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g npm@1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi'
- 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ] || [ "${TRAVIS_NODE_VERSION:0:4}" = "iojs" ]; then npm install -g npm@4.5 ; else npm install -g npm; fi; fi'
install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g npm@1.3 && npm install -g npm@1.4.28 && npm install -g npm@2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
script:
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
- 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi'
- 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi'
- 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi'
sudo: false
env:
- TEST=true
matrix:
fast_finish: true
include:
- node_js: "node"
env: PRETEST=true
- node_js: "4"
env: COVERAGE=true
- node_js: "8.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.11"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "5.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "4.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v3.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v3.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v3.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v2.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "iojs-v1.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "0.11"
env: TEST=true ALLOW_FAILURE=true
- node_js: "0.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "0.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "0.4"
env: TEST=true ALLOW_FAILURE=true
allow_failures:
- os: osx
- env: TEST=true ALLOW_FAILURE=true
Copyright (c) 2013 Raynos.
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.
# function-bind
<!--
[![build status][travis-svg]][travis-url]
[![NPM version][npm-badge-svg]][npm-url]
[![Coverage Status][5]][6]
[![gemnasium Dependency Status][7]][8]
[![Dependency status][deps-svg]][deps-url]
[![Dev Dependency status][dev-deps-svg]][dev-deps-url]
-->
<!-- [![browser support][11]][12] -->
Implementation of function.prototype.bind
## Example
I mainly do this for unit tests I run on phantomjs.
PhantomJS does not have Function.prototype.bind :(
```js
Function.prototype.bind = require("function-bind")
```
## Installation
`npm install function-bind`
## Contributors
- Raynos
## MIT Licenced
[travis-svg]: https://travis-ci.org/Raynos/function-bind.svg
[travis-url]: https://travis-ci.org/Raynos/function-bind
[npm-badge-svg]: https://badge.fury.io/js/function-bind.svg
[npm-url]: https://npmjs.org/package/function-bind
[5]: https://coveralls.io/repos/Raynos/function-bind/badge.png
[6]: https://coveralls.io/r/Raynos/function-bind
[7]: https://gemnasium.com/Raynos/function-bind.png
[8]: https://gemnasium.com/Raynos/function-bind
[deps-svg]: https://david-dm.org/Raynos/function-bind.svg
[deps-url]: https://david-dm.org/Raynos/function-bind
[dev-deps-svg]: https://david-dm.org/Raynos/function-bind/dev-status.svg
[dev-deps-url]: https://david-dm.org/Raynos/function-bind#info=devDependencies
[11]: https://ci.testling.com/Raynos/function-bind.png
[12]: https://ci.testling.com/Raynos/function-bind
'use strict';
/* eslint no-invalid-this: 1 */
var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
var slice = Array.prototype.slice;
var toStr = Object.prototype.toString;
var funcType = '[object Function]';
module.exports = function bind(that) {
var target = this;
if (typeof target !== 'function' || toStr.call(target) !== funcType) {
throw new TypeError(ERROR_MESSAGE + target);
}
var args = slice.call(arguments, 1);
var bound;
var binder = function () {
if (this instanceof bound) {
var result = target.apply(
this,
args.concat(slice.call(arguments))
);
if (Object(result) === result) {
return result;
}
return this;
} else {
return target.apply(
that,
args.concat(slice.call(arguments))
);
}
};
var boundLength = Math.max(0, target.length - args.length);
var boundArgs = [];
for (var i = 0; i < boundLength; i++) {
boundArgs.push('$' + i);
}
bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
if (target.prototype) {
var Empty = function Empty() {};
Empty.prototype = target.prototype;
bound.prototype = new Empty();
Empty.prototype = null;
}
return bound;
};
'use strict';
var implementation = require('./implementation');
module.exports = Function.prototype.bind || implementation;
{
"name": "function-bind",
"version": "1.1.1",
"description": "Implementation of Function.prototype.bind",
"keywords": [
"function",
"bind",
"shim",
"es5"
],
"author": "Raynos <raynos2@gmail.com>",
"repository": "git://github.com/Raynos/function-bind.git",
"main": "index",
"homepage": "https://github.com/Raynos/function-bind",
"contributors": [
{
"name": "Raynos"
},
{
"name": "Jordan Harband",
"url": "https://github.com/ljharb"
}
],
"bugs": {
"url": "https://github.com/Raynos/function-bind/issues",
"email": "raynos2@gmail.com"
},
"dependencies": {},
"devDependencies": {
"@ljharb/eslint-config": "^12.2.1",
"covert": "^1.1.0",
"eslint": "^4.5.0",
"jscs": "^3.0.7",
"tape": "^4.8.0"
},
"license": "MIT",
"scripts": {
"pretest": "npm run lint",
"test": "npm run tests-only",
"posttest": "npm run coverage -- --quiet",
"tests-only": "node test",
"coverage": "covert test/*.js",
"lint": "npm run jscs && npm run eslint",
"jscs": "jscs *.js */*.js",
"eslint": "eslint *.js */*.js"
},
"testling": {
"files": "test/index.js",
"browsers": [
"ie/8..latest",
"firefox/16..latest",
"firefox/nightly",
"chrome/22..latest",
"chrome/canary",
"opera/12..latest",
"opera/next",
"safari/5.1..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
]
}
}
{
"rules": {
"array-bracket-newline": 0,
"array-element-newline": 0,
"max-statements-per-line": [2, { "max": 2 }],
"no-invalid-this": 0,
"no-magic-numbers": 0,
}
}
// jscs:disable requireUseStrict
var test = require('tape');
var functionBind = require('../implementation');
var getCurrentContext = function () { return this; };
test('functionBind is a function', function (t) {
t.equal(typeof functionBind, 'function');
t.end();
});
test('non-functions', function (t) {
var nonFunctions = [true, false, [], {}, 42, 'foo', NaN, /a/g];
t.plan(nonFunctions.length);
for (var i = 0; i < nonFunctions.length; ++i) {
try { functionBind.call(nonFunctions[i]); } catch (ex) {
t.ok(ex instanceof TypeError, 'throws when given ' + String(nonFunctions[i]));
}
}
t.end();
});
test('without a context', function (t) {
t.test('binds properly', function (st) {
var args, context;
var namespace = {
func: functionBind.call(function () {
args = Array.prototype.slice.call(arguments);
context = this;
})
};
namespace.func(1, 2, 3);
st.deepEqual(args, [1, 2, 3]);
st.equal(context, getCurrentContext.call());
st.end();
});
t.test('binds properly, and still supplies bound arguments', function (st) {
var args, context;
var namespace = {
func: functionBind.call(function () {
args = Array.prototype.slice.call(arguments);
context = this;
}, undefined, 1, 2, 3)
};
namespace.func(4, 5, 6);
st.deepEqual(args, [1, 2, 3, 4, 5, 6]);
st.equal(context, getCurrentContext.call());
st.end();
});
t.test('returns properly', function (st) {
var args;
var namespace = {
func: functionBind.call(function () {
args = Array.prototype.slice.call(arguments);
return this;
}, null)
};
var context = namespace.func(1, 2, 3);
st.equal(context, getCurrentContext.call(), 'returned context is namespaced context');
st.deepEqual(args, [1, 2, 3], 'passed arguments are correct');
st.end();
});
t.test('returns properly with bound arguments', function (st) {
var args;
var namespace = {
func: functionBind.call(function () {
args = Array.prototype.slice.call(arguments);
return this;
}, null, 1, 2, 3)
};
var context = namespace.func(4, 5, 6);
st.equal(context, getCurrentContext.call(), 'returned context is namespaced context');
st.deepEqual(args, [1, 2, 3, 4, 5, 6], 'passed arguments are correct');
st.end();
});
t.test('called as a constructor', function (st) {
var thunkify = function (value) {
return function () { return value; };
};
st.test('returns object value', function (sst) {
var expectedReturnValue = [1, 2, 3];
var Constructor = functionBind.call(thunkify(expectedReturnValue), null);
var result = new Constructor();
sst.equal(result, expectedReturnValue);
sst.end();
});
st.test('does not return primitive value', function (sst) {
var Constructor = functionBind.call(thunkify(42), null);
var result = new Constructor();
sst.notEqual(result, 42);
sst.end();
});
st.test('object from bound constructor is instance of original and bound constructor', function (sst) {
var A = function (x) {
this.name = x || 'A';
};
var B = functionBind.call(A, null, 'B');
var result = new B();
sst.ok(result instanceof B, 'result is instance of bound constructor');
sst.ok(result instanceof A, 'result is instance of original constructor');
sst.end();
});
st.end();
});
t.end();
});
test('with a context', function (t) {
t.test('with no bound arguments', function (st) {
var args, context;
var boundContext = {};
var namespace = {
func: functionBind.call(function () {
args = Array.prototype.slice.call(arguments);
context = this;
}, boundContext)
};
namespace.func(1, 2, 3);
st.equal(context, boundContext, 'binds a context properly');
st.deepEqual(args, [1, 2, 3], 'supplies passed arguments');
st.end();
});
t.test('with bound arguments', function (st) {
var args, context;
var boundContext = {};
var namespace = {
func: functionBind.call(function () {
args = Array.prototype.slice.call(arguments);
context = this;
}, boundContext, 1, 2, 3)
};
namespace.func(4, 5, 6);
st.equal(context, boundContext, 'binds a context properly');
st.deepEqual(args, [1, 2, 3, 4, 5, 6], 'supplies bound and passed arguments');
st.end();
});
t.test('returns properly', function (st) {
var boundContext = {};
var args;
var namespace = {
func: functionBind.call(function () {
args = Array.prototype.slice.call(arguments);
return this;
}, boundContext)
};
var context = namespace.func(1, 2, 3);
st.equal(context, boundContext, 'returned context is bound context');
st.notEqual(context, getCurrentContext.call(), 'returned context is not lexical context');
st.deepEqual(args, [1, 2, 3], 'passed arguments are correct');
st.end();
});
t.test('returns properly with bound arguments', function (st) {
var boundContext = {};
var args;
var namespace = {
func: functionBind.call(function () {
args = Array.prototype.slice.call(arguments);
return this;
}, boundContext, 1, 2, 3)
};
var context = namespace.func(4, 5, 6);
st.equal(context, boundContext, 'returned context is bound context');
st.notEqual(context, getCurrentContext.call(), 'returned context is not lexical context');
st.deepEqual(args, [1, 2, 3, 4, 5, 6], 'passed arguments are correct');
st.end();
});
t.test('passes the correct arguments when called as a constructor', function (st) {
var expected = { name: 'Correct' };
var namespace = {
Func: functionBind.call(function (arg) {
return arg;
}, { name: 'Incorrect' })
};
var returned = new namespace.Func(expected);
st.equal(returned, expected, 'returns the right arg when called as a constructor');
st.end();
});
t.test('has the new instance\'s context when called as a constructor', function (st) {
var actualContext;
var expectedContext = { foo: 'bar' };
var namespace = {
Func: functionBind.call(function () {
actualContext = this;
}, expectedContext)
};
var result = new namespace.Func();
st.equal(result instanceof namespace.Func, true);
st.notEqual(actualContext, expectedContext);
st.end();
});
t.end();
});
test('bound function length', function (t) {
t.test('sets a correct length without thisArg', function (st) {
var subject = functionBind.call(function (a, b, c) { return a + b + c; });
st.equal(subject.length, 3);
st.equal(subject(1, 2, 3), 6);
st.end();
});
t.test('sets a correct length with thisArg', function (st) {
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, {});
st.equal(subject.length, 3);
st.equal(subject(1, 2, 3), 6);
st.end();
});
t.test('sets a correct length without thisArg and first argument', function (st) {
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, undefined, 1);
st.equal(subject.length, 2);
st.equal(subject(2, 3), 6);
st.end();
});
t.test('sets a correct length with thisArg and first argument', function (st) {
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, {}, 1);
st.equal(subject.length, 2);
st.equal(subject(2, 3), 6);
st.end();
});
t.test('sets a correct length without thisArg and too many arguments', function (st) {
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, undefined, 1, 2, 3, 4);
st.equal(subject.length, 0);
st.equal(subject(), 6);
st.end();
});
t.test('sets a correct length with thisArg and too many arguments', function (st) {
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, {}, 1, 2, 3, 4);
st.equal(subject.length, 0);
st.equal(subject(), 6);
st.end();
});
});
{
"root": true,
"extends": "@ljharb",
"env": {
"es6": true,
"es2017": true,
"es2020": true,
"es2021": true,
},
"globals": {
"AggregateError": false,
},
"rules": {
"array-bracket-newline": 0,
"array-element-newline": 0,
"complexity": 0,
"eqeqeq": [2, "allow-null"],
"func-name-matching": 0,
"id-length": 0,
"max-lines-per-function": [2, 80],
"max-params": [2, 4],
"max-statements": 0,
"max-statements-per-line": [2, { "max": 2 }],
"multiline-comment-style": 0,
"no-magic-numbers": 0,
"operator-linebreak": [2, "before"],
"sort-keys": 0,
},
"overrides": [
{
"files": "test/**",
"rules": {
"max-lines-per-function": 0,
"new-cap": 0,
},
},
],
}
# 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/get-intrinsic
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']
{
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"lines": 86,
"statements": 85.93,
"functions": 82.43,
"branches": 76.06,
"exclude": [
"coverage",
"test"
]
}
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.1.1](https://github.com/ljharb/get-intrinsic/compare/v1.1.0...v1.1.1) - 2021-02-03
### Fixed
- [meta] export `./package.json` [`#9`](https://github.com/ljharb/get-intrinsic/issues/9)
### Commits
- [readme] flesh out the readme; use `evalmd` [`d12f12c`](https://github.com/ljharb/get-intrinsic/commit/d12f12c15345a0a0772cc65a7c64369529abd614)
- [eslint] set up proper globals config [`5a8c098`](https://github.com/ljharb/get-intrinsic/commit/5a8c0984e3319d1ac0e64b102f8ec18b64e79f36)
- [Dev Deps] update `eslint` [`7b9a5c0`](https://github.com/ljharb/get-intrinsic/commit/7b9a5c0d31a90ca1a1234181c74988fb046701cd)
## [v1.1.0](https://github.com/ljharb/get-intrinsic/compare/v1.0.2...v1.1.0) - 2021-01-25
### Fixed
- [Refactor] delay `Function` eval until syntax-derived values are requested [`#3`](https://github.com/ljharb/get-intrinsic/issues/3)
### Commits
- [Tests] migrate tests to Github Actions [`2ab762b`](https://github.com/ljharb/get-intrinsic/commit/2ab762b48164aea8af37a40ba105bbc8246ab8c4)
- [meta] do not publish github action workflow files [`5e7108e`](https://github.com/ljharb/get-intrinsic/commit/5e7108e4768b244d48d9567ba4f8a6cab9c65b8e)
- [Tests] add some coverage [`01ac7a8`](https://github.com/ljharb/get-intrinsic/commit/01ac7a87ac29738567e8524cd8c9e026b1fa8cb3)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `call-bind`, `es-abstract`, `tape`; add `call-bind` [`911b672`](https://github.com/ljharb/get-intrinsic/commit/911b672fbffae433a96924c6ce013585e425f4b7)
- [Refactor] rearrange evalled constructors a bit [`7e7e4bf`](https://github.com/ljharb/get-intrinsic/commit/7e7e4bf583f3799c8ac1c6c5e10d2cb553957347)
- [meta] add Automatic Rebase and Require Allow Edits workflows [`0199968`](https://github.com/ljharb/get-intrinsic/commit/01999687a263ffce0a3cb011dfbcb761754aedbc)
## [v1.0.2](https://github.com/ljharb/get-intrinsic/compare/v1.0.1...v1.0.2) - 2020-12-17
### Commits
- [Fix] Throw for non‑existent intrinsics [`68f873b`](https://github.com/ljharb/get-intrinsic/commit/68f873b013c732a05ad6f5fc54f697e55515461b)
- [Fix] Throw for non‑existent segments in the intrinsic path [`8325dee`](https://github.com/ljharb/get-intrinsic/commit/8325deee43128f3654d3399aa9591741ebe17b21)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `has-bigints`, `object-inspect` [`0c227a7`](https://github.com/ljharb/get-intrinsic/commit/0c227a7d8b629166f25715fd242553892e458525)
- [meta] do not lint coverage output [`70d2419`](https://github.com/ljharb/get-intrinsic/commit/70d24199b620043cd9110fc5f426d214ebe21dc9)
## [v1.0.1](https://github.com/ljharb/get-intrinsic/compare/v1.0.0...v1.0.1) - 2020-10-30
### Commits
- [Tests] gather coverage data on every job [`d1d280d`](https://github.com/ljharb/get-intrinsic/commit/d1d280dec714e3f0519cc877dbcb193057d9cac6)
- [Fix] add missing dependencies [`5031771`](https://github.com/ljharb/get-intrinsic/commit/5031771bb1095b38be88ce7c41d5de88718e432e)
- [Tests] use `es-value-fixtures` [`af48765`](https://github.com/ljharb/get-intrinsic/commit/af48765a23c5323fb0b6b38dbf00eb5099c7bebc)
## v1.0.0 - 2020-10-29
### Commits
- Implementation [`bbce57c`](https://github.com/ljharb/get-intrinsic/commit/bbce57c6f33d05b2d8d3efa273ceeb3ee01127bb)
- Tests [`17b4f0d`](https://github.com/ljharb/get-intrinsic/commit/17b4f0d56dea6b4059b56fc30ef3ee4d9500ebc2)
- Initial commit [`3153294`](https://github.com/ljharb/get-intrinsic/commit/31532948de363b0a27dd9fd4649e7b7028ec4b44)
- npm init [`fb326c4`](https://github.com/ljharb/get-intrinsic/commit/fb326c4d2817c8419ec31de1295f06bb268a7902)
- [meta] add Automatic Rebase and Require Allow Edits workflows [`48862fb`](https://github.com/ljharb/get-intrinsic/commit/48862fb2508c8f6a57968e6d08b7c883afc9d550)
- [meta] add `auto-changelog` [`5f28ad0`](https://github.com/ljharb/get-intrinsic/commit/5f28ad019e060a353d8028f9f2591a9cc93074a1)
- [meta] add "funding"; create `FUNDING.yml` [`c2bbdde`](https://github.com/ljharb/get-intrinsic/commit/c2bbddeba73a875be61484ee4680b129a6d4e0a1)
- [Tests] add `npm run lint` [`0a84b98`](https://github.com/ljharb/get-intrinsic/commit/0a84b98b22b7cf7a748666f705b0003a493c35fd)
- Only apps should have lockfiles [`9586c75`](https://github.com/ljharb/get-intrinsic/commit/9586c75866c1ee678e4d5d4dbbdef6997e511b05)
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.