From f5f796cd2dee0d6c85e8b64c93545f71bcf3143b Mon Sep 17 00:00:00 2001 From: Gordon Sun Date: Sun, 5 Jun 2022 22:11:52 -0700 Subject: [PATCH] Remove demo and jQuery #499 --- README.md | 1 + codecov.yml | 1 - demo/demo.css | 207 ---------------- demo/demo.ts | 349 --------------------------- demo/index.html | 586 ---------------------------------------------- index.html | 1 - package.json | 7 - tsconfig.json | 4 +- webpack.config.js | 52 +--- yarn.lock | 14 -- 10 files changed, 4 insertions(+), 1218 deletions(-) delete mode 100644 demo/demo.css delete mode 100644 demo/demo.ts delete mode 100644 demo/index.html delete mode 120000 index.html diff --git a/README.md b/README.md index 775dad00..7d8760f6 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ to natural language. ### Quick Start - [Demo app](http://jakubroztocil.github.io/rrule/) +- For contributors and maintainers: the code for the demo app is only on `gh-pages` branch #### Client Side diff --git a/codecov.yml b/codecov.yml index 9e0e8073..60f82f9a 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,7 +1,6 @@ ignore: - "dist/" - "test/" - - "demo/" - "node_modules/" - ".github/" - "webpack.config.js" \ No newline at end of file diff --git a/demo/demo.css b/demo/demo.css deleted file mode 100644 index 61244522..00000000 --- a/demo/demo.css +++ /dev/null @@ -1,207 +0,0 @@ -body { - font: 14px/1.4 sans-serif; - color: #111; - background: #fafafa; -} -a { - color: #366097; -} -h2, h1 { - text-align: center; - font-family: georgia, serif; - font-size: 3em; - font-weight: normal; -} -h2 { - font-size: 2.5em; - margin-bottom: .7em; -} - -pre, ol { - margin: 0 -} - - - -table { - border-collapse: collapse; - width: 100%; -} - -table, td, th { - border: 1px solid #fafafa; -} -td, th { - padding: .4em; -} - -tbody th { - text-align: right; - width: 10em; -} - -code, label { - background: #fff; - border-radius: .3em; - padding: .2em .3em; - border: 1px solid #ededed; -} - - -label { - white-space: nowrap; - display: inline-block; - margin: 0 .3em .3em 0; - cursor: pointer; - font-size: .9em; -} -input:not([type=checkbox]):not([type=radio]), select { - width: 100%; - font-size: 1.4em; - box-sizing: border-box; -} -input { - padding: .2em; -} - -.error { - color: red; -} - - -#page { - min-width: 960px; - margin: auto; -} - -#intro { - text-align: center; - font-size: 1.2em; -} - -/* Input --------------------------------------- */ - - -#tabs { - border-bottom: 1px solid #111; - text-align: center; -} -#tabs a { - background: #111; - border: 1px solid #111; - padding: .4em 1em; - margin: 0 .5em -1px; - color: #eee; - display: inline-block; - text-decoration: none; - font-weight: bold; - font-size: 1.1em; - border-top-left-radius: .2em; - border-top-right-radius: .2em; -} -#tabs a.active { - color: #111; - background: #fafafa; - border-bottom-color: #fafafa; -} -#input { - float: left; - width: 40% -} -#input th { - width: 7em !important; -} -#input section { - padding: 1em; -} -.examples li { - margin-bottom: .7em; -} -.examples code { - cursor: pointer; -} -#rfc-input input { - font-family: monospace; -} - -#options-input input, #options-input select { - font-size: 1em; -} -.option-name { - position: relative; - cursor: help; -} -.option-name .help { - border-radius: .3em; - font-weight: normal; - display: none; - position: absolute; - padding: 1em; - background: #333; - color: #fafafa; - border: 1px solid #000; - left: 110%; - right: -100%; - width: 350px; - text-align: left; - top: -1em; - box-shadow: 3px 3px 3px #888; - line-height: 1.6; - font-size: .9em; -} -.option-name .help code { - color: #fff; - background: #000; -} -.option-name:hover code:first-child{ - background: #222; - color: #fafafa; -} -.option-name:hover .help { - display: block; -} - - -/* Output --------------------------------------- */ - - -#output { - float: right; - width: 58% -} -#output pre { - white-space: pre-wrap; -} -#output td { - background: #fff; -} -#output td, #output th { - vertical-align: top; -} -#output li { - font-family: monospace; -} -#output li:nth-child(even) { - background: #f1f1f1; -} -#dates { - font-size: .9em; -} -#dates td:first-child { - color: #ccc; -} -#dates td:first-child { - text-align: right; -} -#dates td.b { - background: #eaeaea; -} -#dates td.b { - background: #f0f0f0; -} - -#output a { - color: inherit -} diff --git a/demo/demo.ts b/demo/demo.ts deleted file mode 100644 index 8bd18cc2..00000000 --- a/demo/demo.ts +++ /dev/null @@ -1,349 +0,0 @@ -import * as $ from 'jquery' - -import { RRule, Weekday, Options } from '../src/index' - -// Make library accessible to browser debuggers so users can try things out themselves -// tslint:disable-next-line:no-duplicate-imports -import * as rruleExports from '../src/index' -$.extend(window, rruleExports) - -const getDay = (i: number) => [ - RRule.MO, - RRule.TU, - RRule.WE, - RRule.TH, - RRule.FR, - RRule.SA, - RRule.SU -][i] - -const makeArray = (s: string | string[]) => - Array.isArray(s) ? s : [s] - -const getFormValues = function ($form: JQuery) { - const paramObj: { [K in keyof Partial]: string | string[] } = {} - $form.serializeArray().forEach(kv => { - const k = kv.name as keyof Options - if (paramObj.hasOwnProperty(k)) { - const v = makeArray(paramObj[k]!) - v.push(kv.value) - paramObj[k] = v - } else { - paramObj[k] = kv.value - } - }) - - return paramObj -} - -const getOptionsCode = function (options: Partial) { - const days = [ - 'RRule.MO', - 'RRule.TU', - 'RRule.WE', - 'RRule.TH', - 'RRule.FR', - 'RRule.SA', - 'RRule.SU' - ] - - const items = Object.keys(options).map((k: keyof Options) => { - let v: unknown = options[k] - if (v === null) { - v = 'null' - } else if (k === 'freq') { - v = `RRule.${RRule.FREQUENCIES[v as number]}` - } else if (k === 'dtstart' || k === 'until') { - const d = v as Date - v = - 'new Date(Date.UTC(' + - [ - d.getUTCFullYear(), - d.getUTCMonth(), - d.getUTCDate(), - d.getUTCHours(), - d.getUTCMinutes(), - d.getUTCSeconds() - ].join(', ') + - '))' - } else if (k === 'byweekday') { - if (Array.isArray(v)) { - v = (v as Weekday[]).map(function (wday) { - console.log('wday', wday) - let s = days[wday.weekday] - if (wday.n) { - return s + `.nth(${wday.n})` - } - return s - }) - } else { - const w = v as Weekday - v = days[w.weekday] - } - } else if (k === 'wkst') { - if (v === RRule.MO) { - return '' - } - const w = v as Weekday - v = days[w.weekday] - } - - if (Array.isArray(v)) { - v = `[${v.join(', ')}]` - } - - console.log(k, ' =', v) - return `${k}: ${v}` - }) - - return `{\n ${items.filter(v => !!v).join(',\n ')}\n}` -} - -const makeRows = function (dates: Date[]) { - let prevParts: string[] = [] - let prevStates: boolean[] = [] - - const rows = dates.map((date, index) => { - let states: boolean[] = [] - let parts = date.toUTCString().split(' ') - - const cells = parts.map((part, i) => { - if (part !== prevParts[i]) { - states[i] = !prevStates[i] - } else { - states[i] = prevStates[i] - } - const cls = states[i] ? 'a' : 'b' - return `${part}` - }) - - prevParts = parts - prevStates = states - - return `${index + 1}${cells.join('\n')}` - }) - - return rows.join('\n\n') -} - -$(function () { - const $tabs = $('#tabs') - - const activateTab = function ($a: JQuery) { - const id = $a.attr('href')!.split('#')[1] - $tabs.find('a').removeClass('active') - $a.addClass('active') - $('#input-types section').hide() - return $(`#input-types #${id}`) - .show() - .find('input:first') - .trigger('focus') - .trigger('change') - } - - $('#input-types section') - .hide() - .each(function () { - $('', { - href: `#${$(this).attr('id')}` - }) - .text( - $(this) - .find('h3') - .hide() - .text() - ) - .appendTo($tabs) - .on('click', function () { - activateTab($(this)) - return false - }) - }) - - $('.examples code').on('click', function () { - const $code = $(this) - return $code - .parents('section:first') - .find('input') - .val($code.text()) - .trigger('change') - }) - - let init: string - let makeRule: () => RRule - - $('input, select').on('keyup change', function () { - const $in = $(this) - const $section = $in.parents('section:first') - const inputMethod = $section.attr('id')!.split('-')[0] - - switch (inputMethod) { - case 'text': - makeRule = () => RRule.fromText($in.val()!.toString()) - init = `RRule.fromText("${(this as HTMLFormElement).value}")` - break - case 'rfc': - makeRule = () => RRule.fromString((this as HTMLFormElement).value) - init = `RRule.fromString("${(this as HTMLFormElement).value}")` - break - case 'options': - let values = getFormValues($in.parents('form')) - let options: Partial = {} - - for (const k in values) { - const key = k as keyof Options - - let value = values[key] - if (!value) { - continue - } - - switch (key) { - case 'dtstart': - case 'until': - const date = new Date(Date.parse(value + 'Z')) - options[key] = date - continue - - case 'byweekday': - if (Array.isArray(value)) { - options[key] = value.map(i => getDay(parseInt(i, 10))) - } else { - options[key] = getDay(parseInt(value, 10)) - } - continue - - case 'wkst': - options[key] = getDay(parseInt(value as string, 10)) - continue - - case 'interval': - const i = parseInt(value as string, 10) - if (i === 1 || !value) { - continue - } - - options[key] = i - continue - - case 'tzid': - options[key] = value as string - continue - - case 'byweekday': - case 'byweekno': - case 'byhour': - case 'byminute': - case 'bysecond': - case 'byyearday': - case 'bymonth': - case 'bymonthday': - case 'bysetpos': - case 'bynmonthday': - if (!Array.isArray(value)) { - value = value.split(/[,\s]+/) - } - value = value.filter(v => v) - options[key] = value.map(n => parseInt(n, 10)) - continue - - case 'bynweekday': - if (!Array.isArray(value)) { - value = value.split(/[,\s]+/) - } - value = value.filter(v => v) - options[key] = [value.map(n => parseInt(n, 10))] - continue - - case 'byeaster': - options[key] = parseInt(value as string, 10) - continue - - case 'freq': - case 'count': - options[key] = parseInt(value as string, 10) - continue - - default: - console.warn('Unsupported key', key) - continue - } - } - - makeRule = () => new RRule(options) - init = `new RRule(${getOptionsCode(options)})` - console.log(options) - break - } - - $('#init').html(init) - $('#rfc-output a').html('') - $('#text-output a').html('') - $('#options-output').html('') - $('#dates').html('') - - let rule: RRule - try { - rule = makeRule() - } catch (e) { - $('#init').append( - $('
').text(`=> ${String(e || null)}`)
-      )
-      return
-    }
-
-    const rfc = rule.toString()
-    const text = rule.toText()
-    $('#rfc-output a')
-      .text(rfc)
-      .attr('href', `#/rfc/${rfc}`)
-    $('#text-output a')
-      .text(text)
-      .attr('href', `#/text/${text}`)
-    $('#options-output').text(getOptionsCode(rule.origOptions))
-    if (inputMethod === 'options') {
-      $('#options-output')
-        .parents('tr')
-        .hide()
-    } else {
-      $('#options-output')
-        .parents('tr')
-        .show()
-    }
-    const max = 500
-    const dates = rule.all(function (date, i) {
-      if (!rule.options.count && i === max) {
-        return false // That's enough
-      }
-      return true
-    })
-
-    let html = makeRows(dates)
-    if (!rule.options.count) {
-      html += `\
-Showing first ${max} dates, set
-count to see more.\
-`
-    }
-    return $('#dates').html(html)
-  })
-
-  activateTab($tabs.find('a:first'))
-
-  const processHash = function () {
-    const hash = location.hash.substring(1)
-    if (hash) {
-      const match = /^\/(rfc|text)\/(.+)$/.exec(hash)
-      if (match) {
-        const method = match[1] // rfc | text
-        const arg = match[2]
-        activateTab($(`a[href='#${method}-input']`))
-        return $(`#${method}-input input:first`)
-          .val(arg)
-          .trigger('change')
-      }
-    }
-  }
-  processHash()
-  return $(window).on('hashchange', processHash)
-})
diff --git a/demo/index.html b/demo/index.html
deleted file mode 100644
index 88067afb..00000000
--- a/demo/index.html
+++ /dev/null
@@ -1,586 +0,0 @@
-
-
-
-
-
-  rrule.js demo
-  
-  
-
-
-
-  
-

