Skip to content

Instantly share code, notes, and snippets.

@nikeokoronkwo
Last active September 1, 2025 14:04
Show Gist options
  • Select an option

  • Save nikeokoronkwo/dd83becbb6cee4d98f63556ba108e14b to your computer and use it in GitHub Desktop.

Select an option

Save nikeokoronkwo/dd83becbb6cee4d98f63556ba108e14b to your computer and use it in GitHub Desktop.
[GSoC] Web Generator Result for Select Libraries

Generator Results

The following are results of generating code via the Dart JS Interop Generator for some select NPM packages.

// ignore_for_file: camel_case_types, constant_identifier_names
// ignore_for_file: library_private_types_in_public_api
// ignore_for_file: non_constant_identifier_names, unnecessary_parenthesis
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:js_interop' as _i1;
/// Generate secure URL-friendly unique ID.
///
/// By default, the ID will have 21 symbols to have a collision probability
/// similar to UUID v4.
///
/// ```js
/// import { nanoid } from 'nanoid'
/// model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
/// ```
/// - [size]: Size of the ID. The default size is 21.
///
/// Returns A random string.
@_i1.JS()
external Type nanoid<Type extends _i1.JSString>([num? size]);
/// Generate secure unique ID with custom alphabet.
///
/// Alphabet must contain 256 symbols or less. Otherwise, the generator
/// will not be secure.
/// - [alphabet]: Alphabet used to generate the ID.
/// - [defaultSize]: Size of the ID. The default size is 21.
///
/// Returns A random string generator.
///
/// ```js
/// const { customAlphabet } = require('nanoid')
/// const nanoid = customAlphabet('0123456789абвгдеё', 5)
/// nanoid() //=> "8ё56а"
/// ```
@_i1.JS()
external _AnonymousFunction_1425286<Type>
customAlphabet<Type extends _i1.JSString>(
String alphabet, [
num? defaultSize,
]);
/// Generate unique ID with custom random generator and alphabet.
///
/// Alphabet must contain 256 symbols or less. Otherwise, the generator
/// will not be secure.
///
/// ```js
/// import { customRandom } from 'nanoid/format'
///
/// const nanoid = customRandom('abcdef', 5, size => {
/// const random = []
/// for (let i = 0; i < size; i++) {
/// random.push(randomByte())
/// }
/// return random
/// })
///
/// nanoid() //=> "fbaef"
/// ```
/// - [alphabet]: Alphabet used to generate a random string.
/// - [size]: Size of the random string.
/// - [random]: A random bytes generator.
///
/// Returns A random string generator.
@_i1.JS()
external _AnonymousFunction_1606891<Type>
customRandom<Type extends _i1.JSString>(
String alphabet,
num size,
_AnonymousFunction_1560420 random,
);
/// Generate an array of random bytes collected from hardware noise.
///
/// ```js
/// import { customRandom, random } from 'nanoid'
/// const nanoid = customRandom("abcdef", 5, random)
/// ```
/// - [bytes]: Size of the array.
///
/// Returns An array of random bytes.
@_i1.JS()
external _i1.JSUint8Array random(num bytes);
/// URL safe symbols.
///
/// ```js
/// import { urlAlphabet } from 'nanoid'
/// const nanoid = customAlphabet(urlAlphabet, 10)
/// nanoid() //=> "Uakgb_J5m9"
/// ```
@_i1.JS()
external String get urlAlphabet;
extension type _AnonymousFunction_1425286<Type extends _i1.JSAny?>._(
_i1.JSFunction _) implements _i1.JSFunction {
external Type call([num? size]);
}
extension type _AnonymousFunction_1560420._(_i1.JSFunction _)
implements _i1.JSFunction {
external _i1.JSUint8Array call(num bytes);
}
extension type _AnonymousFunction_1606891<Type extends _i1.JSAny?>._(
_i1.JSFunction _) implements _i1.JSFunction {
external Type call();
}
// ignore_for_file: camel_case_types, constant_identifier_names
// ignore_for_file: library_private_types_in_public_api
// ignore_for_file: non_constant_identifier_names, unnecessary_parenthesis
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:js_interop' as _i1;
typedef V1Options = AnonymousUnion_1533355;
typedef V4Options = AnonymousUnion_1357523;
typedef V6Options = V1Options;
typedef V7Options = _i1.JSAny;
@_i1.JS()
external String get NIL;
@_i1.JS()
external String get MAX;
@_i1.JS()
external _AnonymousFunction_9387663 get parse;
@_i1.JS()
external _AnonymousFunction_1522965 get stringify;
@_i1.JS()
external _i1.JSAny get v1;
@_i1.JS()
external VToV get v1ToV6;
@_i1.JS()
external _i1.JSAny get v3;
@_i1.JS()
external _i1.JSAny get v4;
@_i1.JS()
external _i1.JSAny get v5;
@_i1.JS()
external _i1.JSAny get v6;
@_i1.JS()
external VToV get v6ToV1;
@_i1.JS()
external _i1.JSAny get v7;
@_i1.JS()
external _AnonymousFunction_1164364 get validate;
@_i1.JS()
external _AnonymousFunction_5027328 get version;
extension type V1RandomOptions._(_i1.JSObject _)
implements V1BaseOptions, RandomOptions {}
extension type V1RngOptions._(_i1.JSObject _)
implements V1BaseOptions, RngOptions {}
extension type AnonymousUnion_1533355._(V1BaseOptions _)
implements V1BaseOptions {
V1RandomOptions get asV1RandomOptions => (_ as V1RandomOptions);
V1RngOptions get asV1RngOptions => (_ as V1RngOptions);
}
extension type V1BaseOptions._(_i1.JSObject _) implements _i1.JSObject {
/// RFC "node" field as an `Array[6]` of byte values (per 4.1.6)
external InputBuffer? node;
/// RFC "clock sequence" as a `Number` between 0 - 0x3fff
external double? clockseq;
/// RFC "timestamp" field (`Number` of milliseconds, unix epoch)
external AnonymousUnion_1491979? msecs;
/// RFC "timestamp" field (`Number` of nanoseconds to add to msecs, should be
/// 0-10,000)
external double? nsecs;
}
extension type RandomOptions._(_i1.JSObject _) implements _i1.JSObject {
/// `Array` of 16 random bytes (0-255)
external InputBuffer? random;
}
typedef InputBuffer = ArrayLike<_i1.JSNumber>;
extension type ArrayLike<T extends _i1.JSAny?>._(_i1.JSObject _)
implements _i1.JSObject {
external double get length;
external T operator [](num n);
external void operator []=(
num n,
T newValue,
);
}
/// Enables basic storage and retrieval of dates and times.
extension type Date._(_i1.JSObject _) implements _i1.JSObject {
/// Returns a string representation of a date. The format of the string
/// depends on the locale.
@_i1.JS('toString')
external String toString$();
/// Returns a date as a string value.
external String toDateString();
/// Returns a time as a string value.
external String toTimeString();
/// Returns a value as a string value appropriate to the host environment's
/// current locale.
/// Converts a date and time to a string by using the current or specified
/// locale.
/// - [locales]: A locale string or array of locale strings that contain one
/// or more language or locale tags. If you include more than one locale
/// string, list them in descending order of priority so that the first
/// entry is the preferred locale. If you omit this parameter, the default
/// locale of the JavaScript runtime is used.
/// - [options]: An object that contains one or more properties that specify
/// comparison options.
external String toLocaleString();
/// Returns a date as a string value appropriate to the host environment's
/// current locale.
/// Converts a date to a string by using the current or specified locale.
/// - [locales]: A locale string or array of locale strings that contain one
/// or more language or locale tags. If you include more than one locale
/// string, list them in descending order of priority so that the first
/// entry is the preferred locale. If you omit this parameter, the default
/// locale of the JavaScript runtime is used.
/// - [options]: An object that contains one or more properties that specify
/// comparison options.
external String toLocaleDateString();
/// Returns a time as a string value appropriate to the host environment's
/// current locale.
/// Converts a time to a string by using the current or specified locale.
/// - [locales]: A locale string or array of locale strings that contain one
/// or more language or locale tags. If you include more than one locale
/// string, list them in descending order of priority so that the first
/// entry is the preferred locale. If you omit this parameter, the default
/// locale of the JavaScript runtime is used.
/// - [options]: An object that contains one or more properties that specify
/// comparison options.
external String toLocaleTimeString();
/// Returns the stored time value in milliseconds since midnight, January 1,
/// 1970 UTC.
external double valueOf();
/// Returns the stored time value in milliseconds since midnight, January 1,
/// 1970 UTC.
external double getTime();
/// Gets the year, using local time.
external double getFullYear();
/// Gets the year using Universal Coordinated Time (UTC).
external double getUTCFullYear();
/// Gets the month, using local time.
external double getMonth();
/// Gets the month of a Date object using Universal Coordinated Time (UTC).
external double getUTCMonth();
/// Gets the day-of-the-month, using local time.
external double getDate();
/// Gets the day-of-the-month, using Universal Coordinated Time (UTC).
external double getUTCDate();
/// Gets the day of the week, using local time.
external double getDay();
/// Gets the day of the week using Universal Coordinated Time (UTC).
external double getUTCDay();
/// Gets the hours in a date, using local time.
external double getHours();
/// Gets the hours value in a Date object using Universal Coordinated Time
/// (UTC).
external double getUTCHours();
/// Gets the minutes of a Date object, using local time.
external double getMinutes();
/// Gets the minutes of a Date object using Universal Coordinated Time (UTC).
external double getUTCMinutes();
/// Gets the seconds of a Date object, using local time.
external double getSeconds();
/// Gets the seconds of a Date object using Universal Coordinated Time (UTC).
external double getUTCSeconds();
/// Gets the milliseconds of a Date, using local time.
external double getMilliseconds();
/// Gets the milliseconds of a Date object using Universal Coordinated Time
/// (UTC).
external double getUTCMilliseconds();
/// Gets the difference in minutes between Universal Coordinated Time (UTC)
/// and the time on the local computer.
external double getTimezoneOffset();
/// Sets the date and time value in the Date object.
/// - [time]: A numeric value representing the number of elapsed milliseconds
/// since midnight, January 1, 1970 GMT.
external double setTime(num time);
/// Sets the milliseconds value in the Date object using local time.
/// - [ms]: A numeric value equal to the millisecond value.
external double setMilliseconds(num ms);
/// Sets the milliseconds value in the Date object using Universal Coordinated
/// Time (UTC).
/// - [ms]: A numeric value equal to the millisecond value.
external double setUTCMilliseconds(num ms);
/// Sets the seconds value in the Date object using local time.
/// - [sec]: A numeric value equal to the seconds value.
/// - [ms]: A numeric value equal to the milliseconds value.
external double setSeconds(
num sec, [
num? ms,
]);
/// Sets the seconds value in the Date object using Universal Coordinated Time
/// (UTC).
/// - [sec]: A numeric value equal to the seconds value.
/// - [ms]: A numeric value equal to the milliseconds value.
external double setUTCSeconds(
num sec, [
num? ms,
]);
/// Sets the minutes value in the Date object using local time.
/// - [min]: A numeric value equal to the minutes value.
/// - [sec]: A numeric value equal to the seconds value.
/// - [ms]: A numeric value equal to the milliseconds value.
external double setMinutes(
num min, [
num? sec,
num? ms,
]);
/// Sets the minutes value in the Date object using Universal Coordinated Time
/// (UTC).
/// - [min]: A numeric value equal to the minutes value.
/// - [sec]: A numeric value equal to the seconds value.
/// - [ms]: A numeric value equal to the milliseconds value.
external double setUTCMinutes(
num min, [
num? sec,
num? ms,
]);
/// Sets the hour value in the Date object using local time.
/// - [hours]: A numeric value equal to the hours value.
/// - [min]: A numeric value equal to the minutes value.
/// - [sec]: A numeric value equal to the seconds value.
/// - [ms]: A numeric value equal to the milliseconds value.
external double setHours(
num hours, [
num? min,
num? sec,
num? ms,
]);
/// Sets the hours value in the Date object using Universal Coordinated Time
/// (UTC).
/// - [hours]: A numeric value equal to the hours value.
/// - [min]: A numeric value equal to the minutes value.
/// - [sec]: A numeric value equal to the seconds value.
/// - [ms]: A numeric value equal to the milliseconds value.
external double setUTCHours(
num hours, [
num? min,
num? sec,
num? ms,
]);
/// Sets the numeric day-of-the-month value of the Date object using local
/// time.
/// - [date]: A numeric value equal to the day of the month.
external double setDate(num date);
/// Sets the numeric day of the month in the Date object using Universal
/// Coordinated Time (UTC).
/// - [date]: A numeric value equal to the day of the month.
external double setUTCDate(num date);
/// Sets the month value in the Date object using local time.
/// - [month]: A numeric value equal to the month. The value for January is
/// 0, and other month values follow consecutively.
/// - [date]: A numeric value representing the day of the month. If this
/// value is not supplied, the value from a call to the getDate method is
/// used.
external double setMonth(
num month, [
num? date,
]);
/// Sets the month value in the Date object using Universal Coordinated Time
/// (UTC).
/// - [month]: A numeric value equal to the month. The value for January is
/// 0, and other month values follow consecutively.
/// - [date]: A numeric value representing the day of the month. If it is not
/// supplied, the value from a call to the getUTCDate method is used.
external double setUTCMonth(
num month, [
num? date,
]);
/// Sets the year of the Date object using local time.
/// - [year]: A numeric value for the year.
/// - [month]: A zero-based numeric value for the month (0 for January, 11
/// for December). Must be specified if numDate is specified.
/// - [date]: A numeric value equal for the day of the month.
external double setFullYear(
num year, [
num? month,
num? date,
]);
/// Sets the year value in the Date object using Universal Coordinated Time
/// (UTC).
/// - [year]: A numeric value equal to the year.
/// - [month]: A numeric value equal to the month. The value for January is
/// 0, and other month values follow consecutively. Must be supplied if
/// numDate is supplied.
/// - [date]: A numeric value equal to the day of the month.
external double setUTCFullYear(
num year, [
num? month,
num? date,
]);
/// Returns a date converted to a string using Universal Coordinated Time
/// (UTC).
external String toUTCString();
/// Returns a date as a string value in ISO format.
external String toISOString();
/// Used by the JSON.stringify method to enable the transformation of an
/// object's data for JavaScript Object Notation (JSON) serialization.
external String toJSON([_i1.JSAny? key]);
}
extension type AnonymousUnion_1491979._(_i1.JSAny _) implements _i1.JSAny {
double get asDouble => (_ as _i1.JSNumber).toDartDouble;
Date get asDate => (_ as Date);
}
extension type RngOptions._(_i1.JSObject _) implements _i1.JSObject {
/// Alternative to `options.random`, a `Function` that returns an `Array` of
/// 16 random bytes (0-255)
external _AnonymousFunction_1390839? rng;
}
extension type _AnonymousFunction_1390839._(_i1.JSFunction _)
implements _i1.JSFunction {
external InputBuffer call();
}
extension type AnonymousUnion_1357523._(_i1.JSObject _)
implements _i1.JSObject {
RandomOptions get asRandomOptions => (_ as RandomOptions);
RngOptions get asRngOptions => (_ as RngOptions);
}
extension type _AnonymousFunction_9387663._(_i1.JSFunction _)
implements _i1.JSFunction {
external _i1.JSUint8Array call(String uuid);
}
extension type _AnonymousFunction_1522965._(_i1.JSFunction _)
implements _i1.JSFunction {
external String call(
InputBuffer buffer, [
num? offset,
]);
}
typedef VToV = _i1.JSAny;
extension type _AnonymousFunction_1164364._(_i1.JSFunction _)
implements _i1.JSFunction {
external bool call(String uuid);
}
extension type _AnonymousFunction_5027328._(_i1.JSFunction _)
implements _i1.JSFunction {
external double call(String uuid);
}
@nikeokoronkwo

Copy link
Copy Markdown
Author

Convention: The name of the file corresponds to the name of the NPM package.
If the package does not have TS Type definitions of its own, you may want to try the @types/<pkg> version instead (e.g. @types/uuid for uuid.dart)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment