Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fluent-bundle/eslint_src.json → eslint_ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"../eslint_src.json"
"./eslint_src.json"
],
"rules": {
"prefer-const": "off",
Expand Down
4 changes: 2 additions & 2 deletions fluent-bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
esm/
index.js
compat.js
/index.js
/compat.js
16 changes: 8 additions & 8 deletions fluent-bundle/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GLOBAL := FluentBundle
include ../common.mk

lint:
@eslint --config ./eslint_src.json --max-warnings 0 src/*.ts
@eslint --config $(ROOT)/eslint_ts.json --max-warnings 0 src/*.ts
@eslint --config $(ROOT)/eslint_test.json --max-warnings 0 test/
@echo -e " $(OK) lint"

Expand All @@ -16,6 +16,13 @@ esm/.compiled: $(SOURCES)
@touch $@
@echo -e " $(OK) esm/ compiled"

.PHONY: test
test: esm/.compiled
@nyc --reporter=text --reporter=html mocha \
--recursive --ui tdd \
--require esm \
test/**/*_test.js

build: index.js compat.js

index.js: esm/.compiled
Expand All @@ -36,13 +43,6 @@ compat.js: esm/.compiled
--output.file $@
@echo -e " $(OK) $@ built"

.PHONY: test
test: esm/.compiled
@nyc --reporter=text --reporter=html mocha \
--recursive --ui tdd \
--require esm \
test/**/*_test.js

html:
@typedoc src \
--out ../html/bundle \
Expand Down
16 changes: 0 additions & 16 deletions fluent-sequence/.esdoc.json

This file was deleted.

1 change: 1 addition & 0 deletions fluent-sequence/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
esm/
/index.js
/compat.js
4 changes: 3 additions & 1 deletion fluent-sequence/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.nyc_output
coverage
docs
esm/.compiled
src
test
makefile
tsconfig.json
38 changes: 32 additions & 6 deletions fluent-sequence/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ GLOBAL := FluentSequence

include ../common.mk

test:
lint:
@eslint --config $(ROOT)/eslint_ts.json --max-warnings 0 src/*.ts
@eslint --config $(ROOT)/eslint_test.json --max-warnings 0 test/
@echo -e " $(OK) lint"

.PHONY: compile
compile: esm/.compiled

esm/.compiled: $(SOURCES)
@tsc
@touch $@
@echo -e " $(OK) esm/ compiled"

.PHONY: test
test: esm/.compiled
@nyc --reporter=text --reporter=html mocha \
--recursive --ui tdd \
--require esm \
Expand All @@ -12,7 +26,7 @@ test:
build: index.js compat.js

index.js: $(SOURCES)
@rollup $(CURDIR)/src/index.js \
@rollup $(CURDIR)/esm/index.js \
--config $(ROOT)/bundle_config.js \
--banner "/* $(PACKAGE)@$(VERSION) */" \
--amd.id $(PACKAGE) \
Expand All @@ -21,14 +35,26 @@ index.js: $(SOURCES)
@echo -e " $(OK) $@ built"

compat.js: $(SOURCES)
@rollup $(CURDIR)/src/index.js \
@rollup $(CURDIR)/esm/index.js \
--config $(ROOT)/compat_config.js \
--banner "/* $(PACKAGE)@$(VERSION) */" \
--amd.id $(PACKAGE) \
--name $(GLOBAL) \
--output.file $@
@echo -e " $(OK) $@ built"

lint: _lint
html: _html
clean: _clean
html:
@typedoc src \
--out ../html/bundle \
--mode file \
--excludeNotExported \
--excludePrivate \
--logger none \
--hideGenerator
@echo -e " $(OK) html build"

clean:
@rm -f esm/*.js esm/*.d.ts esm/.compiled
@rm -f index.js compat.js
@rm -rf .nyc_output coverage
@echo -e " $(OK) clean"
8 changes: 4 additions & 4 deletions fluent-sequence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
"email": "stas@mozilla.com"
}
],
"directories": {
"lib": "./src"
},
"type": "commonjs",
"main": "./index.js",
"module": "./src/index.js",
"module": "./esm/index.js",
"types": "./esm/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/projectfluent/fluent.js.git"
Expand All @@ -32,6 +31,7 @@
"node": ">=10.0.0"
},
"devDependencies": {
"@fluent/bundle": ">= 0.15.0",
"cached-iterable": "^0.2.1"
},
"peerDependencies": {
Expand Down
7 changes: 0 additions & 7 deletions fluent-sequence/src/index.js

This file was deleted.

7 changes: 7 additions & 0 deletions fluent-sequence/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* @module fluent-sequence
* @overview Manage ordered sequences of FluentBundles.
*/

export { mapBundleSync } from "./map_sync.js";
export { mapBundleAsync } from "./map_async.js";
36 changes: 0 additions & 36 deletions fluent-sequence/src/map_async.js

This file was deleted.

52 changes: 52 additions & 0 deletions fluent-sequence/src/map_async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { FluentBundle } from "@fluent/bundle";

export function mapBundleAsync(
bundles: AsyncIterable<FluentBundle>,
ids: string
): Promise<FluentBundle | null>

export function mapBundleAsync(
bundles: AsyncIterable<FluentBundle>,
ids: Array<string>
): Promise<Array<FluentBundle | null>>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there documentation on what these do, in combination with the impl below??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're function overloads: https://www.typescriptlang.org/docs/handbook/functions.html#overloads. They allow specifying extra typing constraints when the implementation is quite loose. E.g. "if you pass an array, expect an array as a result".


/*
* Asynchronously map an identifier or an array of identifiers to the best
* `FluentBundle` instance(s).
*
* @param bundles - An iterable of bundles to sift through.
* @param ids - An id or ids to map.
*/
export async function mapBundleAsync(
bundles: AsyncIterable<FluentBundle>,
ids: string | Array<string>
): Promise<FluentBundle | null | Array<FluentBundle | null>> {
if (!Array.isArray(ids)) {
for await (const bundle of bundles) {
if (bundle.hasMessage(ids)) {
return bundle;
}
}

return null;
}

const foundBundles = new Array(ids.length).fill(null);
let remainingCount = ids.length;

for await (const bundle of bundles) {
for (const [index, id] of ids.entries()) {
if (!foundBundles[index] && bundle.hasMessage(id)) {
foundBundles[index] = bundle;
remainingCount--;
}

// Return early when all ids have been mapped to bundles.
if (remainingCount === 0) {
return foundBundles;
}
}
}

return foundBundles;
}
30 changes: 0 additions & 30 deletions fluent-sequence/src/map_sync.js

This file was deleted.

47 changes: 47 additions & 0 deletions fluent-sequence/src/map_sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FluentBundle } from "@fluent/bundle";

export function mapBundleSync(
bundles: Iterable<FluentBundle>,
ids: string
): FluentBundle | null;

export function mapBundleSync(
bundles: Iterable<FluentBundle>,
ids: Array<string>
): Array<FluentBundle | null>;

/*
* Synchronously map an identifier or an array of identifiers to the best
* `FluentBundle` instance(s).
*
* @param bundles - An iterable of bundles to sift through.
* @param ids - An id or ids to map.
*/
export function mapBundleSync(
bundles: Iterable<FluentBundle>,
ids: string | Array<string>
): FluentBundle | null | Array<FluentBundle | null> {
if (!Array.isArray(ids)) {
return getBundleForId(bundles, ids);
}

return ids.map(
id => getBundleForId(bundles, id)
);
}

/*
* Find the best `FluentBundle` with the translation for `id`.
*/
function getBundleForId(
bundles: Iterable<FluentBundle>,
id: string
): NonNullable<FluentBundle> | null {
for (const bundle of bundles) {
if (bundle.hasMessage(id)) {
return bundle;
}
}

return null;
}
19 changes: 0 additions & 19 deletions fluent-sequence/test/bundle_stub.js

This file was deleted.

Loading