Fix bin/publish: copy docs.dist from project root

Fix bin/publish: use correct .env path for rspade_system
Fix bin/publish script: prevent grep exit code 1 from terminating script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-21 02:08:33 +00:00
commit f6fac6c4bc
79758 changed files with 10547827 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}

View File

@@ -0,0 +1 @@
MIT

View File

@@ -0,0 +1,9 @@
# The JavaScript client for Flare to catch frontend errors
Read the JavaScript error tracking section in [the Flare documentation](https://flareapp.io/docs/javascript-error-tracking/installation) for more information.
React plugin: https://www.npmjs.com/package/@flareapp/flare-react
Vue plugin: https://www.npmjs.com/package/@flareapp/flare-vue
Webpack plugin: https://www.npmjs.com/package/@flareapp/flare-webpack-plugin-sourcemap

View File

@@ -0,0 +1,23 @@
import { Flare } from './types';
export default class FlareClient {
config: Flare.Config;
private glows;
private context;
beforeEvaluate: Flare.BeforeEvaluate;
beforeSubmit: Flare.BeforeSubmit;
private reportedErrorsTimestamps;
private solutionProviders;
private sourcemapVersion;
debug: boolean;
light(key?: string, debug?: boolean): FlareClient;
glow(name: string, level?: Flare.MessageLevel, metaData?: Array<object>): FlareClient;
addContext(name: string, value: any): FlareClient;
addContextGroup(groupName: string, value: object): FlareClient;
registerSolutionProvider(provider: Flare.SolutionProvider): FlareClient;
reportMessage(message: string, context?: Flare.Context, exceptionClass?: string): void;
report(error: Error, context?: Flare.Context, extraSolutionParameters?: Flare.SolutionProviderExtraParameters): void;
createReport(error: Error, context?: Flare.Context, extraSolutionParameters?: Flare.SolutionProviderExtraParameters): Promise<Flare.ErrorReport | false>;
private sendReport;
private maxReportsPerMinuteReached;
test(): FlareClient;
}

View File

@@ -0,0 +1 @@
export default function catchWindowErrors(): void;

View File

@@ -0,0 +1,6 @@
declare const _default: {
flareJsKey: string;
clientVersion: string;
sourcemapVersion: string;
};
export default _default;

View File

@@ -0,0 +1,7 @@
export default function cookie(): {
cookies?: undefined;
} | {
cookies: {
[key: string]: string;
};
};

View File

@@ -0,0 +1,2 @@
import { Flare } from '../types';
export declare function collectContext(additionalContext: object): Flare.Context;

View File

@@ -0,0 +1,8 @@
export default function request(): {
request: {
url: string;
useragent: string;
referrer: string;
readyState: DocumentReadyState;
};
};

View File

@@ -0,0 +1,9 @@
export default function requestData(): {
request_data?: undefined;
} | {
request_data: {
queryString: {
[key: string]: string;
};
};
};

View File

@@ -0,0 +1,3 @@
import FlareClient from './FlareClient';
export { readLinesFromFile } from './stacktrace/fileReader';
export declare const flare: FlareClient;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
import { Flare } from '../types';
export default function getSolutions(solutionProviders: Array<Flare.SolutionProvider>, error: Error, extraSolutionParameters?: Flare.SolutionProviderExtraParameters): Promise<Array<Flare.Solution>>;

View File

@@ -0,0 +1,10 @@
declare type CodeSnippet = {
[key: number]: string;
};
declare type ReaderResponse = {
codeSnippet: CodeSnippet;
trimmedColumnNumber: number | null;
};
export declare function getCodeSnippet(url?: string, lineNumber?: number, columnNumber?: number): Promise<ReaderResponse>;
export declare function readLinesFromFile(fileText: string, lineNumber: number, columnNumber?: number, maxSnippetLineLength?: number, maxSnippetLines?: number): ReaderResponse;
export {};

View File

@@ -0,0 +1,2 @@
import { Flare } from '../types';
export declare function createStackTrace(error: Error): Promise<Array<Flare.StackFrame>>;

View File

@@ -0,0 +1,74 @@
export declare namespace Flare {
type BeforeEvaluate = (error: Error) => Error | false | Promise<Error | false>;
type BeforeSubmit = (report: ErrorReport) => ErrorReport | false | Promise<ErrorReport | false>;
type Config = {
key: string;
reportingUrl: string;
maxGlowsPerReport: number;
maxReportsPerMinute: number;
};
type ErrorReport = {
notifier: string;
exception_class: string;
seen_at: number;
message: string;
language: 'javascript';
glows: Array<Flare.Glow>;
context: Flare.Context;
stacktrace: Array<Flare.StackFrame>;
sourcemap_version_id: string;
solutions: Array<Flare.Solution>;
};
interface SolutionProviderExtraParameters {
}
type SolutionProvider = {
canSolve: (error: Error, extraParameters?: SolutionProviderExtraParameters) => boolean | Promise<boolean>;
getSolutions: (error: Error, extraParameters?: SolutionProviderExtraParameters) => Array<Flare.Solution> | Promise<Array<Flare.Solution>>;
};
type Solution = {
class: string;
title: string;
description: string;
links: {
[label: string]: string;
};
action_description?: string;
is_runnable?: boolean;
};
type Context = {
request?: {
url?: String;
useragent?: String;
referrer?: String;
readyState?: String;
};
request_data?: {
queryString: {
[key: string]: string;
};
};
cookies?: {
[key: string]: string;
};
[key: string]: any;
};
type StackFrame = {
line_number: number;
column_number: number;
method: string;
file: string;
code_snippet: {
[key: number]: string;
};
trimmed_column_number: number | null;
class: string;
};
type Glow = {
time: number;
microtime: number;
name: String;
message_level: MessageLevel;
meta_data: Array<Object>;
};
type MessageLevel = 'info' | 'debug' | 'warning' | 'error' | 'critical';
}

View File

@@ -0,0 +1,4 @@
export declare function assert(value: any, message: string, debug: boolean): boolean;
export declare function flatJsonStringify(json: Object): string;
export declare function now(): number;
export declare function flattenOnce(array: Array<Array<any>>): any[];

View File

@@ -0,0 +1,234 @@
import { assert, now, flatJsonStringify } from './util';
import { collectContext } from './context';
import { createStackTrace } from './stacktrace';
import build from './build';
import getSolutions from './solutions';
import { Flare } from './types';
export default class FlareClient {
public config: Flare.Config = {
key: '',
reportingUrl: 'https://flareapp.io/api/reports',
maxGlowsPerReport: 30,
maxReportsPerMinute: 500,
};
private glows: Array<Flare.Glow> = [];
private context: Flare.Context = { context: {} };
public beforeEvaluate: Flare.BeforeEvaluate = error => error;
public beforeSubmit: Flare.BeforeSubmit = report => report;
private reportedErrorsTimestamps: Array<number> = [];
private solutionProviders: Array<Flare.SolutionProvider> = [];
private sourcemapVersion: string = build.sourcemapVersion;
public debug: boolean = false;
public light(key: string = build.flareJsKey, debug = false): FlareClient {
this.debug = debug;
if (
!assert(
key && typeof key === 'string',
'An empty or incorrect Flare key was passed, errors will not be reported.',
this.debug
) ||
!assert(
Promise,
'ES6 promises are not supported in this environment, errors will not be reported.',
this.debug
)
) {
return this;
}
this.config.key = key;
return this;
}
public glow(name: string, level: Flare.MessageLevel = 'info', metaData: Array<object> = []): FlareClient {
const time = now();
this.glows.push({
name,
message_level: level,
meta_data: metaData,
time,
microtime: time,
});
if (this.glows.length > this.config.maxGlowsPerReport) {
this.glows = this.glows.slice(this.glows.length - this.config.maxGlowsPerReport);
}
return this;
}
public addContext(name: string, value: any): FlareClient {
this.context.context[name] = value;
return this;
}
public addContextGroup(groupName: string, value: object): FlareClient {
this.context[groupName] = value;
return this;
}
public registerSolutionProvider(provider: Flare.SolutionProvider): FlareClient {
if (
!assert(
'canSolve' in provider,
'A solution provider without a [canSolve] property was added.',
this.debug
) ||
!assert(
'getSolutions' in provider,
'A solution provider without a [getSolutions] property was added.',
this.debug
)
) {
return this;
}
this.solutionProviders.push(provider);
return this;
}
public reportMessage(message: string, context: Flare.Context = {}, exceptionClass: string = 'Log'): void {
const seenAt = now();
createStackTrace(Error()).then(stacktrace => {
// The first item in the stacktrace is from this file, and irrelevant
stacktrace.shift();
const report: Flare.ErrorReport = {
notifier: `Flare JavaScript client v${build.clientVersion}`,
exception_class: exceptionClass,
seen_at: seenAt,
message: message,
language: 'javascript',
glows: this.glows,
context: collectContext({ ...context, ...this.context }),
stacktrace,
sourcemap_version_id: this.sourcemapVersion,
solutions: [],
};
this.sendReport(report);
});
}
public report(
error: Error,
context: Flare.Context = {},
extraSolutionParameters: Flare.SolutionProviderExtraParameters = {}
): void {
Promise.resolve(this.beforeEvaluate(error)).then(reportReadyForEvaluation => {
if (!reportReadyForEvaluation) {
return;
}
this.createReport(error, context, extraSolutionParameters).then(report =>
report ? this.sendReport(report) : {}
);
});
}
public createReport(
error: Error,
context: Flare.Context = {},
extraSolutionParameters: Flare.SolutionProviderExtraParameters = {}
): Promise<Flare.ErrorReport | false> {
if (!assert(error, 'No error provided.', this.debug)) {
return Promise.resolve(false);
}
const seenAt = now();
return Promise.all([
getSolutions(this.solutionProviders, error, extraSolutionParameters),
createStackTrace(error),
]).then(result => {
const [solutions, stacktrace] = result;
assert(stacktrace.length, "Couldn't generate stacktrace of this error: " + error, this.debug);
return {
notifier: `Flare JavaScript client v${build.clientVersion}`,
exception_class: error.constructor && error.constructor.name ? error.constructor.name : 'undefined',
seen_at: seenAt,
message: error.message,
language: 'javascript',
glows: this.glows,
context: collectContext({ ...context, ...this.context }),
stacktrace,
sourcemap_version_id: this.sourcemapVersion,
solutions,
};
});
}
private sendReport(report: Flare.ErrorReport): void {
if (
!assert(
this.config.key,
'The client was not yet initialised with an API key. ' +
"Run client.light('<flare-project-key>') when you initialise your app. " +
"If you are running in dev mode and didn't run the light command on purpose, you can ignore this error.",
this.debug
)
) {
return;
}
if (this.maxReportsPerMinuteReached()) {
return;
}
Promise.resolve(this.beforeSubmit(report)).then(reportReadyForSubmit => {
if (!reportReadyForSubmit) {
return;
}
const xhr = new XMLHttpRequest();
xhr.open('POST', this.config.reportingUrl);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('x-api-token', this.config.key);
xhr.send(flatJsonStringify({ ...reportReadyForSubmit, key: this.config.key }));
this.reportedErrorsTimestamps.push(Date.now());
});
}
private maxReportsPerMinuteReached(): boolean {
if (this.reportedErrorsTimestamps.length >= this.config.maxReportsPerMinute) {
const nErrorsBack = this.reportedErrorsTimestamps[
this.reportedErrorsTimestamps.length - this.config.maxReportsPerMinute
];
if (nErrorsBack > Date.now() - 60 * 1000) {
return true;
}
}
return false;
}
public test(): FlareClient {
this.report(new Error('The Flare client is set up correctly!'));
return this;
}
}

View File

@@ -0,0 +1,33 @@
export default function catchWindowErrors() {
const flare = window.flare;
if (!window || !flare) {
return;
}
const originalOnerrorHandler = window.onerror;
const originalOnunhandledrejectionHandler = window.onunhandledrejection;
window.onerror = (_1, _2, _3, _4, error) => {
if (error) {
flare.report(error);
}
if (typeof originalOnerrorHandler === 'function') {
originalOnerrorHandler(_1, _2, _3, _4, error);
}
};
window.onunhandledrejection = (error: PromiseRejectionEvent) => {
if (error.reason instanceof Error) {
flare.report(error.reason);
}
// TODO: Maybe also send errors without stacktrace for unhandled rejections without an Error as reason? (could be a string, …)
if (typeof originalOnunhandledrejectionHandler === 'function') {
// @ts-ignore
originalOnunhandledrejectionHandler(error);
}
};
}

View File

@@ -0,0 +1,9 @@
declare const FLARE_JS_KEY: string | undefined;
declare const FLARE_JS_CLIENT_VERSION: string | undefined;
declare const FLARE_SOURCEMAP_VERSION: string | undefined;
export default {
flareJsKey: typeof FLARE_JS_KEY === 'undefined' ? '' : FLARE_JS_KEY,
clientVersion: typeof FLARE_JS_CLIENT_VERSION === 'undefined' ? '?' : FLARE_JS_CLIENT_VERSION,
sourcemapVersion: typeof FLARE_SOURCEMAP_VERSION === 'undefined' ? '' : FLARE_SOURCEMAP_VERSION,
};

View File

@@ -0,0 +1,17 @@
export default function cookie() {
if (!document.cookie) {
return {};
}
return {
cookies: document.cookie.split('; ').reduce(
(cookies, cookie) => {
const [cookieName, cookieValue] = cookie.split(/=/);
cookies[cookieName] = cookieValue;
return cookies;
},
{} as { [key: string]: string }
),
};
}

View File

@@ -0,0 +1,13 @@
import cookie from './cookie';
import request from './request';
import requestData from './requestData';
import { Flare } from '../types';
export function collectContext(additionalContext: object): Flare.Context {
return {
...cookie(),
...request(),
...requestData(),
...additionalContext,
};
}

View File

@@ -0,0 +1,10 @@
export default function request() {
return {
request: {
url: document.location.href,
useragent: navigator.userAgent,
referrer: document.referrer,
readyState: document.readyState,
},
};
}

View File

@@ -0,0 +1,13 @@
export default function requestData() {
if (!location.search) {
return {};
}
const queryString: { [key: string]: string } = {};
new URLSearchParams(location.search).forEach((value, key) => {
queryString[key] = value;
});
return { request_data: { queryString } };
}

View File

@@ -0,0 +1,11 @@
import FlareClient from './FlareClient';
import catchWindowErrors from './browserClient';
export { readLinesFromFile } from './stacktrace/fileReader';
export const flare = new FlareClient();
if (window) {
window.flare = flare;
}
catchWindowErrors();

View File

@@ -0,0 +1,3 @@
interface Window {
flare: import('./FlareClient').default;
}

View File

@@ -0,0 +1,35 @@
import { flattenOnce } from '../util';
import { Flare } from '../types';
export default function getSolutions(
solutionProviders: Array<Flare.SolutionProvider>,
error: Error,
extraSolutionParameters: Flare.SolutionProviderExtraParameters = {}
): Promise<Array<Flare.Solution>> {
return new Promise(resolve => {
const canSolves = solutionProviders.reduce(
(canSolves, provider) => {
canSolves.push(Promise.resolve(provider.canSolve(error, extraSolutionParameters)));
return canSolves;
},
[] as Array<Promise<boolean>>
);
Promise.all(canSolves).then(resolvedCanSolves => {
const solutionPromises: Array<Promise<Array<Flare.Solution>>> = [];
resolvedCanSolves.forEach((canSolve, i) => {
if (canSolve) {
solutionPromises.push(
Promise.resolve(solutionProviders[i].getSolutions(error, extraSolutionParameters))
);
}
});
Promise.all(solutionPromises).then(solutions => {
resolve(flattenOnce(solutions));
});
});
});
}

View File

@@ -0,0 +1,107 @@
const cachedFiles: { [key: string]: string } = {};
type CodeSnippet = {
[key: number]: string;
};
type ReaderResponse = {
codeSnippet: CodeSnippet;
trimmedColumnNumber: number | null;
};
export function getCodeSnippet(url?: string, lineNumber?: number, columnNumber?: number): Promise<ReaderResponse> {
return new Promise(resolve => {
if (!url || !lineNumber) {
return resolve({
codeSnippet: {
0: `Could not read from file: missing file URL or line number. URL: ${url} lineNumber: ${lineNumber}`,
},
trimmedColumnNumber: null,
});
}
readFile(url).then(fileText => {
if (!fileText) {
return resolve({
codeSnippet: { 0: `Could not read from file: Error while opening file at URL ${url}` },
trimmedColumnNumber: null,
});
}
return resolve(readLinesFromFile(fileText, lineNumber, columnNumber));
});
});
}
function readFile(url: string): Promise<string | null> {
return new Promise(resolve => {
const rawFile = new XMLHttpRequest();
if (cachedFiles[url]) {
return resolve(cachedFiles[url]);
}
rawFile.open('GET', url, false);
rawFile.onreadystatechange = () => {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
cachedFiles[url] = rawFile.responseText;
return resolve(rawFile.responseText);
}
}
return resolve(null);
};
try {
rawFile.send(null);
} catch (error) {
return resolve(null);
}
});
}
export function readLinesFromFile(
fileText: string,
lineNumber: number,
columnNumber?: number,
maxSnippetLineLength = 1000,
maxSnippetLines = 40
): ReaderResponse {
const codeSnippet: CodeSnippet = {};
let trimmedColumnNumber = null;
const lines = fileText.split('\n');
for (let i = -maxSnippetLines / 2; i <= maxSnippetLines / 2; i++) {
const currentLineIndex = lineNumber + i;
if (currentLineIndex >= 0 && lines[currentLineIndex]) {
const displayLine = currentLineIndex + 1; // the linenumber in a stacktrace is not zero-based like an array
if (lines[currentLineIndex].length > maxSnippetLineLength) {
if (columnNumber && columnNumber + maxSnippetLineLength / 2 > maxSnippetLineLength) {
codeSnippet[displayLine] = lines[currentLineIndex].substr(
columnNumber - Math.round(maxSnippetLineLength / 2),
maxSnippetLineLength
);
if (displayLine === lineNumber) {
trimmedColumnNumber = Math.round(maxSnippetLineLength / 2);
}
continue;
}
codeSnippet[displayLine] = lines[currentLineIndex].substr(0, maxSnippetLineLength) + '…';
continue;
}
codeSnippet[displayLine] = lines[currentLineIndex];
}
}
return { codeSnippet, trimmedColumnNumber };
}

