{"id":19514883,"url":"https://github.com/ndp/cajoler","last_synced_at":"2026-06-15T19:31:04.288Z","repository":{"id":66258006,"uuid":"368426572","full_name":"ndp/cajoler","owner":"ndp","description":"C'mon, do it!","archived":false,"fork":false,"pushed_at":"2022-02-09T03:46:00.000Z","size":211,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2025-11-18T19:23:49.582Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-18T06:39:19.000Z","updated_at":"2024-11-27T17:59:17.000Z","dependencies_parsed_at":"2023-02-22T16:30:31.596Z","dependency_job_id":null,"html_url":"https://github.com/ndp/cajoler","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/ndp/cajoler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndp%2Fcajoler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndp%2Fcajoler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndp%2Fcajoler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndp%2Fcajoler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndp","download_url":"https://codeload.github.com/ndp/cajoler/tar.gz/refs/heads/trunk","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndp%2Fcajoler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34377872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T23:37:55.219Z","updated_at":"2026-06-15T19:31:04.266Z","avatar_url":"https://github.com/ndp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cajoler\n\n\u003e ca·jole /kəˈjōl/\n\u003e • verb •\n\u003e persuade (someone) to do something by sustained coaxing or flattery.\n\nEncourage your visitors to do something, without being rude. \n\nCajoler presents a clean dialog to the user and get their response.\nI takes care of\n* light-weight client-side storage\n* simple presentation of a dialog without dependency on any web framework.\n\nSome ideas for Cajoler:\n* acknowledge that cookies exist\n* confirm terms-of-use\n* nudge to switch to https\n\nPresents a modeless dialog when called, if certain criteria are met, and \nremembers the users' response in localStorage (or cookies if localStorage isn't available.)\nBy default, if the user chooses \"No\", they are no asked again, but when buttons\nare shown or not is fully configurable.\n\nRequires no server-side storage.\n\nAppropriate for secondary functionality.\n\n## Usage\n\n```typescript\nimport { cajoler } from 'cajoler'\n\ncajoler(\n  {\n    key: 'foo',\n    nudgePrompt: '\u003ch2\u003eSwitch to a secure connection?\u003c/h2\u003e\u003cp\u003eSites without the \"s\" in \"https:\" are susceptible to \"wire-tapping\" attacks. Observers can easily see what you are doing.\u003c/p\u003e',\n    showFilter: previousButton =\u003e\n                  window.location.protocol === 'http:' \u0026\u0026 previousButton !== 'no',\n    yes:        {\n      label:    'Use a Secure Connection',\n      callback: () =\u003e (window.location.protocol = 'https:')\n    },\n    no:         {\n      label: 'Dismiss'\n    }\n  }\n)\n```\n\nThere is one call, `cajoler`, and receives options:\n\n* `key`: A key to identify the check/message. You may have multiple nudges if you want, and the users' responses are remembered by this key. If not provided, a generic key is used. \n* `nudgePrompt`: The text of the nudge. Provide this in HTML, or a function that returns HTML. If the user clicked a button on a previous visit, the function receives it as a parameter. (If not, it receives an empty string.)\n* `yes` A descriptor for the main positive button. It's an object with\n    - `label`: the name of the button signifying an \"Yes\" answer\n    - `callback`: a function to call when the user selects \"Yes\"\n* `no` An object similar to `yes`, with\n    - `label`: the name of the button signifying an \"No\" answer\n      _A blank value indicates there is no \"No\" button. (Default)_\n    - `callback`: a function to call when the user selects \"No\"\n* `maybe` An object similar to `yes`, with\n    - `label`: the name of the button signifying an \"Maybe\" answer\n      _A blank value indicates there is no \"Maybe\" button. (Default)_\n    - `callback`: a function to call when the user selects \"Maybe\"\n* `position` Either `top` or `bottom`, determining where the alert is positioned.\n* `cssClass` The CSS class use for the wrapper component. If you change this from the default of `cajoler`, you'll need to do all your own CSS.\n* `delay` Milliseconds to wait before showing the alert. The default is 1000.\n* `autoCloseDelay` Milliseconds to show the dialog before automatically closing it. The default is 60,000.\n* `onAutoClose` callback to do something when the dialog closes\n* `showFilter`: A function that returns `true` if the cajoling message should be shown to the user. It is passed a value\n  of the previous button the user chose. If the user has not chosen before, or local data has been deleted, the\n  parameter will be an empty string.\n  \n### CSS\n\nStyles can be imported¹ from `cajoler/src/cajoler.css`. To customize colors or anything else, simply use the cascade, and\noverride selectors. Everything is name-spaced inside `.cajoler`, and it's pretty easy to do your own thing. If you don't want to use this class name, override the option `cssClass` in the options.\n\n¹ I used a configuration with webpack and `html-webpack-plugin` and `css-loader`, but you can do it your own way.\n\n## Development\n\nBuild using TSDX.\n\n### Commands\n\nTSDX scaffolds your new library inside `/src`.\n\nTo run TSDX, use:\n\n```bash\nnpm start # or yarn start\n```\n\nThis builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`\n.\n\nTo do a one-off build, use `npm run build` or `yarn build`.\n\nTo run tests, use `npm test` or `yarn test`.\n\n### Continuous Integration\n\n[![CI](https://github.com/ndp/cajoler/actions/workflows/main.yml/badge.svg)](https://github.com/ndp/cajoler/actions/workflows/main.yml)\n\n#### GitHub Actions\n\nTwo actions are added by default:\n\n- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix\n- `size` which comments cost comparison of your library on every pull request\n  using [`size-limit`](https://github.com/ai/size-limit)\n\n### Configuration\n\nCode quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields\nin `package.json` accordingly.\n\n#### Jest\n\nJest tests are set up to run with `npm test` or `yarn test`.\n\n#### Bundle Analysis\n\n[`size-limit`](https://github.com/ai/size-limit) is set up to calculate the real cost of your library\nwith `npm run size` and visualize the bundle with `npm run analyze`.\n\n### Optimizations\n\nPlease see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know\nthat you can take advantage of development-only optimizations:\n\n```typescript\n// ./types/index.d.ts\ndeclare var __DEV__: boolean;\n\n// inside your code...\nif (__DEV__) {\n  console.log('foo');\n}\n```\n\nYou can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant)\nand [warning](https://github.com/palmerhq/tsdx#warning) functions.\n\n### Publishing to NPM\n\nWe use [np](https://github.com/sindresorhus/np). Use a command such as `np --branch trunk major`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndp%2Fcajoler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndp%2Fcajoler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndp%2Fcajoler/lists"}