{"id":15447220,"url":"https://github.com/jaredly/pjs","last_synced_at":"2025-04-19T21:30:59.615Z","repository":{"id":894641,"uuid":"647111","full_name":"jaredly/PJs","owner":"jaredly","description":"kinda like pyjamas, but quicker, cleaner, and easier. has the goal of generating readable, usable *robust* javascript code from python code","archived":false,"fork":false,"pushed_at":"2013-07-13T10:07:33.000Z","size":576,"stargazers_count":53,"open_issues_count":1,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-29T13:35:15.068Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://jaredforsyth.com/projects/pjs","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredly.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-05-04T18:56:56.000Z","updated_at":"2022-08-06T23:46:31.000Z","dependencies_parsed_at":"2022-08-16T11:20:42.396Z","dependency_job_id":null,"html_url":"https://github.com/jaredly/PJs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2FPJs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2FPJs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2FPJs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredly%2FPJs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredly","download_url":"https://codeload.github.com/jaredly/PJs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249810111,"owners_count":21328539,"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-01T20:04:17.850Z","updated_at":"2025-04-19T21:30:59.598Z","avatar_url":"https://github.com/jaredly.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"PJs\n===\n\nkinda like pyjamas...\n\nbut shorter. quicker. cleaner. more convenient. Oh, and, *easier*. Takes care\nof error handling, so you don't get cryptic error messages that originate from\njavascript's lazyness regarding undefined variables.\n\nPJs has the goal of generating readable, usable *robust* javascript code from\npython code, and of providing some libraries to make web development easier.\n\nInstallation\n------------\n\nI don't yet have a dist on pypi, so just clone the repo.\n\nIf you want to run the tests, ``pjs`` depends on ``pbj`` so you first need to\n``pip install pbj``. Pbj is a build tool that I wrote, and you can invoke it\n(once installed) with ``./make.pbj`` in the ``pjs`` directory. \n\nUsage\n-----\n\nThe ``convert.py`` should work pretty well for playing around with pjs.\n\n\nRecent Addtions\n---------------\n\n- nested class support (full namespacing!!)\n- operator overloading\n- easy javascript embedding\n\n\nTo make a javascript function call, prepend ``js.`` to the call (I'm reserving\nthe name ``js``; I hope you don't mind). Any calls starting with ``window.``\nare treated as javascript calls as well. The difference is that the ``js``\nprefix is removed -- it is assumed that you are working with a local variable.\n\n::\n\n    jq = window.jQuery\n    def make_tabs(id):\n        js.jq(id).tabs()\n\nThis is necessary because PJs wraps strings, tuples, lists, and dictionarys,\nso jQuery wouldn't know what to do with ``jq(\"hi\")`` which\notherwise would be translated to ``jq($b.str(\"hi\"))``. As it is, the above\ncode becomes::\n\n    _.jq = window.jQuery;\n    _.make_tabs = $def(function $_make_tabs(id) {\n      _.jq($b.js(id)).tabs();\n    });\n\nNow that might be a bit confusing, but the important thing is that PJs knows\nto convert ``id`` to a javascript type (the added builtin function ``js`` converts a\npython object to the corresponding javascript type).\n\nIf you want to avoid that kind of magic, that's fine too, but you need to\nconvert the function arguments yourself. In python, you'd have::\n\n    jq = window.jQuery\n    def make_tabs(id):\n      jq(js(id)).tabs()\n\nNot much different in this example, but for more complicated expressions such\nas ``foo(a, b, c, d).bar(e, f)`` it's much simpler to just put a ``js.`` at\nthe very beginning.\n\nOne thing for which you must rely on magic (sorry) is subscripting; in PJs, in\norder to allow for __get/setitem\\__ manipulation, expressions such as\n``people[gender]`` are converted to ``people.__getitem__(gender)``. If you've\ngot a javascript-style list, the magic ``js.`` prefix will preserve\nsubscripts (and convert the argument back to javascript). So\n``js.people[gender]`` becomes ``people[$b.js(gender)]``. Slicing is also\nhandled intelligently; ``js.people[start:end]`` comes out as\n``people.slice(start, end)``.\n       \n\n\n\n\nThings you can't do:\n\n- python attribute magic:\n\n  - __getattr__\n  - __setattr__\n\nThese will have major performance implications; I imagine they might be\nenableable via a flag -- for most programs that level of control isn't\nabsolutely nessecary.\n\nThings you can do:\n\n- just about everything else\n- classes\n- modules!\n- functions\n- decorators\n\n  - classmethod\n  - staticmethod\n\n- operator magic; __add__, __mul__ etc.\n\nif you find a bug or something you don't like, feel free to file a ticket on\ngithub, or *even better*, fork the repo, fix your problem, and then pull\nrequest. We love pull requests.\n\nPythonic Functions\n==================\n\nHere's a bit from the top of the functions.js, which allows for pythonic function in javascript!\n\n(pjs provides the function $def for creating pythonic functions)\n\nHow to use:\n\n- $def([defaults], [aflag], [kflag], fn);\n- defaults, aflag, and kflag are all optional, but required to be in that\n  order to avoid ambiguity.\n- defaults = an associative array of key, value pairs; the key is the arg\n  name, anf the vaule is default value.\n- aflag signals that the last (or second-to-last, if kflag is true) is to be\n  populated with excess positional arguments. (in python, this is the \\*args\n  syntax).\n- kflag is like aflag, but for dictionary arguments, e.g. \\**kwargs.\n- there's also checks happening the whole way, so you won't be stuck debugging\n  another annoying undefined error.\n\nHere's an example that uses all of these:\n\n::\n\n    var foo = $def({c:null, d:10}, true, true, function foo(a, b, c, d, args, kwargs) {\n        // only a and b are required, and excess positional and dictionary\n        // arguments will be captured.\n        console.log([a, b, c, d, args, kwargs]);\n    });\n    \n    // and in use...\n\n    \u003e foo(1);\n    TypeError: foo requires 2 arguments (1 given)\n    \u003e foo(1,2);\n    [1, 2, null, 10, [], {}]\n    \u003e foo(1,2,3);\n    [1, 2, 3, 10, [], {}]\n    \u003e foo(1,2,3,4,5,6,7,8,9);\n    [1, 2, 3, 4, [5, 6, 7, 8, 9], {}]\n\n    now some some real magic; dictionary arguments:\n\n    \u003e foo.args([1], {'b':9, 'd':20, 'man':'hatten'}\n    [1, 9, null, 20, [], {'man': 'hatten'}]\n\n    !! that looks like python !! well...almost. but it's lovely :)\n \npython-style classes are also implemented, with full namespacing!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredly%2Fpjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredly%2Fpjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredly%2Fpjs/lists"}