View File

@@ -0,0 +1,56 @@
import ErrorStackParser from 'error-stack-parser';
import { getCodeSnippet } from './fileReader';
import { Flare } from '../types';
import { flare } from '..';
import { assert } from '../util';
export function createStackTrace(error: Error): Promise<Array<Flare.StackFrame>> {
return new Promise(resolve => {
if (!hasStack(error)) {
assert(false, "Couldn't generate stacktrace of below error:", flare.debug);
if (flare.debug) {
console.error(error);
}
return resolve([
{
line_number: 0,
column_number: 0,
method: 'unknown',
file: 'unknown',
code_snippet: { 0: 'Could not read from file: stacktrace missing' },
trimmed_column_number: null,
class: 'unknown',
},
]);
}
Promise.all(
ErrorStackParser.parse(error).map(frame => {
return new Promise<Flare.StackFrame>(resolve => {
getCodeSnippet(frame.fileName, frame.lineNumber, frame.columnNumber).then(snippet => {
resolve({
line_number: frame.lineNumber || 1,
column_number: frame.columnNumber || 1,
method: frame.functionName || 'Anonymous or unknown function',
file: frame.fileName || 'Unknown file',
code_snippet: snippet.codeSnippet,
trimmed_column_number: snippet.trimmedColumnNumber,
class: '',
});
});
});
})
).then(resolve);
});
}
function hasStack(err: any): boolean {
return (
!!err &&
(!!err.stack || !!err.stacktrace || !!err['opera#sourceloc']) &&
typeof (err.stack || err.stacktrace || err['opera#sourceloc']) === 'string' &&
err.stack !== `${err.name}: ${err.message}`
);
}

View File

@@ -0,0 +1,78 @@
export namespace Flare {
export type BeforeEvaluate = (error: Error) => Error | false | Promise<Error | false>;
export type BeforeSubmit = (report: ErrorReport) => ErrorReport | false | Promise<ErrorReport | false>;
export type Config = {
key: string;
reportingUrl: string;
maxGlowsPerReport: number;
maxReportsPerMinute: number;
};
export type ErrorReport = {
notifier: string;
exception_class: string;
seen_at: number;
message: string;
language: 'javascript';
glows: Array<Flare.Glow>;
context: Flare.Context;
stacktrace: Array<Flare.StackFrame>;
sourcemap_version_id: string;
solutions: Array<Flare.Solution>;
};
export interface SolutionProviderExtraParameters {}
export type SolutionProvider = {
canSolve: (error: Error, extraParameters?: SolutionProviderExtraParameters) => boolean | Promise<boolean>;
getSolutions: (
error: Error,
extraParameters?: SolutionProviderExtraParameters
) => Array<Flare.Solution> | Promise<Array<Flare.Solution>>;
};
export type Solution = {
class: string;
title: string;
description: string;
links: { [label: string]: string };
action_description?: string;
is_runnable?: boolean;
};
export type Context = {
request?: {
url?: String;
useragent?: String;
referrer?: String; // TODO: Flare doesn't catch this yet
readyState?: String; // TODO: Flare doesn't catch this yet
};
request_data?: {
queryString: { [key: string]: string };
};
cookies?: { [key: string]: string };
[key: string]: any;
};
export type StackFrame = {
line_number: number;
column_number: number; // TODO: Flare doesn't catch this yet
method: string;
file: string;
code_snippet: { [key: number]: string };
trimmed_column_number: number | null;
class: string;
};
export type Glow = {
time: number;
microtime: number;
name: String;
message_level: MessageLevel;
meta_data: Array<Object>;
};
export type MessageLevel = 'info' | 'debug' | 'warning' | 'error' | 'critical';
}

View File

@@ -0,0 +1,42 @@
import build from '../build';
export function assert(value: any, message: string, debug: boolean) {
if (debug && !value) {
console.error(`Flare JavaScript client v${build.clientVersion}: ${message}`);
}
return !!value;
}
// https://stackoverflow.com/a/11616993/6374824
export function flatJsonStringify(json: Object): string {
let cache: any = [];
const flattenedStringifiedJson = JSON.stringify(json, function(_, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
try {
return JSON.parse(JSON.stringify(value));
} catch (error) {
return;
}
}
cache.push(value);
}
return value;
});
cache = null;
return flattenedStringifiedJson;
}
export function now(): number {
return Math.round(Date.now() / 1000);
}
export function flattenOnce(array: Array<Array<any>>) {
return array.reduce((flat, toFlatten) => {
return flat.concat(toFlatten);
}, []);
}

