• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nodeplusplus / xregex-filter / 299

pending completion
299

Pull #16

circleci

Unknown Committer
Unknown Commit Message
Pull Request #16: Bump json5 from 2.1.2 to 2.2.3

299 of 299 branches covered (100.0%)

Branch coverage included in aggregate %.

293 of 293 relevant lines covered (100.0%)

8.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/filters/datetime/parseStringTime.ts
1
import moment from "moment";
4✔
2

3
import { IXFilterFunction } from "../../types/XFilter";
4

5
const parseStringTime: IXFilterFunction<
6
  string,
7
  any,
8
  IXFilterFunctionParseStringTimeOpts
9
> = function parseStringTime(
4✔
10
  payload: any,
11
  opts?: IXFilterFunctionParseStringTimeOpts
12
): string {
13
  if (!payload || typeof payload !== "string") return payload;
15✔
14
  if (!opts || !opts.pattern || !opts.replace) return payload;
12✔
15

16
  // Cleanup first
17
  const datetime = payload.toLowerCase().trim().replace(/\s\s+/g, " ");
9✔
18
  if (!datetime) return payload;
9✔
19

20
  const { pattern, replace, format, locale } = opts;
7✔
21

22
  let parsedDatetime = datetime.replace(new RegExp(pattern), replace).trim();
7✔
23
  if (!parsedDatetime) return payload;
7✔
24

25
  const datetimeString: string = format
6✔
26
    ? moment(parsedDatetime, format, locale, true).toISOString()
6✔
27
    : parsedDatetime;
28
  if (!moment(datetimeString).isValid()) return payload;
6✔
29

30
  return moment(datetimeString).toISOString();
2✔
31
};
32

33
export default parseStringTime;
4✔
34
export interface IXFilterFunctionParseStringTimeOpts {
35
  pattern: string;
36
  replace: string;
37
  format?: string | string[];
38
  locale?: string;
39
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc