How to use the intl-messageformat-parser.default function in intl-messageformat-parser

To help you get started, we’ve selected a few intl-messageformat-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleChrome / lighthouse / lighthouse-core / scripts / i18n / prune-obsolete-lhl-messages.js View on Github external
/**
 * @license Copyright 2019 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */
'use strict';

const fs = require('fs');
const path = require('path');
const glob = require('glob');
const MessageParser = require('intl-messageformat-parser').default;

const {collectAllCustomElementsFromICU} = require('../../lib/i18n/i18n.js');

/** @typedef {Record} LhlMessages */

/**
 * Returns whether the string `lhlMessage` has ICU arguments matching the
 * already extracted `goldenArgumentIds`. Assumes `goldenArgumentIds` is sorted.
 * @param {Array} goldenArgumentIds
 * @param {string} lhlMessage
 * @return {boolean}
 */
function equalArguments(goldenArgumentIds, lhlMessage) {
  const parsedMessage = MessageParser.parse(lhlMessage);
  const lhlArgumentElements = collectAllCustomElementsFromICU(parsedMessage.elements);
  const lhlArgumentIds = [...lhlArgumentElements.keys()];