type stringclasses 7
values | content stringlengths 4 9.55k | repo stringlengths 7 96 | path stringlengths 4 178 | language stringclasses 1
value |
|---|---|---|---|---|
ArrowFunction |
res => {
this.noticias = res.data;
} | adrielparedes/openscore | openscore-ui/src/app/views/noticias/noticias.component.ts | TypeScript |
ClassDeclaration |
@Component({
selector: 'app-noticias',
templateUrl: './noticias.component.html',
styleUrls: ['./noticias.component.scss']
})
export class NoticiasComponent implements OnInit {
noticias: Noticia[] = [];
constructor(private noticiasService: NoticiasService) { }
ngOnInit() {
this.refresh();
}
refr... | adrielparedes/openscore | openscore-ui/src/app/views/noticias/noticias.component.ts | TypeScript |
MethodDeclaration |
ngOnInit() {
this.refresh();
} | adrielparedes/openscore | openscore-ui/src/app/views/noticias/noticias.component.ts | TypeScript |
MethodDeclaration |
refresh() {
this.noticiasService.getAll(0, 0, [{ key: 'status', value: 'PUBLICADO' }]).subscribe(res => {
this.noticias = res.data;
})
} | adrielparedes/openscore | openscore-ui/src/app/views/noticias/noticias.component.ts | TypeScript |
ArrowFunction |
(item) => item.id === id | Bielma/nestjs-store | src/users/services/users.service.ts | TypeScript |
ClassDeclaration |
@Injectable()
export class UsersService {
constructor(
private productsService: ProductsService,
private configService: ConfigService,
) {}
private counterId = 1;
private users: User[] = [
{
id: 1,
email: 'correo@mail.com',
password: '12345',
role: 'admin',
},
];
f... | Bielma/nestjs-store | src/users/services/users.service.ts | TypeScript |
MethodDeclaration |
findAll() {
const apiKey = this.configService.get('API_KEY');
const dbName = this.configService.get('DATABASE_NAME');
console.log(apiKey, dbName);
return this.users;
} | Bielma/nestjs-store | src/users/services/users.service.ts | TypeScript |
MethodDeclaration |
findOne(id: number) {
const user = this.users.find((item) => item.id === id);
if (!user) {
throw new NotFoundException(`User #${id} not found`);
}
return user;
} | Bielma/nestjs-store | src/users/services/users.service.ts | TypeScript |
MethodDeclaration |
create(data: CreateUserDto) {
this.counterId = this.counterId + 1;
const newUser = {
id: this.counterId,
...data,
};
this.users.push(newUser);
return newUser;
} | Bielma/nestjs-store | src/users/services/users.service.ts | TypeScript |
MethodDeclaration |
update(id: number, changes: UpdateUserDto) {
const user = this.findOne(id);
const index = this.users.findIndex((item) => item.id === id);
this.users[index] = {
...user,
...changes,
};
return this.users[index];
} | Bielma/nestjs-store | src/users/services/users.service.ts | TypeScript |
MethodDeclaration |
remove(id: number) {
const index = this.users.findIndex((item) => item.id === id);
if (index === -1) {
throw new NotFoundException(`User #${id} not found`);
}
this.users.splice(index, 1);
return true;
} | Bielma/nestjs-store | src/users/services/users.service.ts | TypeScript |
MethodDeclaration |
getOrderByUser(id: number): Order {
const user = this.findOne(id);
return {
date: new Date(),
user,
products: this.productsService.findAll(),
};
} | Bielma/nestjs-store | src/users/services/users.service.ts | TypeScript |
InterfaceDeclaration |
export interface Country {
_id?: String;
name: String;
states?: State[];
} | APMIS-HMS/cepmanagement | src/app/models/country.ts | TypeScript |
ClassDeclaration |
export declare class ResponseOrganization extends Response<Organization> {
data: Organization
} | h1542462994/teamwork-software-engineering | server/src/main/resources/static/js/model/response_organization.d.ts | TypeScript |
ArrowFunction |
(_, { search }, context, rootValue) => { return process.env.npm_package_version } | Aeysha0056/vue-storefront-api | packages/default-catalog/graphql/elasticsearch/root.resolver.ts | TypeScript |
MethodDeclaration |
__resolveType () {
return null;
} | Aeysha0056/vue-storefront-api | packages/default-catalog/graphql/elasticsearch/root.resolver.ts | TypeScript |
ArrowFunction |
(
globalConfigState: GlobalConfigState,
): GlobalConfigState => {
if (!isMigrateModel(globalConfigState, MODEL_VERSION, 'GlobalConfig')) {
return globalConfigState;
}
// NOTE: needs to run before default stuff
globalConfigState = _migrateMiscToSeparateKeys(globalConfigState);
// NOTE: needs to run be... | isupovs/super-productivity | src/app/features/config/migrate-global-config.util.ts | TypeScript |
ArrowFunction |
(config: GlobalConfigState): GlobalConfigState => {
const idle: IdleConfig = !!config.idle
? config.idle
: {
...DEFAULT_GLOBAL_CONFIG.idle,
// eslint-disable-next-line
isOnlyOpenIdleWhenCurrentTask: (config.misc as any).isOnlyOpenIdleWhenCurrentTask,
// eslint-disable-next-lin... | isupovs/super-productivity | src/app/features/config/migrate-global-config.util.ts | TypeScript |
ArrowFunction |
(key) => {
if ((config as any)[key]) {
delete (config as any)[key];
}
} | isupovs/super-productivity | src/app/features/config/migrate-global-config.util.ts | TypeScript |
ArrowFunction |
(config: GlobalConfigState): GlobalConfigState => {
const newCfg: Partial<GlobalConfigState> = { ...config };
for (const key in DEFAULT_GLOBAL_CONFIG) {
if (!newCfg.hasOwnProperty(key)) {
// @ts-ignore
newCfg[key] = { ...DEFAULT_GLOBAL_CONFIG[key] };
} else if (
// @ts-ignore
typeof... | isupovs/super-productivity | src/app/features/config/migrate-global-config.util.ts | TypeScript |
ArrowFunction |
(
config: GlobalConfigState,
): GlobalConfigState => {
const keyboardCopy: any = {
// also add new keys
...DEFAULT_GLOBAL_CONFIG.keyboard,
...config.keyboard,
};
Object.keys(keyboardCopy).forEach((key: string) => {
if (keyboardCopy[key] === false || keyboardCopy[key] === undefined) {
keyb... | isupovs/super-productivity | src/app/features/config/migrate-global-config.util.ts | TypeScript |
ArrowFunction |
(key: string) => {
if (keyboardCopy[key] === false || keyboardCopy[key] === undefined) {
keyboardCopy[key] = null;
}
} | isupovs/super-productivity | src/app/features/config/migrate-global-config.util.ts | TypeScript |
ArrowFunction |
(config: GlobalConfigState): GlobalConfigState => {
if (config.sync) {
return config;
}
let prevProvider: SyncProvider | null = null;
let syncInterval: number = 0;
if ((config as any).dropboxSync?.isEnabled) {
prevProvider = SyncProvider.Dropbox;
syncInterval = (config as any).dropboxSync.syncIn... | isupovs/super-productivity | src/app/features/config/migrate-global-config.util.ts | TypeScript |
ArrowFunction |
(config: GlobalConfigState): GlobalConfigState => {
if (config.misc.defaultProjectId === 'G.NONE' || config.misc.defaultProjectId === '') {
return {
...config,
misc: {
...config.misc,
defaultProjectId: null,
},
};
}
return {
...config,
};
} | isupovs/super-productivity | src/app/features/config/migrate-global-config.util.ts | TypeScript |
ClassDeclaration | /**
* @en The forward render stage
* @zh 前向渲染阶段。
*/
@ccclass('ForwardStage')
export class ForwardStage extends RenderStage {
public static initInfo: IRenderStageInfo = {
name: 'ForwardStage',
priority: ForwardStagePriority.FORWARD,
tag: 0,
renderQueues: [
{
... | CatXia/CatXiaEngine | library/engine-3d/cocos/core/pipeline/forward/forward-stage.ts | TypeScript |
MethodDeclaration |
public initialize (info: IRenderStageInfo): boolean {
super.initialize(info);
if (info.renderQueues) {
this.renderQueues = info.renderQueues;
}
return true;
} | CatXia/CatXiaEngine | library/engine-3d/cocos/core/pipeline/forward/forward-stage.ts | TypeScript |
MethodDeclaration |
public activate (pipeline: ForwardPipeline, flow: ForwardFlow) {
super.activate(pipeline, flow);
for (let i = 0; i < this.renderQueues.length; i++) {
let phase = 0;
for (let j = 0; j < this.renderQueues[i].stages.length; j++) {
phase |= getPhaseID(this.renderQueu... | CatXia/CatXiaEngine | library/engine-3d/cocos/core/pipeline/forward/forward-stage.ts | TypeScript |
MethodDeclaration |
public destroy () {
} | CatXia/CatXiaEngine | library/engine-3d/cocos/core/pipeline/forward/forward-stage.ts | TypeScript |
MethodDeclaration |
public render (view: RenderView) {
this._instancedQueue.clear();
this._batchedQueue.clear();
const pipeline = this._pipeline as ForwardPipeline;
const device = pipeline.device;
this._renderQueues.forEach(this.renderQueueClearFunc);
const renderObjects = pipeline.render... | CatXia/CatXiaEngine | library/engine-3d/cocos/core/pipeline/forward/forward-stage.ts | TypeScript |
MethodDeclaration | /**
* @en Clear the given render queue
* @zh 清空指定的渲染队列
* @param rq The render queue
*/
protected renderQueueClearFunc (rq: RenderQueue) {
rq.clear();
} | CatXia/CatXiaEngine | library/engine-3d/cocos/core/pipeline/forward/forward-stage.ts | TypeScript |
MethodDeclaration | /**
* @en Sort the given render queue
* @zh 对指定的渲染队列执行排序
* @param rq The render queue
*/
protected renderQueueSortFunc (rq: RenderQueue) {
rq.sort();
} | CatXia/CatXiaEngine | library/engine-3d/cocos/core/pipeline/forward/forward-stage.ts | TypeScript |
ClassDeclaration |
export class User {
@ApiProperty({
required: false,
example: 1,
description: 'User ID',
})
id?: number;
@ApiProperty({
example: 'Juan',
description: 'The fist name of the User',
})
firstName: string;
@ApiProperty({
example: 'Perez',
description: 'The lastname of the User',
... | rudemex/iol | src/users/entities/user.entity.ts | TypeScript |
ArrowFunction |
() => {
const s: SoftwareDeliveryMachine = {
configuration: {
sdm: {
k8s: {
options: {},
},
},
},
} as any;
const t = isSyncRepoCommit(... | atomist/sdm-pack-k8 | test/sync/goals.test.ts | TypeScript |
ArrowFunction |
async () => {
const s: SoftwareDeliveryMachine = {
configuration: {
name: "@atomist/k8s-sdm_i-started-something",
sdm: {
k8s: {
options: {
sync: {
... | atomist/sdm-pack-k8 | test/sync/goals.test.ts | TypeScript |
ArrowFunction |
async () => { } | atomist/sdm-pack-k8 | test/sync/goals.test.ts | TypeScript |
ArrowFunction |
async () => {
const s: SoftwareDeliveryMachine = {
configuration: {
name: "@atomist/k8s-sdm_i-started-something",
sdm: {
k8s: {
options: {
sync: {
... | atomist/sdm-pack-k8 | test/sync/goals.test.ts | TypeScript |
ArrowFunction |
async () => {
const s: SoftwareDeliveryMachine = {
configuration: {
name: "@atomist/k8s-sdm_i-started-something",
sdm: {
k8s: {
options: {
sync: {
... | atomist/sdm-pack-k8 | test/sync/goals.test.ts | TypeScript |
ArrowFunction |
async () => {
const s: SoftwareDeliveryMachine = {
configuration: {
name: "@atomist/k8s-sdm_i-started-something",
sdm: {
k8s: {
options: {
sync: {
... | atomist/sdm-pack-k8 | test/sync/goals.test.ts | TypeScript |
ArrowFunction |
async () => {
const s: SoftwareDeliveryMachine = {
configuration: {
name: "@atomist/k8s-sdm_i-started-something",
sdm: {
k8s: {
options: {
sync: {
... | atomist/sdm-pack-k8 | test/sync/goals.test.ts | TypeScript |
ArrowFunction |
state => state ? this._filterStates(state) : this.statesList.slice() | martinavagyan/us-infographic | client/src/app/components/search/search.component.ts | TypeScript |
ArrowFunction |
state => state.name.toLowerCase().indexOf(filterValue) === 0 | martinavagyan/us-infographic | client/src/app/components/search/search.component.ts | TypeScript |
ClassDeclaration |
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {
@Input('statesList') public statesList: State[] = [];
@Output('selectedRegionEvent') public selectedRegionEvent = new EventEmitter<string>()... | martinavagyan/us-infographic | client/src/app/components/search/search.component.ts | TypeScript |
MethodDeclaration |
ngOnInit() {
this.filteredStates = this.stateCtrl.valueChanges
.pipe(
startWith(''),
map(state => state ? this._filterStates(state) : this.statesList.slice())
);
} | martinavagyan/us-infographic | client/src/app/components/search/search.component.ts | TypeScript |
MethodDeclaration |
public stateClicked(selectedState: State): void {
this.selectedRegionEvent.emit(selectedState.id);
} | martinavagyan/us-infographic | client/src/app/components/search/search.component.ts | TypeScript |
MethodDeclaration |
private _filterStates(value: string): State[] {
const filterValue = value.toLowerCase();
return this.statesList.filter(state => state.name.toLowerCase().indexOf(filterValue) === 0);
} | martinavagyan/us-infographic | client/src/app/components/search/search.component.ts | TypeScript |
ClassDeclaration |
@NgModule({
declarations: [
AppComponent
],
imports: [
HttpModule,
HttpClientModule,
FormsModule,
BrowserModule,
AppRoutingModule,
SharedModule
],
providers: [
AuthService,
LoaderService,
ModalTempService,
ModalConfirmService,
CardService
],
bootstrap: [App... | MarinTerentiev/mag | src/app/app.module.ts | TypeScript |
FunctionDeclaration |
export default async function createPlugin({
logger,
config,
}: PluginEnvironment) {
return await createRouter({ logger, config });
} | AdnCodez/backstage | packages/backend/src/plugins/kubernetes.ts | TypeScript |
ArrowFunction |
({ name, value, className, ...props }: Props & InputProps) => (
<Field name={name}>
{({ field, form }: FieldProps) | 07test9992/panel | resources/scripts/components/elements/Checkbox.tsx | TypeScript |
InterfaceDeclaration |
interface Props {
name: string;
value: string;
className?: string;
} | 07test9992/panel | resources/scripts/components/elements/Checkbox.tsx | TypeScript |
TypeAliasDeclaration |
type OmitFields = 'ref' | 'name' | 'value' | 'type' | 'checked' | 'onClick' | 'onChange'; | 07test9992/panel | resources/scripts/components/elements/Checkbox.tsx | TypeScript |
TypeAliasDeclaration |
type InputProps = Omit<JSX.IntrinsicElements['input'], OmitFields>; | 07test9992/panel | resources/scripts/components/elements/Checkbox.tsx | TypeScript |
ArrowFunction |
(): void => this.terminate() | BenediktMagnus/Wichtelbot | scripts/main.ts | TypeScript |
ClassDeclaration |
class Main
{
private wichtelbot: Wichtelbot|null = null;
private applicationIsRunning = false;
constructor ()
{
const terminateFunction = (): void => this.terminate();
process.on('exit', terminateFunction);
process.on('SIGINT', terminateFunction); // Ctrl + C
process.o... | BenediktMagnus/Wichtelbot | scripts/main.ts | TypeScript |
MethodDeclaration | /**
* Terminate all running connections and report about the closing programme.
*/
public terminate (): void
{
if (this.applicationIsRunning)
{
this.applicationIsRunning = false;
if (this.wichtelbot)
{
this.wichtelbot.terminate();
... | BenediktMagnus/Wichtelbot | scripts/main.ts | TypeScript |
MethodDeclaration |
public async run (): Promise<void>
{
console.log('Wichtelbot is starting...');
this.applicationIsRunning = true;
this.wichtelbot = new Wichtelbot();
await this.wichtelbot.run();
console.log(`Wichtelbot started.`);
} | BenediktMagnus/Wichtelbot | scripts/main.ts | TypeScript |
ArrowFunction |
() => {
afterEach(() => {
jest.resetAllMocks();
});
it('creates snapshot', () => {
const { asFragment } = render(<InputTypeahead {...defaultProps} />);
expect(asFragment).toMatchSnapshot();
});
it('renders proper content with selectedValues', () => {
const { getByTestId, getAllByTestId, get... | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
jest.resetAllMocks();
} | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { asFragment } = render(<InputTypeahead {...defaultProps} />);
expect(asFragment).toMatchSnapshot();
} | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId, getAllByTestId, getByText } = render(<InputTypeahead {...defaultProps} />);
expect(getByTestId('typeaheadBtn')).toBeInTheDocument();
expect(getAllByTestId('typeaheadSelectedItem')).toHaveLength(2);
expect(getByText(defaultProps.label)).toBeInTheDocument();
} | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId, getByText } = render(<InputTypeahead {...defaultProps} selected={{}} | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId, getAllByTestId, getByText, getByPlaceholderText } = render(
<InputTypeahead {...defaultProps} />
);
const btn = getByTestId('typeaheadBtn');
fireEvent.click(btn);
expect(getByTestId('typeaheadDropdown')).toBeInTheDocument();
expect(getByTestId('typeaheadInp... | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByText, getByTestId } = render(<InputTypeahead {...defaultProps} />);
const item = getByText('Option key 1');
fireEvent.click(item);
expect(getByTestId('typeaheadDropdown')).toBeInTheDocument();
} | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId, getAllByTestId } = render(<InputTypeahead {...defaultProps} />);
const btn = getByTestId('typeaheadBtn');
fireEvent.click(btn);
const opts = getAllByTestId('typeaheadDropdownBtn');
expect(opts[0]).toHaveTextContent('Option key 2(12)');
expect(opts[1]).toHaveTextC... | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getAllByTestId } = render(<InputTypeahead {...defaultProps} />);
const opts = getAllByTestId('typeaheadSelectedItem');
expect(opts[0]).toHaveTextContent('Option key 2(12)');
expect(opts[1]).toHaveTextContent('Option key 1(7)');
} | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId, getAllByTestId } = render(<InputTypeahead {...defaultProps} />);
const btn = getByTestId('typeaheadBtn');
fireEvent.click(btn);
const opts = getAllByTestId('typeaheadDropdownBtn');
fireEvent.click(opts[0]);
expect(onChangeMock).toHaveBeenCalledTimes(1);
exp... | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId, getAllByTestId } = render(<InputTypeahead {...defaultProps} />);
const btn = getByTestId('typeaheadBtn');
fireEvent.click(btn);
const opts = getAllByTestId('typeaheadDropdownBtn');
fireEvent.click(opts[2]);
expect(onChangeMock).toHaveBeenCalledTimes(1);
exp... | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId } = render(<InputTypeahead {...defaultProps} />);
const btn = getByTestId('typeaheadBtn');
fireEvent.click(btn);
const clearBtn = getByTestId('typeaheadClearBtn');
fireEvent.click(clearBtn);
expect(onResetSomeFiltersMock).toHaveBeenCalledTimes(1);
expect(onR... | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId, getAllByTestId, getAllByText } = render(<InputTypeahead {...defaultProps} />);
const btn = getByTestId('typeaheadBtn');
fireEvent.click(btn);
expect(getAllByTestId('typeaheadDropdownBtn')).toHaveLength(4);
const input = getByTestId('typeaheadInput');
fireEvent.... | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
() => {
const { getByTestId, getAllByTestId, queryAllByTestId, getByText } = render(<InputTypeahead {...defaultProps} />);
const btn = getByTestId('typeaheadBtn');
fireEvent.click(btn);
expect(getAllByTestId('typeaheadDropdownBtn')).toHaveLength(4);
const input = getByTestId('typeaheadInput');
... | DirtyCajunRice/hub | web/src/layout/common/InputTypeahead.test.tsx | TypeScript |
ArrowFunction |
({ navigation }) => {
const { aggregation } = useArtworkFiltersAggregation({ paramName: PARAM_NAME })
const options: FilterData[] = (aggregation?.counts ?? []).map(({ value: paramValue, name }) => {
return { displayText: toTitleCase(name), paramName: PARAM_NAME, paramValue }
})
const { handleSelect, isSe... | artsy/eigen | src/lib/Components/ArtworkFilter/Filters/ArtistNationalitiesOptions.tsx | TypeScript |
ArrowFunction |
({ value: paramValue, name }) => {
return { displayText: toTitleCase(name), paramName: PARAM_NAME, paramValue }
} | artsy/eigen | src/lib/Components/ArtworkFilter/Filters/ArtistNationalitiesOptions.tsx | TypeScript |
ArrowFunction |
(option) => ({ ...option, paramValue: isSelected(option) }) | artsy/eigen | src/lib/Components/ArtworkFilter/Filters/ArtistNationalitiesOptions.tsx | TypeScript |
InterfaceDeclaration |
interface ArtistNationalitiesOptionsScreenProps
extends StackScreenProps<ArtworkFilterNavigationStack, "ArtistNationalitiesOptionsScreen"> {} | artsy/eigen | src/lib/Components/ArtworkFilter/Filters/ArtistNationalitiesOptions.tsx | TypeScript |
ClassDeclaration |
@Schema()
class Card extends Document {
@Prop({ type: String })
weight: string;
@Prop({ type: String })
type: string;
} | Michalus88/black-jack-nest-react-mongo | src/schemas/user.schema.ts | TypeScript |
ClassDeclaration |
@Schema()
export class User extends Document {
@Prop({ type: String, unique: true, required: true })
email: string;
@Prop({ required: true })
pwd: string;
@Prop({ type: Number, default: 1500 })
means: number;
@Prop({ type: [CardSchema] })
deck: CardInterface[];
@Prop({ type: [CardSchema] })
pla... | Michalus88/black-jack-nest-react-mongo | src/schemas/user.schema.ts | TypeScript |
InterfaceDeclaration |
export interface CardInterface {
weight: string;
type: string;
} | Michalus88/black-jack-nest-react-mongo | src/schemas/user.schema.ts | TypeScript |
ArrowFunction |
(
command: commander.Command,
version: string,
name: string,
description: string,
usage?: string
): void => {
// Set command version
command.version(version);
// Set command name
command.name(name);
// Set command description
command.description(description);
// Set command usage
command.usag... | joshuatvernon/scriptdir | src/utils/command/set-description/index.ts | TypeScript |
FunctionDeclaration |
export function executableName(name: string): string {
return `${name}${os.platform() === "win32" ? ".exe" : ""}`;
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function changeExt(path: string, newExt: string): string {
return path.replace(/\.[^/.]+$/, newExt);
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export async function loadBinaryVersions(name: string): Promise<string[]> {
const info = await httpsGetJson(`https://binaries.tonlabs.io/${name}.json`);
const versions = info[name].sort(compareVersions).reverse();
return versions.length < 10 ? versions : [...versions.slice(0, 10), "..."];
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function formatTokens(nanoTokens: string | number | bigint): string {
const token = BigInt(1000000000);
const bigNano = BigInt(nanoTokens);
const tokens = Number(bigNano / token) + Number(bigNano % token) / Number(token);
const tokensString = tokens < 1 ? tokens.toString() : `≈ ${Math.round(toke... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function writeTextFile(p: string, s: string) {
const folderPath = path.dirname(p);
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true });
}
fs.writeFileSync(p, s);
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function writeJsonFile(p: string, v: unknown) {
writeTextFile(p, JSON.stringify(v, undefined, " "));
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
async function installGlobally(dstPath: string, version: string, terminal: Terminal): Promise<void> {
const binDir = path.dirname(dstPath);
const [name, ext] = path.basename(dstPath).split(".");
try {
writeJsonFile(`${binDir}/package.json`, {
name: name, // ex: tonos-cli
ver... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
function downloadAndUnzip(dst: string, url: string, terminal: Terminal): Promise<void> {
return new Promise((resolve, reject) => {
request(url)
.on("data", _ => {
terminal.write(".");
})
.on("error", reject) // http protocol errors
.pipe(
... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export async function downloadFromGithub(terminal: Terminal, srcUrl: string, dstPath: string) {
terminal.write(`Downloading from ${srcUrl}`);
if (!fs.existsSync(dstPath)) {
fs.mkdirSync(dstPath, { recursive: true });
}
await downloadAndUnzip(dstPath, srcUrl, terminal);
terminal.write("\n");... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
function downloadAndGunzip(dest: string, url: string, terminal: Terminal): Promise<void> {
return new Promise((resolve, reject) => {
const request = https.get(url, response => {
if (response.statusCode !== 200) {
reject(
new Error(
`Do... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export async function downloadFromBinaries(
terminal: Terminal,
dstPath: string,
src: string,
options?: {
executable?: boolean,
adjustedPath?: string,
globally?: boolean,
version?: string,
},
) {
src = src.replace("{p}", os.platform());
const srcExt = path.ex... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function run(
name: string,
args: string[],
options: SpawnOptionsWithoutStdio,
terminal: Terminal,
): Promise<string> {
return new Promise((resolve, reject) => {
try {
const { cwd } = options;
if (cwd && !fs.existsSync(cwd)) {
throw Error(`Dire... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function uniqueFilePath(folderPath: string, namePattern: string): string {
let index = 0;
while (true) {
const filePath = path.resolve(
folderPath,
namePattern.replace("{}", index === 0 ? "" : index.toString()),
);
if (!fs.existsSync(filePath)) {
... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function versionToNumber(s: string): number {
if (s.toLowerCase() === "latest") {
return 1_000_000_000;
}
const parts = `${s || ""}`
.split(".")
.map(x => Number.parseInt(x))
.slice(0, 3);
while (parts.length < 3) {
parts.push(0);
}
return parts[0]... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function compareVersions(a: string, b: string): number {
const an = versionToNumber(a);
const bn = versionToNumber(b);
return an < bn ? -1 : (an === bn ? 0 : 1);
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function compareVersionsDescending(a: string, b: string): number {
const an = versionToNumber(a);
const bn = versionToNumber(b);
return an > bn ? -1 : (an === bn ? 0 : 1);
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function progressLine(terminal: Terminal, line: string) {
terminal.write(`\r${line}`);
const extra = _progressLine.length - line.length;
if (extra > 0) {
terminal.write(" ".repeat(extra) + "\b".repeat(extra));
}
_progressLine = line;
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function progress(terminal: Terminal, info: string) {
progressLine(terminal, `${info}...`);
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function progressDone(terminal: Terminal) {
terminal.log(" ✓");
_progressLine = "";
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function httpsGetJson(url: string): Promise<any> {
return new Promise((resolve, reject) => {
const tryUrl = (url: string) => {
https
.get(url, function (res) {
let body = "";
res.on("data", function (chunk) {
... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
function toIdentifier(s: string): string {
let identifier = "";
for (let i = 0; i < s.length; i += 1) {
const c = s[i];
const isLetter = c.toLowerCase() !== c.toUpperCase();
const isDigit = !isLetter && "0123456789".includes(c);
if (isLetter || isDigit) {
identifier ... | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
export function userIdentifier(): string {
return toIdentifier(os.userInfo().username).toLowerCase();
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
FunctionDeclaration |
function toString(value: any): string {
return value === null || value === undefined ? "" : value.toString();
} | INTONNATION/tondev | src/core/utils.ts | TypeScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.