- Code and docs -

-

- rrule.js demo

- -
-

- This is a demo and test app for - rrule.js, a JavaScript library for working with recurrence rules for calendar dates. -

- -
- -
-

Output

- - - - - - - - - - - - - - - - - - - - - -
- rule = - -

-          
- rule.origOptions - -

-          
- rule.toString() - -
-
- rule.toText() - - - - -
- rule.all() - -
-
-
- - -
-

Input

-
-
-
-

Options

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- freq - -
Frequency
-
-
- - - - - - - -
-
- dtstart - -
The recurrence start. Besides being the base for the recurrence, missing parameters in the final recurrence - instances will also be extracted from this date. If not given, - new Date will be used instead. -
-
-
- -
-
- tzid - -
The timezone for the rule. If present, all recurrences will be interpreted as being in the local time - of the given timezone. If not present, UTC will be used instead. -
-
-
- -
-
- until - -
If given, this must be a - Date - instance, that will specify the limit of the recurrence. If a recurrence instance happens to be the same as the - Date instance given in the - until - argument, this will be the last occurrence. -
-
-
- -
-
- count - -
How many occurrences will be generated. -
-
-
- -
-
- interval - -
The interval between each freq iteration. For example, when using - RRule.YEARLY, an interval of - 2 means once every two years, but with - RRule.HOURLY, it means once every two hours. The default interval is - 1. -
-
-
- -
-
- wkst - -
The week start day. Must be one of the - RRule.MO, - RRule.TU, - RRule.WE - constants, or an integer, specifying the first day of the week. This will affect recurrences based on weekly periods. The - default week start is - RRule.MO. -
-
-
- - - - - - - -
-
- byweekday - -
If given, it must be either an integer ( - 0 == RRule.MO), a sequence of integers, one of the weekday constants ( - RRule.MO, - RRule.TU, etc), or a sequence of these constants. When given, these variables will define - the weekdays where the recurrence will be applied. It's also possible to use an argument n for the - weekday instances, which will mean the nth occurrence of this weekday in the period. For example, - with - RRule.MONTHLY, or with - RRule.YEARLY and - BYMONTH, using - RRule.FR.clone(+1) in - byweekday will specify the first friday of the month where the recurrence happens. Notice - that the RFC documentation, this is specified as - BYDAY, but was renamed to avoid the ambiguity of that argument. -
-
-
- - - - - - - -
-
- bymonth - -
If given, it must be either an integer, or a sequence of integers, meaning the months to apply the - recurrence to. -
-
-
- - - - - - - - - - - - -
-
- bysetpos - -
If given, it must be either an integer, or a sequence of integers, positive or negative. Each given - integer will specify an occurrence number, corresponding to the nth occurrence of the rule inside - the frequency period. For example, a - bysetpos of - -1 if combined with a - RRule.MONTHLY - frequency, and a byweekday of ( - RRule.MO, - RRule.TU, - RRule.WE, - RRule.TH, - RRule.FR), will result in the last work day of every month. -
-
-
- -
-
- bymonthday - -
If given, it must be either an integer, or a sequence of integers, meaning the month days to apply - the recurrence to. -
-
-
- -
-
- byyearday - -
If given, it must be either an integer, or a sequence of integers, meaning the year days to apply the - recurrence to. -
-
-
- -
-
- byweekno - -
If given, it must be either an integer, or a sequence of integers, meaning the week numbers to apply - the recurrence to. Week numbers have the meaning described in ISO8601, that is, the first week of - the year is that containing at least four days of the new year. -
-
-
- -
-
- byhour - -
If given, it must be either an integer, or a sequence of integers, meaning the hours to apply the recurrence - to. -
-
-
- -
-
- byminute - -
If given, it must be either an integer, or a sequence of integers, meaning the minutes to apply the - recurrence to. -
-
-
- -
-
- bysecond - -
If given, it must be either an integer, or a sequence of integers, meaning the seconds to apply the - recurrence to. -
-
-
- -
-
- byeaster - -
- This is an extension to the RFC specification which the Python implementation provides. - Not implemented in the JavaScript version. - -
-
-
- -
-
-
- - -
-

