{"id":25527422,"url":"https://github.com/globalizejs/globalize-compiler","last_synced_at":"2025-04-11T06:11:54.960Z","repository":{"id":34113566,"uuid":"37943312","full_name":"globalizejs/globalize-compiler","owner":"globalizejs","description":"Globalize.js runtime compiler for your formatters and parsers","archived":false,"fork":false,"pushed_at":"2022-12-10T22:52:17.000Z","size":327,"stargazers_count":10,"open_issues_count":20,"forks_count":14,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-01-29T09:17:10.848Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/globalizejs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-23T20:31:35.000Z","updated_at":"2023-12-23T07:36:24.000Z","dependencies_parsed_at":"2023-01-15T04:42:10.147Z","dependency_job_id":null,"html_url":"https://github.com/globalizejs/globalize-compiler","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalizejs%2Fglobalize-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalizejs%2Fglobalize-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalizejs%2Fglobalize-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalizejs%2Fglobalize-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/globalizejs","download_url":"https://codeload.github.com/globalizejs/globalize-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239742405,"owners_count":19689310,"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":"2025-02-19T22:18:37.195Z","updated_at":"2025-02-19T22:18:37.705Z","avatar_url":"https://github.com/globalizejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Why Globalize compiler?\n\nUse *globalize-compiler* (a) to extract your Globalize formatters and parsers statically from your source code and (b) to compile + to bundle them into a JavaScript file.\n\nFor information about Globalize, please read its [documentation](https://github.com/jquery/globalize#README.md). More specifically, about [Performance](https://github.com/rxaviers/globalize/tree/fix-398-runtime#performance) and [Compilation and the Runtime modules](https://github.com/rxaviers/globalize/tree/fix-398-runtime#compilation-and-the-runtime-modules).\n\n## Usage\n\n### CLI\n\nUse the command line interface as a convenience over using the API directly. It's sufficient in most cases. It (a) extracts your formatters and parsers statically and (b) compiles + generates the bundle JavaScript. See their respective APIs [`.extract()`][] and [`.compileExtracts()`][] for constrains and other general information.\n\n    # Install\n    [sudo] npm install -g globalize-compiler\n\n    # globalize-compiler -l LOCALE [-c CLDR_FILE] [-m MESSAGES_FILE] -o DEST_FILE SRC_FILES...\n    globalize-compiler -l en \\\n        -m messages/en.json \\\n        -o my-compiled-formatters-and-parsers.js \\\n        src/*.js\n\n**`SRC_FILES`** Source JavaScript files to extract the formatters and parsers from.\n\n**`-h, --help`** Print options and usage.\n\n**`-v, --version`** Print the version number.\n\n**`-l, --locale LOCALE`** Specify a LOCALE to use in compilation.\n\n**`-c, --cldr CLDR_FILE`** Optional. All necessary CLDR data for given locale (JSON format).\n\n**`-z, --tz TIME_ZONE_FILE`** Optional. All necessary time zone data (JSON format).\n\n**`-m, --messages MESSAGES_FILE`** Optional. Translation messages for given locale (JSON format).\n\n**`-o, --output DEST_FILE`** Destination JavaScript file, e.g., `app-en.js`.\n\n### API\n\nUse the API directly in your Grunt or Gulp tasks.\n\n    npm install globalize-compiler --save-dev\n\n*globalize-compiler* has three functions: [`.compile()`][], [`.compileExtracts()`][], and [`.extract()`][].\n\n```js\nvar globalizeCompiler = require( \"globalize-compiler\" );\n// \u003e { compile: [Function: compiler],\n//     compileExtracts: [Function: compileExtracts],\n//     extract: [Function: extractor] }\n```\n\n#### `.compile( formattersAndParsers, options )`\n\n**formattersAndParsers** is an *Array* or an *Object* containing formatters and/or parsers, e.g.:\n\n```js\n// Array\n[\n    formatter1,\n    formatter2,\n    ...,\n    parser1,\n    parser2,\n    ...\n]\n\n// Object\n{\n    formatter1Key: formatter1,\n    formatter2Key: formatter2,\n    ...,\n    parser1Key: parser1,\n    parser2Key: parser2,\n    ...\n}\n```\n\n**options** is an *Object* with the following properties:\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp; **template** optional. A function that replaces the default template. The function will receive a single *Object* parameter with two properties:\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; **code**: string, the source of the compiled formatters and parsers.\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; **dependencies**: array, a list of globalize runtime modules that the compiled code depends on, e.g. `globalize-runtime/number`.\n\n**Returns** a *String* with the generated JavaScript bundle (UMD wrapped) including the compiled formatters and parsers.\n\n**Example**\n\n```javascript\nfs.writeFileSync( \"my-formatters-and-parsers.js\", globalizeCompiler.compile([\n    formatter1,\n    formatter2,\n    ...,\n    parser1,\n    parser2,\n    ...\n]));\n// \u003e \"A very long String with the generate JavaScript bundle content...\"\n```\n\n#### `.extract( input )`\n\n**input** is a *String* with a filename, or a *String* with the file content, or an AST *Object*.\n\n**Returns** an extract. An extract is a *Function* taking one argument: Globalize, the Globalize *Object*; and returning an *Array* with the formatters and parsers created using the passed Globalize.\n\n**Example**\n\n```js\nvar extract = globalizeCompiler.extract( \"src.js\" );\n// \u003e [Function]\n```\n\n**Extracting constrains**\n\nGlobal methods and its aliases are extracted, for example:\n\n```js\nGlobalize.numberFormatter( ... );\nGlobalize.formatNumber( ... );\n```\n\nInstance methods and its aliases are NOT extracted, for example:\n\n```js\n// Currently, NOT extracted:\nvar globalize = new Globalize( locale );\nglobalize.numberFormatter( ... );\nglobalize.formatNumber( ... );\n```\n\n#### `.compileExtracts( attributes )`\n\n**attributes** is an *Object* with the following properties:\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp; **extracts** is an Array of extracts obtained by [`.extract()`][].\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp; **defaultLocale** is a locale to be used as `Globalize.locale( defaultLocale )` when generating the extracted formatters and parsers.\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp; **cldr** optional. It's an *Object* with CLDR data (in the JSON format) or a *Function* taking one argument: locale, a *String*; returning an *Object* with the CLDR data for the passed locale. Defaults to the entire supplemental data plus the entire main data for the defaultLocale.\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp; **timeZoneData** optional. It's an *Object* with IANA time zone data (in the JSON format) or a *Function* returning an *Object* with the IANA time zone data. Defaults to the entire IANA time zone data from [iana-tz-data](https://github.com/rxaviers/iana-tz-data) package.\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp; **messages** optional. It's an *Object* with messages data (in the JSON format) or a *Function* taking one argument: locale, a *String*; returning an *Object* with the messages data for the passed locale. Defaults to `{}`.\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp; **template** optional. A function that replaces the default template. See [`.compile()`][] for more details.\n\n**Returns** a *String* with the generated JavaScript bundle as returned by the [`.compile()`][] function.\n\n**Example**\n\n```js\nvar extracts = [ \"src/a.js\", \"src/b.js\" ].map(function( input ) {\n  return GlobalizeCompiler.extract( input );\n});\n\nvar bundle = GlobalizeCompiler.compileExtracts({\n  defaultLocale: \"en\",\n  extracts: extracts\n});\n// \u003e \"A very long String with the generate JavaScript bundle content...\"\n```\n\n**Important** Read [`.extract()`][] for more information about the extracting constrains.\n\n[`.compile()`]: #compile-formattersandparsers-\n[`.compileExtracts()`]: #compileextracts-attributes-\n[`.extract()`]: #extract-input-\n\n## Development\n\n### Tests\n\n    npm install\n    npm test\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobalizejs%2Fglobalize-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglobalizejs%2Fglobalize-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobalizejs%2Fglobalize-compiler/lists"}