View File

@@ -0,0 +1,56 @@
// @ts-nocheck
import { flare } from '../src/index';
beforeAll(() => {});
it('properly lights', done => {
const projectKey = 'aprojectkey';
flare.light(projectKey);
expect(flare.config.key).toBe(projectKey);
done();
});
it('can create glows', done => {
flare.glow('glowName', undefined, undefined);
expect(flare.glows.length).toBe(1);
expect(flare.glows[0]).toMatchObject({
name: 'glowName',
message_level: 'info',
meta_data: [],
});
expect(typeof flare.glows[0].microtime).toBe('number');
expect(typeof flare.glows[0].time).toBe('number');
done();
});
it.todo('can register solution providers');
it.todo('can use solution providers properly');
it.todo('can use async solution providers properly');
it.todo('can build an error report from an error');
it.todo('can create custom context and context groups');
it.todo('can throttle when too many reports are being sent');
it.todo('can stop a report from being submitted by using beforeSubmit');
it.todo('can use an async beforeSubmit');
it.todo('can edit a report using beforeSubmit and still send it');
it.todo('can stop an error from being evaluated by using beforeEvaluate');
it.todo('can use an async beforeEvaluate');
it.todo('can check out an error using beforeEvaluate and still send it');

View File

@@ -0,0 +1,11 @@
{
"include": ["src"],
"exclude": ["**/tests/*"],
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"noEmit": false,
"jsx": "react"
}
}

View File

@@ -0,0 +1,18 @@
const webpack = require('../../node_modules/webpack');
const merge = require('../../node_modules/webpack-merge');
const path = require('path');
const baseConfig = require('../../webpack.config');
module.exports = merge(baseConfig, {
output: {
library: '@flareapp/flare-client',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new webpack.DefinePlugin({
FLARE_JS_CLIENT_VERSION: JSON.stringify(require('./package.json').version),
}),
],
});

View File

@@ -0,0 +1,18 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[package.json]
indent_size = 2
[*.md]
trim_trailing_whitespace = false

View File

@@ -0,0 +1,28 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/docs export-ignore
/resources/css export-ignore
/resources/js export-ignore
/tests export-ignore
/.babelrc export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.prettierignore export-ignore
/.prettierrc export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/.travis.yml export-ignore
/CONTRIBUTING.md export-ignore
/package-lock.json export-ignore
/phpunit.xml.dist export-ignore
/postcss.config.js export-ignore
/tailwind.config.js export-ignore
/tsconfig.json export-ignore
/tsconfig.dev.json export-ignore
/tsconfig.json export-ignore
/webpack.config.js export-ignore
/yarn.lock export-ignore

View File

@@ -0,0 +1 @@
github: spatie

View File

@@ -0,0 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: Bug Report
url: https://github.com/spatie/ignition/issues/new
about: Report a bug
- name: Feature Request
url: https://github.com/spatie/ignition/discussions/new?category_id=3330702
about: Share ideas for new features
- name: Ask a Question
url: https://github.com/spatie/ignition/discussions/new?category_id=3330701
about: Ask the community for help

View File

@@ -0,0 +1,106 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="SOFT_MARGINS" value="80" />
<HTMLCodeStyleSettings>
<option name="HTML_ATTRIBUTE_WRAP" value="0" />
<option name="HTML_TEXT_WRAP" value="0" />
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="html,body" />
<option name="HTML_DONT_ADD_BREAKS_IF_INLINE_CONTENT" value="title,h1,h2,h3,h4,h5,h6,p,li" />
</HTMLCodeStyleSettings>
<JSCodeStyleSettings version="0">
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</JSCodeStyleSettings>
<JSON>
<option name="SPACE_BEFORE_COLON" value="true" />
</JSON>
<PHPCodeStyleSettings>
<option name="ALIGN_PHPDOC_COMMENTS" value="true" />
<option name="CONCAT_SPACES" value="false" />
<option name="COMMA_AFTER_LAST_ARRAY_ELEMENT" value="true" />
<option name="PHPDOC_BLANK_LINES_AROUND_PARAMETERS" value="true" />
<option name="GROUP_USE_WRAP" value="0" />
<option name="LOWER_CASE_BOOLEAN_CONST" value="true" />
<option name="LOWER_CASE_NULL_CONST" value="true" />
<option name="BLANK_LINES_BEFORE_RETURN_STATEMENT" value="1" />
<option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" />
<option name="SPACE_AFTER_UNARY_NOT" value="true" />
<option name="SPACE_BEFORE_SHORT_CLOSURE_LEFT_PARENTHESIS" value="true" />
<option name="FORCE_SHORT_DECLARATION_ARRAY_STYLE" value="true" />
<option name="NAMESPACE_BRACE_STYLE" value="2" />
</PHPCodeStyleSettings>
<TypeScriptCodeStyleSettings version="0">
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
<option name="IMPORT_PREFER_ABSOLUTE_PATH" value="TRUE" />
</TypeScriptCodeStyleSettings>
<VueCodeStyleSettings>
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
</VueCodeStyleSettings>
<yaml>
<option name="SEQUENCE_ON_NEW_LINE" value="true" />
</yaml>
<codeStyleSettings language="Blade">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="CSS">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="HTML">
<option name="WRAP_ON_TYPING" value="0" />
<option name="SOFT_MARGINS" value="120" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JSON">
<indentOptions>
<option name="INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JavaScript">
<option name="SOFT_MARGINS" value="120" />
</codeStyleSettings>
<codeStyleSettings language="PHP">
<option name="BLANK_LINES_AFTER_PACKAGE" value="1" />
<option name="BLANK_LINES_AROUND_FIELD" value="1" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="SPACE_AFTER_TYPE_CAST" value="true" />
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
</codeStyleSettings>
<codeStyleSettings language="SCSS">
<indentOptions>
<option name="INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="TypeScript">
<option name="SOFT_MARGINS" value="120" />
</codeStyleSettings>
<codeStyleSettings language="Vue">
<option name="SOFT_MARGINS" value="120" />
<indentOptions>
<option name="INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

View File

@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="MultipleExpectChainableInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PhpStanGlobal" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpUnhandledExceptionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PhpUnnecessaryCurlyVarSyntaxInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PsalmGlobal" enabled="false" level="WEAK WARNING" enabled_by_default="false">
<option name="config" value="$PROJECT_DIR$/../laravel-settings/psalm.xml" />
</inspection_tool>
</profile>
</component>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State />
</expanded-state>
<selected-state>
<State>
<id>Angular</id>
</State>
</selected-state>
</profile-state>
</entry>
</component>
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ignition-ui.iml" filepath="$PROJECT_DIR$/.idea/ignition-ui.iml" />
</modules>
</component>
</project>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PsalmOptionsConfiguration">
<option name="config" value="$PROJECT_DIR$/../laravel-settings/psalm.xml" />
<option name="transferred" value="true" />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1 @@
resources/compiled

View File

@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"tabWidth": 4
}

View File

