{"id":15355821,"url":"https://github.com/fibo/strict-mode","last_synced_at":"2025-04-15T06:39:40.776Z","repository":{"id":13066214,"uuid":"15746773","full_name":"fibo/strict-mode","owner":"fibo","description":"enables strict mode in your package","archived":false,"fork":false,"pushed_at":"2021-01-15T11:10:31.000Z","size":122,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T17:11:14.232Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://fibo.github.io/strict-mode","language":"JavaScript","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/fibo.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}},"created_at":"2014-01-08T20:12:24.000Z","updated_at":"2024-05-09T10:35:43.000Z","dependencies_parsed_at":"2022-09-26T19:00:24.123Z","dependency_job_id":null,"html_url":"https://github.com/fibo/strict-mode","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fstrict-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fstrict-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fstrict-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fstrict-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fibo","download_url":"https://codeload.github.com/fibo/strict-mode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675454,"owners_count":21143766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-10-01T12:25:49.021Z","updated_at":"2025-04-15T06:39:40.750Z","avatar_url":"https://github.com/fibo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# strict-mode\n\n\u003e enables strict mode in your package\n\n[![NPM version](https://badge.fury.io/js/strict-mode.svg)](http://badge.fury.io/js/strict-mode)\n[![No deps](https://img.shields.io/badge/dependencies-none-green.svg)](https://github.com/fibo/strict-mode)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n## Installation\n\nWith [npm](https://npmjs.org/) do\n\n```bash\nnpm install strict-mode --save-dev\n```\n\n**NOTA BENE** you may want to install *strict-mode* as a development dependency, see [Bonus Tip below](#bonus-tip).\n\n## Usage\n\n**Please note that this package is intended to be used server side.**\nIf used with [browserify] it is a [no op].\n\nSuppose that the *main attribute* in your *package.json* is *index.js*.\nIf you want that all the modules in your package have strict mode enabled,\njust wrap your *index.js* this way\n\n```javascript\nrequire('strict-mode')(function () {\n\n// your index.js content\n\n// every *require* call inside this function will have strict mode enabled\n\n})\n```\n\n## Motivation\n\n[Strict mode][MDN_Strict_mode] is a best practice but adding a `\"use strict\";` on top of every *.js* file in your package could\n\n* require a big effort\n* be error proning\n* make complain linters (like eslint, jshint, etc.)\n* be a problem when concatenating files\n\nOn the other hand the [use-strict] package solution is too invasive, cause it applies strictness to **all** future modules loaded.\n\n## Use case\n\nAt the time of this writing [Node v4 stable](https://nodejs.org/en/blog/release/v4.0.0/) version was released few days ago.\nFinally we can use `class`, `let`, `const` (among other new exciting features) but you will notice that if you do not turn on strict mode an exception will raise.\nFor instance, a file *Point2d.js* with content\n\n```javascript\nclass Point2d {\n  constructor (x, y) {\n    this.x = x\n    this.y = y\n  }\n}\n\nmodule.exports = Point2d\n```\n\nwhen imported will complain\n\n```\nSyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode\n```\n\nbut if you wrap the import with *strict-mode* everything will just work\n\n```javascript\nrequire('strict-mode')(function () {\n\n  var Point2d = require('./Point2d')\n  // require all other classes you need.\n\n  // You can also export them safely\n  exports.Point2d = Point2d\n})\n```\n\n## Bonus tip\n\nYou could use *strict-mode* just as a development dependency.\n\nFollowing the instructions below, you are not going to deploy *strict-mode* on production but when you run your tests **if some code is not strict, then you will get an error**.\n\nSuppose you have the following folder structure in your package.\n\n    .\n    ├── package.json\n    ├── src\n    │   └── index.js    # your package.json `main` entry\n    └── test\n        ├── test1.js\n        └── test2.js\n\nAssuming you package name is, emh *my-package*, create a file *test/my-package.js* containing\n\n```javascript\nrequire('strict-mode')(function () {\n  module.exports = require('../src/index.js')\n})\n```\n\nNow if you set the environment variable `NODE_PATH=test`, you can use `require('my-package')` in your tests.\n\nFor instance if you are using *tape* you can add this to your *package.json*\n\n```json\n    \"test\": \"NODE_PATH=test tape test/*js\"\n```\n\nYou can also achieve the same result without `NODE_PATH` environment variable, using this nasty trick (to cheat npm :^)\nInstead of *test/my-package.js*, create a *test/node_modules/my-package/index.js* containing\n\n```javascript\nrequire('strict-mode')(function () {\n  module.exports = require('../../../src/index.js')\n})\n```\n\nNotice also that you will probably need to force git add, for instance\n\n```bash\ngit add -f test/node_modules/my-package/index.js\n```\n\n## Credits\n\nCode **stolen** from isaacs' [use-strict].\nA big thank to [MDN](https://developer.mozilla.org) cause it is an awesome knowledge base for everything related with the Web: in particular, I could find some valid counterexamples of strict mode to include in my tests.\n\n## License\n\n[MIT](http://g14n.info/mit-license)\n\n[browserify]: http://browserify.org/ \"browserify\"\n[MDN_Strict_mode]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode\n[no op]: https://github.com/fibo/strict-mode/blob/master/browser.js \"browser.js\"\n[test/node_modules/strict-mode/index.js]: https://github.com/fibo/strict-mode/blob/master/test/node_modules/strict-mode/index.js\n[use-strict]: https://npmjs.org/package/use-strict \"use-strict\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibo%2Fstrict-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffibo%2Fstrict-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibo%2Fstrict-mode/lists"}