- RRULE string

-

- -

-

- Enter an - RRULE as per - iCalendar RFC. -

-

Examples:

-
    -
  • - FREQ=WEEKLY;BYDAY=MO,WE -
  • -
  • - FREQ=MONTHLY;BYMONTHDAY=10,15;COUNT=20 -
  • -
  • - FREQ=DAILY;INTERVAL=3;COUNT=10 -
  • -
  • - FREQ=MONTHLY;BYDAY=-2FR;COUNT=7 -
  • -
-
- - - -
-

Text input

-

- -

-

Examples:

-
    -
  • - Every weekday -
  • -
  • - Every 2 weeks on Tuesday -
  • -
  • - Every week on Monday, Wednesday -
  • -
  • - Every month on the 2nd last Friday for 7 times -
  • -
  • - Every 6 months -
  • -
-
- - -
-
-
- - Fork me on GitHub - - - - diff --git a/index.html b/index.html deleted file mode 120000 index 5ad281df..00000000 --- a/index.html +++ /dev/null @@ -1 +0,0 @@ -demo/index.html \ No newline at end of file diff --git a/package.json b/package.json index 179f60ef..6d399c3f 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "devDependencies": { "@types/assert": "^1.4.3", "@types/chai": "^4.2.7", - "@types/jquery": "^3.3.29", "@types/mocha": "^5.2.5", "@types/mockdate": "^2.0.0", "@types/node": "^12.12.18", @@ -55,7 +54,6 @@ "coverage": "^0.4.1", "html-webpack-plugin": "^3.2.0", "husky": "^3.1.0", - "jquery": "^3.3.1", "mocha": "^6.2.2", "mockdate": "^2.0.5", "nyc": "^14.1.1", @@ -70,11 +68,6 @@ "webpack": "^4.41.3", "webpack-cli": "^3.3.10" }, - "standard": { - "ignore": [ - "demo" - ] - }, "files": [ "dist", "README.md" diff --git a/tsconfig.json b/tsconfig.json index 0ed7bad5..54f45309 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,8 +13,8 @@ "jsx": "react", "strictNullChecks": true, "importHelpers": true, - "rootDirs": ["./src/", "./test/", "./demo/"] + "rootDirs": ["./src/", "./test/"] }, - "include": ["./src/**/*", "./demo/**/*"], + "include": ["./src/**/*"], "exclude": ["node_modules", "./test/**/*"] } diff --git a/webpack.config.js b/webpack.config.js index e5ff3ae1..1e38c9d6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,13 +5,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin"); const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); const paths = { - demo: { - source: path.resolve(__dirname, 'demo'), - styles: path.resolve(__dirname, "demo", "demo.css"), - template: path.resolve(__dirname, "demo", "index.html") - }, source: path.resolve(__dirname, 'src'), - demoDist: path.resolve(__dirname, "dist", "esm", "demo"), es5: path.resolve(__dirname, "dist", "es5"), esm: path.resolve(__dirname, "dist", "esm") }; @@ -56,48 +50,4 @@ const rruleConfig = Object.assign({ }, }, commonConfig); -const demoConfig = { - entry: { - demo: path.join(paths.demo.source, "demo.ts"), - }, - module: { - rules: [ - { - test: /\.js$/, - use: ["source-map-loader"], - enforce: "pre" - }, - { - exclude: /node_modules/, - loader: "ts-loader", - test: /\.ts$/ - } - ] - }, - output: { - filename: "demo.js", - path: paths.demoDist - }, - resolve: { - extensions: [".js", ".ts"] - }, - plugins: [ - new webpack.ProvidePlugin({ - $: "jquery", - jQuery: "jquery" - }), - new CopyWebpackPlugin([ - { - from: paths.demo.styles, - to: paths.demoDist - } - ]), - new HtmlWebpackPlugin({ - template: paths.demo.template - }) - ], - devtool: "source-map", - mode: "production" -}; - -module.exports = [rruleConfig, demoConfig]; +module.exports = [rruleConfig]; diff --git a/yarn.lock b/yarn.lock index 2f63f6ea..01d663b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -114,12 +114,6 @@ resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff" integrity sha512-hRJD2ahnnpLgsj6KWMYSrmXkM3rm2Dl1qkx6IOFD5FnuNPXJIG5L0dhgKXCYTRMGzU4n0wImQ/xfmRc4POUFlg== -"@types/jquery@^3.3.29": - version "3.3.29" - resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.3.29.tgz#680a2219ce3c9250483722fccf5570d1e2d08abd" - dependencies: - "@types/sizzle" "*" - "@types/mocha@^5.2.5": version "5.2.5" resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.5.tgz#8a4accfc403c124a0bafe8a9fc61a05ec1032073" @@ -138,10 +132,6 @@ resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== -"@types/sizzle@*": - version "2.3.2" - resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47" - "@webassemblyjs/ast@1.8.5": version "1.8.5" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.8.5.tgz#51b1c5fe6576a34953bf4b253df9f0d490d9e359" @@ -2233,10 +2223,6 @@ istanbul-reports@^2.2.4, istanbul-reports@^2.2.6: dependencies: handlebars "^4.1.2" -jquery@^3.3.1: - version "3.3.1" - resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.3.1.tgz#958ce29e81c9790f31be7792df5d4d95fc57fbca" - js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"