@@ -0,0 +1,181 @@
# Changelog
All notable changes to `ignition-ui` will be documented in this file.
## 4.11.0 - 2024-04-26
- Add support for LiveWire 3
## 4.10.1 - 2024-03-29
- Change context icon
## 4.10.0 - 2024-03-28
- Add support for Laravel Context
## 4.9.5 - 2024-02-01
- Add `noopener` and `noreferrer` to external links
## 4.9.4 - 2023-09-19
- Subtle stacktrace background gradient
## 4.9.3 - 2023-08-24
- Fix: parsing and formatting multiline SQL queries
## 4.9.2 - 2023-08-23
- Fix: apply changes made to the Ignition config immediately
## 4.9.1 - 2023-08-21
- Fix URL encoding in copied paths
## 4.9.0 - 2023-08-21
- Feature: Add 'copy to clipboard' option to editors
## 4.8.2 - 2023-08-18
- Fix: Improve detection of vendor frames for JS frames
## 4.8.1 - 2023-08-17
- Fix: Navigation for custom contexts not working when context name has whitespaces.
## 4.8.0 - 2023-08-11
- Use container queries for responsive components
- Tweak SQL parameter bindings in the query debug tab
- Fix: don't listen to keypress events when typing in input fields or textareas
## 4.7.1 - 2023-07-25
- Only show context section when relevant
## 4.7.0 - 2023-07-25
- Add browser section displaying the user agent
## 4.6.1 - 2023-07-24
- Fix request tab not showing up for JS errors
## 4.6.0 - 2023-06-28
- Add support for stacktrace arguments
## 4.5.0 - 2023-06-06
- Add job section
- Add command section
## 4.4.1 - 2023-05-25
- Include changes from 4.3.0 again
## 4.4.0 - 2023-05-25
- Add support for custom context
- Add support for exception context
- Show SQL bindings inline in debug section
## 4.3.0 - 2023-05-23
- Add export for HighlightedCode component
## 4.2.4 - 2023-05-04
- Fix typo in regex (non-breaking)
## 4.2.3 - 2023-05-04
- Fix extracting SQL queries from Laravel 10 exception messages
## 4.2.2 - 2023-05-02
- Use scroll overflow for code blocks in solutions
- Make AI disclaimer more subtle
## 4.2.1 - 2023-05-02
- Add additional margin in AI solution disclaimer
## 4.2.0 - 2023-04-24
- Add indicator for AI-generated solutions (#10)
- Add support for rendering markdown in solutions (#9)
- Fix vendor frame grouping on Windows (#8)
## 4.1.2 - 2023-04-20
- Only show App section when there is information to show
## 4.0.4 - 2023-02-28
- Old UI not found
- Tweak card UI to better match Laravel's splash screen (#7)
## 4.0.3 - 2023-02-28
- SSR support
- Right-align line numbers in stacktrace
## 4.0.2 - 2022-05-16
- Update `EnvContext` type: can be `null` or `undefined`
- Don't compress bundle (makes debugging easier down the line)
## 4.0.1 - 2022-05-10
- Fix `Context` component when no `queryString` is provided
## 4.0.0 - 2022-05-10
- Flare specific properties have been removed from the `ErrorOccurrence` type (e.g. `id`, `error_id`, `received_at`, ...)
- All `ErrorOccurrence.context_items` are properly typed now
- Removed any untyped `ContextItem`s (no more `{ group:string; name:string; value:any; }` context items)
- Removed `getContextValues` helper because we no longer need to extract data from untyped `ContextItem`s
- Fixed a missing key in `Query` debug section
- Fixed selecting exceptions without accidentally collapsing the error card
### Upgrading
Implementations of the Ignition components, for example `spatie/laraval-ignition` and Flare, should make sure to provide an update `errorOccurrence` object that adheres to the `ErrorOccurrence` type. This mainly involves transforming the `context_items` to their proper types as described in `types/types.d.ts`.
## 3.3.5 - 2022-05-10
- Handle missing stack trace frames better
## 3.3.4 - 2022-04-23
- Log error to console if healthcheck fails
- Fix flash of unstyled content in Livewire modals
## 3.3.3 - 2022-03-04
- Fix errors when there is only one (non-application) frame in the stack
## 3.3.2 - 2022-03-02
- Include types in build
## 3.3.1 - 2022-03-02
- Improve "create GitHub issue" default content
## 3.3.0 - 2022-03-01
- Add error boundaries
## 3.2.0 - 2022-03-01
- Missing editor config will trigger a warning instead of an error
- Add support for `remoteSitesPath` again
## 3.1.0 - 2022-03-01
- Drop URL hashes for current frame and line number (see https://github.com/spatie/laravel-ignition/issues/64)

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Spatie <info@spatie.be>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,16 @@
# Ignition UI
UI components used in Laravel's default Ignition error page.
See [spatie/ignition](https://github.com/spatie/ignition) for more information.
## Tagging a new release
- `yarn dev`
- make required changes
- update CHANGELOG.md
- `yarn publish`
- enter the new version you decided on in CHANGELOG.md
- update `@flareapp/ignition-ui` dependency in `spatie/ignition`
- in `spatie/ignition` run `yarn bundle` (or wait for the GH action)
- publish new version of `spatie/ignition` to packagist

View File

@@ -0,0 +1,173 @@
/**
* prism.js Twilight theme
* Based (more or less) on the Twilight theme originally of Textmate fame.
* @author Remy Bach
*/
code[class*="language-"],
pre[class*="language-"] {
color: white;
background: none;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 1em;
text-align: left;
text-shadow: 0 -.1em .2em black;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"],
:not(pre) > code[class*="language-"] {
background: hsl(0, 0%, 8%); /* #141414 */
}
/* Code blocks */
pre[class*="language-"] {
border-radius: .5em;
border: .3em solid hsl(0, 0%, 33%); /* #282A2B */
box-shadow: 1px 1px .5em black inset;
margin: .5em 0;
overflow: auto;
padding: 1em;
}
pre[class*="language-"]::-moz-selection {
/* Firefox */
background: hsl(200, 4%, 16%); /* #282A2B */
}
pre[class*="language-"]::selection {
/* Safari */
background: hsl(200, 4%, 16%); /* #282A2B */
}
/* Text Selection colour */
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
}
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
}
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
}
/* Inline code */
:not(pre) > code[class*="language-"] {
border-radius: .3em;
border: .13em solid hsl(0, 0%, 33%); /* #545454 */
box-shadow: 1px 1px .3em -.1em black inset;
padding: .15em .2em .05em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: hsl(0, 0%, 47%); /* #777777 */
}
.token.punctuation {
opacity: .7;
}
.token.namespace {
opacity: .7;
}
.token.tag,
.token.boolean,
.token.number,
.token.deleted {
color: hsl(14, 58%, 55%); /* #CF6A4C */
}
.token.keyword,
.token.property,
.token.selector,
.token.constant,
.token.symbol,
.token.builtin {
color: hsl(53, 89%, 79%); /* #F9EE98 */
}
.token.attr-name,
.token.attr-value,
.token.string,
.token.char,
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string,
.token.variable,
.token.inserted {
color: hsl(76, 21%, 52%); /* #8F9D6A */
}
.token.atrule {
color: hsl(218, 22%, 55%); /* #7587A6 */
}
.token.regex,
.token.important {
color: hsl(42, 75%, 65%); /* #E9C062 */
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
/* Markup */
.language-markup .token.tag,
.language-markup .token.attr-name,
.language-markup .token.punctuation {
color: hsl(33, 33%, 52%); /* #AC885B */
}
/* Make the tokens sit above the line highlight so the colours don't look faded. */
.token {
position: relative;
z-index: 1;
}
.line-highlight.line-highlight {
background: hsla(0, 0%, 33%, 0.25); /* #545454 */
background: linear-gradient(to right, hsla(0, 0%, 33%, .1) 70%, hsla(0, 0%, 33%, 0)); /* #545454 */
border-bottom: 1px dashed hsl(0, 0%, 33%); /* #545454 */
border-top: 1px dashed hsl(0, 0%, 33%); /* #545454 */
margin-top: 0.75em; /* Same as .prisms padding-top */
z-index: 0;
}
.line-highlight.line-highlight:before,
.line-highlight.line-highlight[data-end]:after {
background-color: hsl(215, 15%, 59%); /* #8794A6 */
color: hsl(24, 20%, 95%); /* #F5F2F0 */
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
../../../../sql-formatter/bin/sqlfmt.js

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Sasha Koss and Lesha Koss https://kossnocorp.mit-license.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,69 @@
<p align="center">
<a href="https://date-fns.org/">
<img alt="date-fns" title="date-fns" src="https://raw.githubusercontent.com/date-fns/date-fns/master/docs/logotype.svg" width="300" />
</a>
</p>
<p align="center">
<b>date-fns</b> provides the most comprehensive, yet simple and consistent toolset
<br>
for manipulating <b>JavaScript dates</b> in <b>a browser</b> & <b>Node.js</b>.</b>
</p>
<div align="center">
[📖&nbsp; Documentation](https://date-fns.org/docs/Getting-Started/)&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;[🧑‍💻&nbsp; JavaScript Jobs](https://jobs.date-fns.org/)
</div>
<hr>
# It's like [Lodash](https://lodash.com) for dates
- It has [**200+ functions** for all occasions](https://date-fns.org/docs/Getting-Started/).
- **Modular**: Pick what you need. Works with webpack, Browserify, or Rollup and also supports tree-shaking.
- **Native dates**: Uses existing native type. It doesn't extend core objects for safety's sake.
- **Immutable & Pure**: Built using pure functions and always returns a new date instance.
- **TypeScript & Flow**: Supports both Flow and TypeScript
- **I18n**: Dozens of locales. Include only what you need.
- [and many more benefits](https://date-fns.org/)
```js
import { compareAsc, format } from 'date-fns'
format(new Date(2014, 1, 11), 'yyyy-MM-dd')
//=> '2014-02-11'
const dates = [
new Date(1995, 6, 2),
new Date(1987, 1, 11),
new Date(1989, 6, 10),
]
dates.sort(compareAsc)
//=> [
// Wed Feb 11 1987 00:00:00,
// Mon Jul 10 1989 00:00:00,
// Sun Jul 02 1995 00:00:00
// ]
```
The library is available as an [npm package](https://www.npmjs.com/package/date-fns).
To install the package run:
```bash
npm install date-fns --save
# or with yarn
yarn add date-fns
```
## Docs
[See date-fns.org](https://date-fns.org/) for more details, API,
and other docs.
<br />
<!-- END OF README-JOB SECTION -->
## License
[MIT © Sasha Koss](https://kossnocorp.mit-license.org/)

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = addLeadingZeros;
function addLeadingZeros(number, targetLength) {
var sign = number < 0 ? '-' : '';
var output = Math.abs(number).toString();
while (output.length < targetLength) {
output = '0' + output;
}
return sign + output;
}
module.exports = exports.default;

View File

@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = assign;
function assign(target, dirtyObject) {
if (target == null) {
throw new TypeError('assign requires that input parameter not be null or undefined');
}
dirtyObject = dirtyObject || {};
for (var property in dirtyObject) {
if (Object.prototype.hasOwnProperty.call(dirtyObject, property)) {
target[property] = dirtyObject[property];
}
}
return target;
}
module.exports = exports.default;

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = cloneObject;
var _index = _interopRequireDefault(require("../assign/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function cloneObject(dirtyObject) {
return (0, _index.default)({}, dirtyObject);
}
module.exports = exports.default;

View File

@@ -0,0 +1,884 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _index = _interopRequireDefault(require("../../../_lib/getUTCDayOfYear/index.js"));
var _index2 = _interopRequireDefault(require("../../../_lib/getUTCISOWeek/index.js"));
var _index3 = _interopRequireDefault(require("../../../_lib/getUTCISOWeekYear/index.js"));
var _index4 = _interopRequireDefault(require("../../../_lib/getUTCWeek/index.js"));
var _index5 = _interopRequireDefault(require("../../../_lib/getUTCWeekYear/index.js"));
var _index6 = _interopRequireDefault(require("../../addLeadingZeros/index.js"));
var _index7 = _interopRequireDefault(require("../lightFormatters/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var dayPeriodEnum = {
am: 'am',
pm: 'pm',
midnight: 'midnight',
noon: 'noon',
morning: 'morning',
afternoon: 'afternoon',
evening: 'evening',
night: 'night'
};
/*
* | | Unit | | Unit |
* |-----|--------------------------------|-----|--------------------------------|
* | a | AM, PM | A* | Milliseconds in day |
* | b | AM, PM, noon, midnight | B | Flexible day period |
* | c | Stand-alone local day of week | C* | Localized hour w/ day period |
* | d | Day of month | D | Day of year |
* | e | Local day of week | E | Day of week |
* | f | | F* | Day of week in month |
* | g* | Modified Julian day | G | Era |
* | h | Hour [1-12] | H | Hour [0-23] |
* | i! | ISO day of week | I! | ISO week of year |
* | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
* | k | Hour [1-24] | K | Hour [0-11] |
* | l* | (deprecated) | L | Stand-alone month |
* | m | Minute | M | Month |
* | n | | N | |
* | o! | Ordinal number modifier | O | Timezone (GMT) |
* | p! | Long localized time | P! | Long localized date |
* | q | Stand-alone quarter | Q | Quarter |
* | r* | Related Gregorian year | R! | ISO week-numbering year |
* | s | Second | S | Fraction of second |
* | t! | Seconds timestamp | T! | Milliseconds timestamp |
* | u | Extended year | U* | Cyclic year |
* | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
* | w | Local week of year | W* | Week of month |
* | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
* | y | Year (abs) | Y | Local week-numbering year |
* | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
*
* Letters marked by * are not implemented but reserved by Unicode standard.
*
* Letters marked by ! are non-standard, but implemented by date-fns:
* - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
* - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
* i.e. 7 for Sunday, 1 for Monday, etc.
* - `I` is ISO week of year, as opposed to `w` which is local week of year.
* - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
* `R` is supposed to be used in conjunction with `I` and `i`
* for universal ISO week-numbering date, whereas
* `Y` is supposed to be used in conjunction with `w` and `e`
* for week-numbering date specific to the locale.
* - `P` is long localized date format
* - `p` is long localized time format
*/
var formatters = {
// Era
G: function (date, token, localize) {
var era = date.getUTCFullYear() > 0 ? 1 : 0;
switch (token) {
// AD, BC
case 'G':
case 'GG':
case 'GGG':
return localize.era(era, {
width: 'abbreviated'
});
// A, B
case 'GGGGG':
return localize.era(era, {
width: 'narrow'
});
// Anno Domini, Before Christ
case 'GGGG':
default:
return localize.era(era, {
width: 'wide'
});
}
},
// Year
y: function (date, token, localize) {
// Ordinal number
if (token === 'yo') {
var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript)
var year = signedYear > 0 ? signedYear : 1 - signedYear;
return localize.ordinalNumber(year, {
unit: 'year'
});
}
return _index7.default.y(date, token);
},
// Local week-numbering year
Y: function (date, token, localize, options) {
var signedWeekYear = (0, _index5.default)(date, options); // Returns 1 for 1 BC (which is year 0 in JavaScript)
var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear; // Two digit year
if (token === 'YY') {
var twoDigitYear = weekYear % 100;
return (0, _index6.default)(twoDigitYear, 2);
} // Ordinal number
if (token === 'Yo') {
return localize.ordinalNumber(weekYear, {
unit: 'year'
});
} // Padding
return (0, _index6.default)(weekYear, token.length);
},
// ISO week-numbering year
R: function (date, token) {
var isoWeekYear = (0, _index3.default)(date); // Padding
return (0, _index6.default)(isoWeekYear, token.length);
},
// Extended year. This is a single number designating the year of this calendar system.
// The main difference between `y` and `u` localizers are B.C. years:
// | Year | `y` | `u` |
// |------|-----|-----|
// | AC 1 | 1 | 1 |
// | BC 1 | 1 | 0 |
// | BC 2 | 2 | -1 |
// Also `yy` always returns the last two digits of a year,
// while `uu` pads single digit years to 2 characters and returns other years unchanged.
u: function (date, token) {
var year = date.getUTCFullYear();
return (0, _index6.default)(year, token.length);
},
// Quarter
Q: function (date, token, localize) {
var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
switch (token) {
// 1, 2, 3, 4
case 'Q':
return String(quarter);
// 01, 02, 03, 04
case 'QQ':
return (0, _index6.default)(quarter, 2);
// 1st, 2nd, 3rd, 4th
case 'Qo':
return localize.ordinalNumber(quarter, {
unit: 'quarter'
});
// Q1, Q2, Q3, Q4
case 'QQQ':
return localize.quarter(quarter, {
width: 'abbreviated',
context: 'formatting'
});
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
case 'QQQQQ':
return localize.quarter(quarter, {
width: 'narrow',
context: 'formatting'
});
// 1st quarter, 2nd quarter, ...
case 'QQQQ':
default:
return localize.quarter(quarter, {
width: 'wide',
context: 'formatting'
});
}
},
// Stand-alone quarter
q: function (date, token, localize) {
var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
switch (token) {
// 1, 2, 3, 4
case 'q':
return String(quarter);
// 01, 02, 03, 04
case 'qq':
return (0, _index6.default)(quarter, 2);
// 1st, 2nd, 3rd, 4th
case 'qo':
return localize.ordinalNumber(quarter, {
unit: 'quarter'
});
// Q1, Q2, Q3, Q4
case 'qqq':
return localize.quarter(quarter, {
width: 'abbreviated',
context: 'standalone'
});
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
case 'qqqqq':
return localize.quarter(quarter, {
width: 'narrow',
context: 'standalone'
});
// 1st quarter, 2nd quarter, ...
case 'qqqq':
default:
return localize.quarter(quarter, {
width: 'wide',
context: 'standalone'
});
}
},
// Month
M: function (date, token, localize) {
var month = date.getUTCMonth();
switch (token) {
case 'M':
case 'MM':
return _index7.default.M(date, token);
// 1st, 2nd, ..., 12th
case 'Mo':
return localize.ordinalNumber(month + 1, {
unit: 'month'
});
// Jan, Feb, ..., Dec
case 'MMM':
return localize.month(month, {
width: 'abbreviated',
context: 'formatting'
});
// J, F, ..., D
case 'MMMMM':
return localize.month(month, {
width: 'narrow',
context: 'formatting'
});
// January, February, ..., December
case 'MMMM':
default:
return localize.month(month, {
width: 'wide',
context: 'formatting'
});
}
},
// Stand-alone month
L: function (date, token, localize) {
var month = date.getUTCMonth();
switch (token) {
// 1, 2, ..., 12
case 'L':
return String(month + 1);
// 01, 02, ..., 12
case 'LL':
return (0, _index6.default)(month + 1, 2);
// 1st, 2nd, ..., 12th
case 'Lo':
return localize.ordinalNumber(month + 1, {
unit: 'month'
});
// Jan, Feb, ..., Dec
case 'LLL':
return localize.month(month, {
width: 'abbreviated',
context: 'standalone'
});
// J, F, ..., D
case 'LLLLL':
return localize.month(month, {
width: 'narrow',
context: 'standalone'
});
// January, February, ..., December
case 'LLLL':
default:
return localize.month(month, {
width: 'wide',
context: 'standalone'
});
}
},
// Local week of year
w: function (date, token, localize, options) {
var week = (0, _index4.default)(date, options);
if (token === 'wo') {
return localize.ordinalNumber(week, {
unit: 'week'
});
}
return (0, _index6.default)(week, token.length);
},
// ISO week of year
I: function (date, token, localize) {
var isoWeek = (0, _index2.default)(date);
if (token === 'Io') {
return localize.ordinalNumber(isoWeek, {
unit: 'week'
});
}
return (0, _index6.default)(isoWeek, token.length);
},
// Day of the month
d: function (date, token, localize) {
if (token === 'do') {
return localize.ordinalNumber(date.getUTCDate(), {
unit: 'date'
});
}
return _index7.default.d(date, token);
},
// Day of year
D: function (date, token, localize) {
var dayOfYear = (0, _index.default)(date);
if (token === 'Do') {
return localize.ordinalNumber(dayOfYear, {
unit: 'dayOfYear'
});
}
return (0, _index6.default)(dayOfYear, token.length);
},
// Day of week
E: function (date, token, localize) {
var dayOfWeek = date.getUTCDay();
switch (token) {
// Tue
case 'E':
case 'EE':
case 'EEE':
return localize.day(dayOfWeek, {
width: 'abbreviated',
context: 'formatting'
});
// T
case 'EEEEE':
return localize.day(dayOfWeek, {
width: 'narrow',
context: 'formatting'
});
// Tu
case 'EEEEEE':
return localize.day(dayOfWeek, {
width: 'short',
context: 'formatting'
});
// Tuesday
case 'EEEE':
default:
return localize.day(dayOfWeek, {
width: 'wide',
context: 'formatting'
});
}
},
// Local day of week
e: function (date, token, localize, options) {
var dayOfWeek = date.getUTCDay();
var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
switch (token) {
// Numerical value (Nth day of week with current locale or weekStartsOn)
case 'e':
return String(localDayOfWeek);
// Padded numerical value
case 'ee':
return (0, _index6.default)(localDayOfWeek, 2);
// 1st, 2nd, ..., 7th
case 'eo':
return localize.ordinalNumber(localDayOfWeek, {
unit: 'day'
});
case 'eee':
return localize.day(dayOfWeek, {
width: 'abbreviated',
context: 'formatting'
});
// T
case 'eeeee':
return localize.day(dayOfWeek, {
width: 'narrow',
context: 'formatting'
});
// Tu
case 'eeeeee':
return localize.day(dayOfWeek, {
width: 'short',
context: 'formatting'
});
// Tuesday
case 'eeee':
default:
return localize.day(dayOfWeek, {
width: 'wide',
context: 'formatting'
});
}
},
// Stand-alone local day of week
c: function (date, token, localize, options) {
var dayOfWeek = date.getUTCDay();
var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
switch (token) {
// Numerical value (same as in `e`)
case 'c':
return String(localDayOfWeek);
// Padded numerical value
case 'cc':
return (0, _index6.default)(localDayOfWeek, token.length);
// 1st, 2nd, ..., 7th
case 'co':
return localize.ordinalNumber(localDayOfWeek, {
unit: 'day'
});
case 'ccc':
return localize.day(dayOfWeek, {
width: 'abbreviated',
context: 'standalone'
});
// T
case 'ccccc':
return localize.day(dayOfWeek, {
width: 'narrow',
context: 'standalone'
});
// Tu
case 'cccccc':
return localize.day(dayOfWeek, {
width: 'short',
context: 'standalone'
});
// Tuesday
case 'cccc':
default:
return localize.day(dayOfWeek, {
width: 'wide',
context: 'standalone'
});
}
},
// ISO day of week
i: function (date, token, localize) {
var dayOfWeek = date.getUTCDay();
var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
switch (token) {
// 2
case 'i':
return String(isoDayOfWeek);
// 02
case 'ii':
return (0, _index6.default)(isoDayOfWeek, token.length);
// 2nd
case 'io':
return localize.ordinalNumber(isoDayOfWeek, {
unit: 'day'
});
// Tue
case 'iii':
return localize.day(dayOfWeek, {
width: 'abbreviated',
context: 'formatting'
});
// T
case 'iiiii':
return localize.day(dayOfWeek, {
width: 'narrow',
context: 'formatting'
});
// Tu
case 'iiiiii':
return localize.day(dayOfWeek, {
width: 'short',
context: 'formatting'
});
// Tuesday
case 'iiii':
default:
return localize.day(dayOfWeek, {
width: 'wide',
context: 'formatting'
});
}
},
// AM or PM
a: function (date, token, localize) {
var hours = date.getUTCHours();
var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
switch (token) {
case 'a':
case 'aa':
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'abbreviated',
context: 'formatting'
});
case 'aaa':
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'abbreviated',
context: 'formatting'
}).toLowerCase();
case 'aaaaa':
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'narrow',
context: 'formatting'
});
case 'aaaa':
default:
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'wide',
context: 'formatting'
});
}
},
// AM, PM, midnight, noon
b: function (date, token, localize) {
var hours = date.getUTCHours();
var dayPeriodEnumValue;
if (hours === 12) {
dayPeriodEnumValue = dayPeriodEnum.noon;
} else if (hours === 0) {
dayPeriodEnumValue = dayPeriodEnum.midnight;
} else {
dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
}
switch (token) {
case 'b':
case 'bb':
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'abbreviated',
context: 'formatting'
});
case 'bbb':
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'abbreviated',
context: 'formatting'
}).toLowerCase();
case 'bbbbb':
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'narrow',
context: 'formatting'
});
case 'bbbb':
default:
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'wide',
context: 'formatting'
});
}
},
// in the morning, in the afternoon, in the evening, at night
B: function (date, token, localize) {
var hours = date.getUTCHours();
var dayPeriodEnumValue;
if (hours >= 17) {
dayPeriodEnumValue = dayPeriodEnum.evening;
} else if (hours >= 12) {
dayPeriodEnumValue = dayPeriodEnum.afternoon;
} else if (hours >= 4) {
dayPeriodEnumValue = dayPeriodEnum.morning;
} else {
dayPeriodEnumValue = dayPeriodEnum.night;
}
switch (token) {
case 'B':
case 'BB':
case 'BBB':
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'abbreviated',
context: 'formatting'
});
case 'BBBBB':
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'narrow',
context: 'formatting'
});
case 'BBBB':
default:
return localize.dayPeriod(dayPeriodEnumValue, {
width: 'wide',
context: 'formatting'
});
}
},
// Hour [1-12]
h: function (date, token, localize) {
if (token === 'ho') {
var hours = date.getUTCHours() % 12;
if (hours === 0) hours = 12;
return localize.ordinalNumber(hours, {
unit: 'hour'
});
}
return _index7.default.h(date, token);
},
// Hour [0-23]
H: function (date, token, localize) {
if (token === 'Ho') {
return localize.ordinalNumber(date.getUTCHours(), {
unit: 'hour'
});
}
return _index7.default.H(date, token);
},
// Hour [0-11]
K: function (date, token, localize) {
var hours = date.getUTCHours() % 12;
if (token === 'Ko') {
return localize.ordinalNumber(hours, {
unit: 'hour'
});
}
return (0, _index6.default)(hours, token.length);
},
// Hour [1-24]
k: function (date, token, localize) {
var hours = date.getUTCHours();
if (hours === 0) hours = 24;
if (token === 'ko') {
return localize.ordinalNumber(hours, {
unit: 'hour'
});
}
return (0, _index6.default)(hours, token.length);
},
// Minute
m: function (date, token, localize) {
if (token === 'mo') {
return localize.ordinalNumber(date.getUTCMinutes(), {
unit: 'minute'
});
}
return _index7.default.m(date, token);
},
// Second
s: function (date, token, localize) {
if (token === 'so') {
return localize.ordinalNumber(date.getUTCSeconds(), {
unit: 'second'
});
}
return _index7.default.s(date, token);
},
// Fraction of second
S: function (date, token) {
return _index7.default.S(date, token);
},
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
X: function (date, token, _localize, options) {
var originalDate = options._originalDate || date;
var timezoneOffset = originalDate.getTimezoneOffset();
if (timezoneOffset === 0) {
return 'Z';
}
switch (token) {
// Hours and optional minutes
case 'X':
return formatTimezoneWithOptionalMinutes(timezoneOffset);
// Hours, minutes and optional seconds without `:` delimiter
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
// so this token always has the same output as `XX`
case 'XXXX':
case 'XX':
// Hours and minutes without `:` delimiter
return formatTimezone(timezoneOffset);
// Hours, minutes and optional seconds with `:` delimiter
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
// so this token always has the same output as `XXX`
case 'XXXXX':
case 'XXX': // Hours and minutes with `:` delimiter
default:
return formatTimezone(timezoneOffset, ':');
}
},
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
x: function (date, token, _localize, options) {
var originalDate = options._originalDate || date;
var timezoneOffset = originalDate.getTimezoneOffset();
switch (token) {
// Hours and optional minutes
case 'x':
return formatTimezoneWithOptionalMinutes(timezoneOffset);
// Hours, minutes and optional seconds without `:` delimiter
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
// so this token always has the same output as `xx`
case 'xxxx':
case 'xx':
// Hours and minutes without `:` delimiter
return formatTimezone(timezoneOffset);
// Hours, minutes and optional seconds with `:` delimiter
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
// so this token always has the same output as `xxx`
case 'xxxxx':
case 'xxx': // Hours and minutes with `:` delimiter
default:
return formatTimezone(timezoneOffset, ':');
}
},
// Timezone (GMT)
O: function (date, token, _localize, options) {
var originalDate = options._originalDate || date;
var timezoneOffset = originalDate.getTimezoneOffset();
switch (token) {
// Short
case 'O':
case 'OO':
case 'OOO':
return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
// Long
case 'OOOO':
default:
return 'GMT' + formatTimezone(timezoneOffset, ':');
}
},
// Timezone (specific non-location)
z: function (date, token, _localize, options) {
var originalDate = options._originalDate || date;
var timezoneOffset = originalDate.getTimezoneOffset();
switch (token) {
// Short
case 'z':
case 'zz':
case 'zzz':
return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
// Long
case 'zzzz':
default:
return 'GMT' + formatTimezone(timezoneOffset, ':');
}
},
// Seconds timestamp
t: function (date, token, _localize, options) {
var originalDate = options._originalDate || date;
var timestamp = Math.floor(originalDate.getTime() / 1000);
return (0, _index6.default)(timestamp, token.length);
},
// Milliseconds timestamp
T: function (date, token, _localize, options) {
var originalDate = options._originalDate || date;
var timestamp = originalDate.getTime();
return (0, _index6.default)(timestamp, token.length);
}
};
function formatTimezoneShort(offset, dirtyDelimiter) {
var sign = offset > 0 ? '-' : '+';
var absOffset = Math.abs(offset);
var hours = Math.floor(absOffset / 60);
var minutes = absOffset % 60;
if (minutes === 0) {
return sign + String(hours);
}
var delimiter = dirtyDelimiter || '';
return sign + String(hours) + delimiter + (0, _index6.default)(minutes, 2);
}
function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
if (offset % 60 === 0) {
var sign = offset > 0 ? '-' : '+';
return sign + (0, _index6.default)(Math.abs(offset) / 60, 2);
}
return formatTimezone(offset, dirtyDelimiter);
}
function formatTimezone(offset, dirtyDelimiter) {
var delimiter = dirtyDelimiter || '';
var sign = offset > 0 ? '-' : '+';
var absOffset = Math.abs(offset);
var hours = (0, _index6.default)(Math.floor(absOffset / 60), 2);
var minutes = (0, _index6.default)(absOffset % 60, 2);
return sign + hours + delimiter + minutes;
}
var _default = formatters;
exports.default = _default;
module.exports = exports.default;

View File

@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _index = _interopRequireDefault(require("../../addLeadingZeros/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
* | | Unit | | Unit |
* |-----|--------------------------------|-----|--------------------------------|
* | a | AM, PM | A* | |
* | d | Day of month | D | |
* | h | Hour [1-12] | H | Hour [0-23] |
* | m | Minute | M | Month |
* | s | Second | S | Fraction of second |
* | y | Year (abs) | Y | |
*
* Letters marked by * are not implemented but reserved by Unicode standard.
*/
var formatters = {
// Year
y: function (date, token) {
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
// | Year | y | yy | yyy | yyyy | yyyyy |
// |----------|-------|----|-------|-------|-------|
// | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
// | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
// | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
// | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
// | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript)
var year = signedYear > 0 ? signedYear : 1 - signedYear;
return (0, _index.default)(token === 'yy' ? year % 100 : year, token.length);
},
// Month
M: function (date, token) {
var month = date.getUTCMonth();
return token === 'M' ? String(month + 1) : (0, _index.default)(month + 1, 2);
},
// Day of the month
d: function (date, token) {
return (0, _index.default)(date.getUTCDate(), token.length);
},
// AM or PM
a: function (date, token) {
var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
switch (token) {
case 'a':
case 'aa':
return dayPeriodEnumValue.toUpperCase();
case 'aaa':
return dayPeriodEnumValue;
case 'aaaaa':
return dayPeriodEnumValue[0];
case 'aaaa':
default:
return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
}
},
// Hour [1-12]
h: function (date, token) {
return (0, _index.default)(date.getUTCHours() % 12 || 12, token.length);
},
// Hour [0-23]
H: function (date, token) {
return (0, _index.default)(date.getUTCHours(), token.length);
},
// Minute
m: function (date, token) {
return (0, _index.default)(date.getUTCMinutes(), token.length);
},
// Second
s: function (date, token) {
return (0, _index.default)(date.getUTCSeconds(), token.length);
},
// Fraction of second
S: function (date, token) {
var numberOfDigits = token.length;
var milliseconds = date.getUTCMilliseconds();
var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
return (0, _index.default)(fractionalSeconds, token.length);
}
};
var _default = formatters;
exports.default = _default;
module.exports = exports.default;

View File

@@ -0,0 +1,105 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function dateLongFormatter(pattern, formatLong) {
switch (pattern) {
case 'P':
return formatLong.date({
width: 'short'
});
case 'PP':
return formatLong.date({
width: 'medium'
});
case 'PPP':
return formatLong.date({
width: 'long'
});
case 'PPPP':
default:
return formatLong.date({
width: 'full'
});
}
}
function timeLongFormatter(pattern, formatLong) {
switch (pattern) {
case 'p':
return formatLong.time({
width: 'short'
});
case 'pp':
return formatLong.time({
width: 'medium'
});
case 'ppp':
return formatLong.time({
width: 'long'
});
case 'pppp':
default:
return formatLong.time({
width: 'full'
});
}
}
function dateTimeLongFormatter(pattern, formatLong) {
var matchResult = pattern.match(/(P+)(p+)?/) || [];
var datePattern = matchResult[1];
var timePattern = matchResult[2];
if (!timePattern) {
return dateLongFormatter(pattern, formatLong);
}
var dateTimeFormat;
switch (datePattern) {
case 'P':
dateTimeFormat = formatLong.dateTime({
width: 'short'
});
break;
case 'PP':
dateTimeFormat = formatLong.dateTime({
width: 'medium'
});
break;
case 'PPP':
dateTimeFormat = formatLong.dateTime({
width: 'long'
});
break;
case 'PPPP':
default:
dateTimeFormat = formatLong.dateTime({
width: 'full'
});
break;
}
return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
}
var longFormatters = {
p: timeLongFormatter,
P: dateTimeLongFormatter
};
var _default = longFormatters;
exports.default = _default;
module.exports = exports.default;

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getTimezoneOffsetInMilliseconds;
/**
* Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
* They usually appear for dates that denote time before the timezones were introduced
* (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
* and GMT+01:00:00 after that date)
*
* Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
* which would lead to incorrect calculations.
*
* This function returns the timezone offset in milliseconds that takes seconds in account.
*/
function getTimezoneOffsetInMilliseconds(date) {
var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
utcDate.setUTCFullYear(date.getFullYear());
return date.getTime() - utcDate.getTime();
}
module.exports = exports.default;

View File

@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getUTCDayOfYear;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var MILLISECONDS_IN_DAY = 86400000; // This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCDayOfYear(dirtyDate) {
(0, _index2.default)(1, arguments);
var date = (0, _index.default)(dirtyDate);
var timestamp = date.getTime();
date.setUTCMonth(0, 1);
date.setUTCHours(0, 0, 0, 0);
var startOfYearTimestamp = date.getTime();
var difference = timestamp - startOfYearTimestamp;
return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
}
module.exports = exports.default;

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getUTCISOWeek;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../startOfUTCISOWeek/index.js"));
var _index3 = _interopRequireDefault(require("../startOfUTCISOWeekYear/index.js"));
var _index4 = _interopRequireDefault(require("../requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var MILLISECONDS_IN_WEEK = 604800000; // This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCISOWeek(dirtyDate) {
(0, _index4.default)(1, arguments);
var date = (0, _index.default)(dirtyDate);
var diff = (0, _index2.default)(date).getTime() - (0, _index3.default)(date).getTime(); // Round the number of days to the nearest integer
// because the number of milliseconds in a week is not constant
// (e.g. it's different in the week of the daylight saving time clock shift)
return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
}
module.exports = exports.default;

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getUTCISOWeekYear;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../requiredArgs/index.js"));
var _index3 = _interopRequireDefault(require("../startOfUTCISOWeek/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCISOWeekYear(dirtyDate) {
(0, _index2.default)(1, arguments);
var date = (0, _index.default)(dirtyDate);
var year = date.getUTCFullYear();
var fourthOfJanuaryOfNextYear = new Date(0);
fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
var startOfNextYear = (0, _index3.default)(fourthOfJanuaryOfNextYear);
var fourthOfJanuaryOfThisYear = new Date(0);
fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
var startOfThisYear = (0, _index3.default)(fourthOfJanuaryOfThisYear);
if (date.getTime() >= startOfNextYear.getTime()) {
return year + 1;
} else if (date.getTime() >= startOfThisYear.getTime()) {
return year;
} else {
return year - 1;
}
}
module.exports = exports.default;

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getUTCWeek;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
var _index3 = _interopRequireDefault(require("../startOfUTCWeekYear/index.js"));
var _index4 = _interopRequireDefault(require("../requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var MILLISECONDS_IN_WEEK = 604800000; // This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCWeek(dirtyDate, options) {
(0, _index4.default)(1, arguments);
var date = (0, _index.default)(dirtyDate);
var diff = (0, _index2.default)(date, options).getTime() - (0, _index3.default)(date, options).getTime(); // Round the number of days to the nearest integer
// because the number of milliseconds in a week is not constant
// (e.g. it's different in the week of the daylight saving time clock shift)
return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
}
module.exports = exports.default;

View File

@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getUTCWeekYear;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../requiredArgs/index.js"));
var _index3 = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
var _index4 = _interopRequireDefault(require("../toInteger/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function getUTCWeekYear(dirtyDate, dirtyOptions) {
(0, _index2.default)(1, arguments);
var date = (0, _index.default)(dirtyDate);
var year = date.getUTCFullYear();
var options = dirtyOptions || {};
var locale = options.locale;
var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : (0, _index4.default)(localeFirstWeekContainsDate);
var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : (0, _index4.default)(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
}
var firstWeekOfNextYear = new Date(0);
firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate);
firstWeekOfNextYear.setUTCHours(0, 0, 0, 0);
var startOfNextYear = (0, _index3.default)(firstWeekOfNextYear, dirtyOptions);
var firstWeekOfThisYear = new Date(0);
firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
var startOfThisYear = (0, _index3.default)(firstWeekOfThisYear, dirtyOptions);
if (date.getTime() >= startOfNextYear.getTime()) {
return year + 1;
} else if (date.getTime() >= startOfThisYear.getTime()) {
return year;
} else {
return year - 1;
}
}
module.exports = exports.default;

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isSameUTCWeek;
var _index = _interopRequireDefault(require("../requiredArgs/index.js"));
var _index2 = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function isSameUTCWeek(dirtyDateLeft, dirtyDateRight, options) {
(0, _index.default)(2, arguments);
var dateLeftStartOfWeek = (0, _index2.default)(dirtyDateLeft, options);
var dateRightStartOfWeek = (0, _index2.default)(dirtyDateRight, options);
return dateLeftStartOfWeek.getTime() === dateRightStartOfWeek.getTime();
}
module.exports = exports.default;

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isProtectedDayOfYearToken = isProtectedDayOfYearToken;
exports.isProtectedWeekYearToken = isProtectedWeekYearToken;
exports.throwProtectedError = throwProtectedError;
var protectedDayOfYearTokens = ['D', 'DD'];
var protectedWeekYearTokens = ['YY', 'YYYY'];
function isProtectedDayOfYearToken(token) {
return protectedDayOfYearTokens.indexOf(token) !== -1;
}
function isProtectedWeekYearToken(token) {
return protectedWeekYearTokens.indexOf(token) !== -1;
}
function throwProtectedError(token, format, input) {
if (token === 'YYYY') {
throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://git.io/fxCyr"));
} else if (token === 'YY') {
throw new RangeError("Use `yy` instead of `YY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://git.io/fxCyr"));
} else if (token === 'D') {
throw new RangeError("Use `d` instead of `D` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://git.io/fxCyr"));
} else if (token === 'DD') {
throw new RangeError("Use `dd` instead of `DD` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://git.io/fxCyr"));
}
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = requiredArgs;
function requiredArgs(required, args) {
if (args.length < required) {
throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
}
}
module.exports = exports.default;

View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRoundingMethod = getRoundingMethod;
var roundingMap = {
ceil: Math.ceil,
round: Math.round,
floor: Math.floor,
trunc: function (value) {
return value < 0 ? Math.ceil(value) : Math.floor(value);
} // Math.trunc is not supported by IE
};
var defaultRoundingMethod = 'trunc';
function getRoundingMethod(method) {
return method ? roundingMap[method] : roundingMap[defaultRoundingMethod];
}

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = setUTCDay;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../requiredArgs/index.js"));
var _index3 = _interopRequireDefault(require("../toInteger/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function setUTCDay(dirtyDate, dirtyDay, dirtyOptions) {
(0, _index2.default)(2, arguments);
var options = dirtyOptions || {};
var locale = options.locale;
var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn;
var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : (0, _index3.default)(localeWeekStartsOn);
var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : (0, _index3.default)(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
}
var date = (0, _index.default)(dirtyDate);
var day = (0, _index3.default)(dirtyDay);
var currentDay = date.getUTCDay();
var remainder = day % 7;
var dayIndex = (remainder + 7) % 7;
var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay;
date.setUTCDate(date.getUTCDate() + diff);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = setUTCISODay;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../requiredArgs/index.js"));
var _index3 = _interopRequireDefault(require("../toInteger/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function setUTCISODay(dirtyDate, dirtyDay) {
(0, _index2.default)(2, arguments);
var day = (0, _index3.default)(dirtyDay);
if (day % 7 === 0) {
day = day - 7;
}
var weekStartsOn = 1;
var date = (0, _index.default)(dirtyDate);
var currentDay = date.getUTCDay();
var remainder = day % 7;
var dayIndex = (remainder + 7) % 7;
var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay;
date.setUTCDate(date.getUTCDate() + diff);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = setUTCISOWeek;
var _index = _interopRequireDefault(require("../toInteger/index.js"));
var _index2 = _interopRequireDefault(require("../../toDate/index.js"));
var _index3 = _interopRequireDefault(require("../getUTCISOWeek/index.js"));
var _index4 = _interopRequireDefault(require("../requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function setUTCISOWeek(dirtyDate, dirtyISOWeek) {
(0, _index4.default)(2, arguments);
var date = (0, _index2.default)(dirtyDate);
var isoWeek = (0, _index.default)(dirtyISOWeek);
var diff = (0, _index3.default)(date) - isoWeek;
date.setUTCDate(date.getUTCDate() - diff * 7);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = setUTCWeek;
var _index = _interopRequireDefault(require("../toInteger/index.js"));
var _index2 = _interopRequireDefault(require("../../toDate/index.js"));
var _index3 = _interopRequireDefault(require("../getUTCWeek/index.js"));
var _index4 = _interopRequireDefault(require("../requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function setUTCWeek(dirtyDate, dirtyWeek, options) {
(0, _index4.default)(2, arguments);
var date = (0, _index2.default)(dirtyDate);
var week = (0, _index.default)(dirtyWeek);
var diff = (0, _index3.default)(date, options) - week;
date.setUTCDate(date.getUTCDate() - diff * 7);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = startOfUTCISOWeek;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function startOfUTCISOWeek(dirtyDate) {
(0, _index2.default)(1, arguments);
var weekStartsOn = 1;
var date = (0, _index.default)(dirtyDate);
var day = date.getUTCDay();
var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
date.setUTCDate(date.getUTCDate() - diff);
date.setUTCHours(0, 0, 0, 0);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = startOfUTCISOWeekYear;
var _index = _interopRequireDefault(require("../getUTCISOWeekYear/index.js"));
var _index2 = _interopRequireDefault(require("../startOfUTCISOWeek/index.js"));
var _index3 = _interopRequireDefault(require("../requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function startOfUTCISOWeekYear(dirtyDate) {
(0, _index3.default)(1, arguments);
var year = (0, _index.default)(dirtyDate);
var fourthOfJanuary = new Date(0);
fourthOfJanuary.setUTCFullYear(year, 0, 4);
fourthOfJanuary.setUTCHours(0, 0, 0, 0);
var date = (0, _index2.default)(fourthOfJanuary);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = startOfUTCWeek;
var _index = _interopRequireDefault(require("../../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../requiredArgs/index.js"));
var _index3 = _interopRequireDefault(require("../toInteger/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function startOfUTCWeek(dirtyDate, dirtyOptions) {
(0, _index2.default)(1, arguments);
var options = dirtyOptions || {};
var locale = options.locale;
var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn;
var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : (0, _index3.default)(localeWeekStartsOn);
var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : (0, _index3.default)(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
}
var date = (0, _index.default)(dirtyDate);
var day = date.getUTCDay();
var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
date.setUTCDate(date.getUTCDate() - diff);
date.setUTCHours(0, 0, 0, 0);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = startOfUTCWeekYear;
var _index = _interopRequireDefault(require("../getUTCWeekYear/index.js"));
var _index2 = _interopRequireDefault(require("../requiredArgs/index.js"));
var _index3 = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
var _index4 = _interopRequireDefault(require("../toInteger/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// This function will be a part of public API when UTC function will be implemented.
// See issue: https://github.com/date-fns/date-fns/issues/376
function startOfUTCWeekYear(dirtyDate, dirtyOptions) {
(0, _index2.default)(1, arguments);
var options = dirtyOptions || {};
var locale = options.locale;
var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : (0, _index4.default)(localeFirstWeekContainsDate);
var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : (0, _index4.default)(options.firstWeekContainsDate);
var year = (0, _index.default)(dirtyDate, dirtyOptions);
var firstWeek = new Date(0);
firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
firstWeek.setUTCHours(0, 0, 0, 0);
var date = (0, _index3.default)(firstWeek, dirtyOptions);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assertType = assertType;
function assertType(_) {}

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = toInteger;
function toInteger(dirtyNumber) {
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
return NaN;
}
var number = Number(dirtyNumber);
if (isNaN(number)) {
return number;
}
return number < 0 ? Math.ceil(number) : Math.floor(number);
}
module.exports = exports.default;

View File

@@ -0,0 +1,4 @@
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
import { add } from 'date-fns'
export default add

View File

@@ -0,0 +1,82 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = add;
var _index = _interopRequireDefault(require("../addDays/index.js"));
var _index2 = _interopRequireDefault(require("../addMonths/index.js"));
var _index3 = _interopRequireDefault(require("../toDate/index.js"));
var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
var _index5 = _interopRequireDefault(require("../_lib/toInteger/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @name add
* @category Common Helpers
* @summary Add the specified years, months, weeks, days, hours, minutes and seconds to the given date.
*
* @description
* Add the specified years, months, weeks, days, hours, minutes and seconds to the given date.
*
* @param {Date|Number} date - the date to be changed
* @param {Duration} duration - the object with years, months, weeks, days, hours, minutes and seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
*
* | Key | Description |
* |----------------|------------------------------------|
* | years | Amount of years to be added |
* | months | Amount of months to be added |
* | weeks | Amount of weeks to be added |
* | days | Amount of days to be added |
* | hours | Amount of hours to be added |
* | minutes | Amount of minutes to be added |
* | seconds | Amount of seconds to be added |
*
* All values default to 0
*
* @returns {Date} the new date with the seconds added
* @throws {TypeError} 2 arguments required
*
* @example
* // Add the following duration to 1 September 2014, 10:19:50
* const result = add(new Date(2014, 8, 1, 10, 19, 50), {
* years: 2,
* months: 9,
* weeks: 1,
* days: 7,
* hours: 5,
* minutes: 9,
* seconds: 30,
* })
* //=> Thu Jun 15 2017 15:29:20
*/
function add(dirtyDate, duration) {
(0, _index4.default)(2, arguments);
if (!duration || typeof duration !== 'object') return new Date(NaN);
var years = duration.years ? (0, _index5.default)(duration.years) : 0;
var months = duration.months ? (0, _index5.default)(duration.months) : 0;
var weeks = duration.weeks ? (0, _index5.default)(duration.weeks) : 0;
var days = duration.days ? (0, _index5.default)(duration.days) : 0;
var hours = duration.hours ? (0, _index5.default)(duration.hours) : 0;
var minutes = duration.minutes ? (0, _index5.default)(duration.minutes) : 0;
var seconds = duration.seconds ? (0, _index5.default)(duration.seconds) : 0; // Add years and months
var date = (0, _index3.default)(dirtyDate);
var dateWithMonths = months || years ? (0, _index2.default)(date, months + years * 12) : date; // Add weeks and days
var dateWithDays = days || weeks ? (0, _index.default)(dateWithMonths, days + weeks * 7) : dateWithMonths; // Add days, hours, minutes and seconds
var minutesToAdd = minutes + hours * 60;
var secondsToAdd = seconds + minutesToAdd * 60;
var msToAdd = secondsToAdd * 1000;
var finalDate = new Date(dateWithDays.getTime() + msToAdd);
return finalDate;
}
module.exports = exports.default;

View File

@@ -0,0 +1,52 @@
// @flow
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
export type Interval = {
start: Date | number,
end: Date | number,
}
export type Locale = {
code?: string,
formatDistance?: (...args: Array<any>) => any,
formatRelative?: (...args: Array<any>) => any,
localize?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
formatLong?: {
date: (...args: Array<any>) => any,
time: (...args: Array<any>) => any,
dateTime: (...args: Array<any>) => any,
},
match?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
options?: {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
},
}
export type Duration = {
years?: number,
months?: number,
weeks?: number,
days?: number,
hours?: number,
minutes?: number,
seconds?: number,
}
export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
declare module.exports: (date: Date | number, duration: Duration) => Date

View File

@@ -0,0 +1,4 @@
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
import { addBusinessDays } from 'date-fns'
export default addBusinessDays

View File

@@ -0,0 +1,73 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = addBusinessDays;
var _index = _interopRequireDefault(require("../isWeekend/index.js"));
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
var _index3 = _interopRequireDefault(require("../_lib/toInteger/index.js"));
var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
var _index5 = _interopRequireDefault(require("../isSunday/index.js"));
var _index6 = _interopRequireDefault(require("../isSaturday/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @name addBusinessDays
* @category Day Helpers
* @summary Add the specified number of business days (mon - fri) to the given date.
*
* @description
* Add the specified number of business days (mon - fri) to the given date, ignoring weekends.
*
* @param {Date|Number} date - the date to be changed
* @param {Number} amount - the amount of business days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @returns {Date} the new date with the business days added
* @throws {TypeError} 2 arguments required
*
* @example
* // Add 10 business days to 1 September 2014:
* const result = addBusinessDays(new Date(2014, 8, 1), 10)
* //=> Mon Sep 15 2014 00:00:00 (skipped weekend days)
*/
function addBusinessDays(dirtyDate, dirtyAmount) {
(0, _index4.default)(2, arguments);
var date = (0, _index2.default)(dirtyDate);
var startedOnWeekend = (0, _index.default)(date);
var amount = (0, _index3.default)(dirtyAmount);
if (isNaN(amount)) return new Date(NaN);
var hours = date.getHours();
var sign = amount < 0 ? -1 : 1;
var fullWeeks = (0, _index3.default)(amount / 5);
date.setDate(date.getDate() + fullWeeks * 7); // Get remaining days not part of a full week
var restDays = Math.abs(amount % 5); // Loops over remaining days
while (restDays > 0) {
date.setDate(date.getDate() + sign);
if (!(0, _index.default)(date)) restDays -= 1;
} // If the date is a weekend day and we reduce a dividable of
// 5 from it, we land on a weekend date.
// To counter this, we add days accordingly to land on the next business day
if (startedOnWeekend && (0, _index.default)(date) && amount !== 0) {
// If we're reducing days, we want to add days until we land on a weekday
// If we're adding days we want to reduce days until we land on a weekday
if ((0, _index6.default)(date)) date.setDate(date.getDate() + (sign < 0 ? 2 : -1));
if ((0, _index5.default)(date)) date.setDate(date.getDate() + (sign < 0 ? 1 : -2));
} // Restore hours to avoid DST lag
date.setHours(hours);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,52 @@
// @flow
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
export type Interval = {
start: Date | number,
end: Date | number,
}
export type Locale = {
code?: string,
formatDistance?: (...args: Array<any>) => any,
formatRelative?: (...args: Array<any>) => any,
localize?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
formatLong?: {
date: (...args: Array<any>) => any,
time: (...args: Array<any>) => any,
dateTime: (...args: Array<any>) => any,
},
match?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
options?: {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
},
}
export type Duration = {
years?: number,
months?: number,
weeks?: number,
days?: number,
hours?: number,
minutes?: number,
seconds?: number,
}
export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
declare module.exports: (date: Date | number, amount: number) => Date

View File

@@ -0,0 +1,4 @@
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
import { addDays } from 'date-fns'
export default addDays

View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = addDays;
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @name addDays
* @category Day Helpers
* @summary Add the specified number of days to the given date.
*
* @description
* Add the specified number of days to the given date.
*
* ### v2.0.0 breaking changes:
*
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @param {Date|Number} date - the date to be changed
* @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @returns {Date} - the new date with the days added
* @throws {TypeError} - 2 arguments required
*
* @example
* // Add 10 days to 1 September 2014:
* const result = addDays(new Date(2014, 8, 1), 10)
* //=> Thu Sep 11 2014 00:00:00
*/
function addDays(dirtyDate, dirtyAmount) {
(0, _index3.default)(2, arguments);
var date = (0, _index2.default)(dirtyDate);
var amount = (0, _index.default)(dirtyAmount);
if (isNaN(amount)) {
return new Date(NaN);
}
if (!amount) {
// If 0 days, no-op to avoid changing times in the hour before end of DST
return date;
}
date.setDate(date.getDate() + amount);
return date;
}
module.exports = exports.default;

View File

@@ -0,0 +1,52 @@
// @flow
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
export type Interval = {
start: Date | number,
end: Date | number,
}
export type Locale = {
code?: string,
formatDistance?: (...args: Array<any>) => any,
formatRelative?: (...args: Array<any>) => any,
localize?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
formatLong?: {
date: (...args: Array<any>) => any,
time: (...args: Array<any>) => any,
dateTime: (...args: Array<any>) => any,
},
match?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
options?: {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
},
}
export type Duration = {
years?: number,
months?: number,
weeks?: number,
days?: number,
hours?: number,
minutes?: number,
seconds?: number,
}
export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
declare module.exports: (date: Date | number, amount: number) => Date

View File

@@ -0,0 +1,4 @@
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
import { addHours } from 'date-fns'
export default addHours

View File

@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = addHours;
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
var _index2 = _interopRequireDefault(require("../addMilliseconds/index.js"));
var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var MILLISECONDS_IN_HOUR = 3600000;
/**
* @name addHours
* @category Hour Helpers
* @summary Add the specified number of hours to the given date.
*
* @description
* Add the specified number of hours to the given date.
*
* ### v2.0.0 breaking changes:
*
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @param {Date|Number} date - the date to be changed
* @param {Number} amount - the amount of hours to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @returns {Date} the new date with the hours added
* @throws {TypeError} 2 arguments required
*
* @example
* // Add 2 hours to 10 July 2014 23:00:00:
* const result = addHours(new Date(2014, 6, 10, 23, 0), 2)
* //=> Fri Jul 11 2014 01:00:00
*/
function addHours(dirtyDate, dirtyAmount) {
(0, _index3.default)(2, arguments);
var amount = (0, _index.default)(dirtyAmount);
return (0, _index2.default)(dirtyDate, amount * MILLISECONDS_IN_HOUR);
}
module.exports = exports.default;

View File

@@ -0,0 +1,52 @@
// @flow
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
export type Interval = {
start: Date | number,
end: Date | number,
}
export type Locale = {
code?: string,
formatDistance?: (...args: Array<any>) => any,
formatRelative?: (...args: Array<any>) => any,
localize?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
formatLong?: {
date: (...args: Array<any>) => any,
time: (...args: Array<any>) => any,
dateTime: (...args: Array<any>) => any,
},
match?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
options?: {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
},
}
export type Duration = {
years?: number,
months?: number,
weeks?: number,
days?: number,
hours?: number,
minutes?: number,
seconds?: number,
}
export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
declare module.exports: (date: Date | number, amount: number) => Date

View File

@@ -0,0 +1,4 @@
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
import { addISOWeekYears } from 'date-fns'
export default addISOWeekYears

View File

@@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = addISOWeekYears;
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
var _index2 = _interopRequireDefault(require("../getISOWeekYear/index.js"));
var _index3 = _interopRequireDefault(require("../setISOWeekYear/index.js"));
var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @name addISOWeekYears
* @category ISO Week-Numbering Year Helpers
* @summary Add the specified number of ISO week-numbering years to the given date.
*
* @description
* Add the specified number of ISO week-numbering years to the given date.
*
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
*
* ### v2.0.0 breaking changes:
*
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* - The function was renamed from `addISOYears` to `addISOWeekYears`.
* "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
* This change makes the name consistent with
* locale-dependent week-numbering year helpers, e.g., `addWeekYears`.
*
* @param {Date|Number} date - the date to be changed
* @param {Number} amount - the amount of ISO week-numbering years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @returns {Date} the new date with the ISO week-numbering years added
* @throws {TypeError} 2 arguments required
*
* @example
* // Add 5 ISO week-numbering years to 2 July 2010:
* const result = addISOWeekYears(new Date(2010, 6, 2), 5)
* //=> Fri Jun 26 2015 00:00:00
*/
function addISOWeekYears(dirtyDate, dirtyAmount) {
(0, _index4.default)(2, arguments);
var amount = (0, _index.default)(dirtyAmount);
return (0, _index3.default)(dirtyDate, (0, _index2.default)(dirtyDate) + amount);
}
module.exports = exports.default;

View File

@@ -0,0 +1,52 @@
// @flow
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
export type Interval = {
start: Date | number,
end: Date | number,
}
export type Locale = {
code?: string,
formatDistance?: (...args: Array<any>) => any,
formatRelative?: (...args: Array<any>) => any,
localize?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
formatLong?: {
date: (...args: Array<any>) => any,
time: (...args: Array<any>) => any,
dateTime: (...args: Array<any>) => any,
},
match?: {
ordinalNumber: (...args: Array<any>) => any,
era: (...args: Array<any>) => any,
quarter: (...args: Array<any>) => any,
month: (...args: Array<any>) => any,
day: (...args: Array<any>) => any,
dayPeriod: (...args: Array<any>) => any,
},
options?: {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
},
}
export type Duration = {
years?: number,
months?: number,
weeks?: number,
days?: number,
hours?: number,
minutes?: number,
seconds?: number,
}
export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
declare module.exports: (date: Date | number, amount: number) => Date

View File

@@ -0,0 +1,4 @@
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
import { addMilliseconds } from 'date-fns'
export default addMilliseconds

View File

@@ -0,0 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = addMilliseconds;
var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
var _index2 = _interopRequireDefault(require("../toDate/index.js"));
var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @name addMilliseconds
* @category Millisecond Helpers
* @summary Add the specified number of milliseconds to the given date.
*
* @description
* Add the specified number of milliseconds to the given date.
*
* ### v2.0.0 breaking changes:
*
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
* @param {Date|Number} date - the date to be changed
* @param {Number} amount - the amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @returns {Date} the new date with the milliseconds added
* @throws {TypeError} 2 arguments required
*
* @example
* // Add 750 milliseconds to 10 July 2014 12:45:30.000:
* const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
* //=> Thu Jul 10 2014 12:45:30.750
*/
function addMilliseconds(dirtyDate, dirtyAmount) {
(0, _index3.default)(2, arguments);
var timestamp = (0, _index2.default)(dirtyDate).getTime();
var amount = (0, _index.default)(dirtyAmount);
return new Date(timestamp + amount);
}
module.exports = exports.default;

Some files were not shown because too many files have changed in this diff Show More