npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

converter-to-sync

v1.1.9

Published

basit bir fonksiyon senkronizeri

Downloads

18

Readme

AlpSuuu/converter-to-sync 😋

kullanışlı bir "Promise resolver" ve asenkron fonksiyonu senkron fonksiyona dönüştürücü! Projemizi github üzerinden manuel olarak veya "git clone" yardımıyla indirdiğinizde projeyi kullanabilmeniz için typescript dosyalarının javascript haline dönüşmüş halini ./dist klasörüne ekledim ayrıca cmd'ye "tsc" yazmanıza gerek yok!

npm install converter-to-sync
git clone https://github.com/AlpSuuu/awaiter.git

İndirme

Tanımlamlar

Fonksiyonlarımızı bir objenin içinde tanımlıyoruz tanımlıyoruz!

const {
    evalSync,
    promiseResolver,
    fetch,
    awaiter,
    syncAll,
    convertSync,
    sleep,
    convertAllToSyncFunction,
    convertToSyncFunction,
    generatorSync,
    Emitter
} = require("converter-to-sync");

Fonksiyonlarımızın Kullanılış Örnekleri;

Başlamadan önce kullandığınız fonksiyonların verilerini kolaylıkla çekmek için aşağıdaki kodu yapıştırın fonksiyonlarımızı her kullandığımızda veriler Kendi Emitter'ımıza yansıyacaktır! Not: Kodu fonksiyonlarımızı kullandığınız kısmın üstüne yapıştırın aksi taktirde Emitter çalışmaz

Emitter.call(async function(data) {
    console.log(data) // { status : "durum mesajı", target : "hedefimiz" , date : "Fonksiyonumuzun kullanılma tarihi", hitch : "Aksama süresi"}
})

...// fonksiyonlarımızı şimdi kullanabilirsiniz

1-) evalSync

String formundaki bir kodu eval yardımıyla çalıştırmaya yarar fakat kodumuzda bir promise döndürmemiz gerekiyor!

let evaled = evalSync(`
    const promiseFunction = async function(param , ms) {
        return new Promise((res) => { 
            setTimeout(() => {
                res.call(void 0 , param)
            } , ms)
        });
    }
    promiseFunction.call(void 0 , "fonksiyonlarınızı senkronize etmek çok kolay :)" , 2500)
`)

console.log(evaled) // output: 'fonksiyonlarınızı senkronize etmek çok kolay :)'

2-) promiseResolver

Promise döndüren bir fonksiyonu veya bir Promise'in resolve edilen değerini çekmemizi sağlayan fonksiyon

const asyncFunction = async function(param1 ,  param2) {
    return param1 + " - " + param2
}

let resolvedValue = promiseResolver(asyncFunction("github" , "AlpSuuu"))
console.log(resolvedValue) // output: 'github - AlpSuuu'

3-) fetch

girmiş olduğunuz url yi https modülü üzerinden aratır ve sonuçları listeler

let data = fetch("https://www.instagram.com/reels/audio/2164441880485605/?__a=1");

console.log(data) // output: Object<void>

4-) awaiter

bir callback yardımıyla Promise fonksiyonunu resolve etmemize yarayan fonksiyon

let func = awaiter(callback => {
    async function asyncFunction(param) {
        return param.toString().toUpperCase()
    }

    callback(asyncFunction("hello world!"))
})

console.log(func) // output: 'HELLO WORLD!'

5-) syncAll

Birden fazla Promise'in teker teker resolve değerlerini bir diziye pushlayıp döndürür

let [ promise_1 , promise_2 , promise_3 , promise_4 ] = syncAll([
    Promise.resolve("i"),
    new Promise((resolve) => setTimeout(resolve, 100, 'love')),
    asyncFunction1("AlpSuüğğğğğ"),
    "<333"
])

console.log(promise_1) // output: 'i'
console.log(promise_2) // output: 'love'
console.log(promise_3) // output: 'AlpSuüğğğğğ'
console.log(promise_4) // output: '<333'

6-) convertSync

fonksiyonumuzun 1. parametresine aseonkron fonksiyonunuzu 2. parametresine de asenkron fonksiyonunuzun parametrelerini girin fonksiyonumuz asenkron fonksiyonunuzu parametreleriyle birlikte çalıştırıp dönen Promise'in response değerini döndürür! (karışık oldu galiba :) örneği incele.)

async function asyncFunction(param1) {
    return new Promise((res) => { 
        setTimeout(res , 15 , param1)
    });
}
// asenkron fonksiyonunuzun parametrelerini ayrı ayrı girin! bir dizi içine tüm parametrelerinizi girmeyin! 
let value = convertSync(asyncFunction , "instagram üzerinden medya indirmek isterseniz npmjs.com/instagram-url-downloader")
console.log(value) // output: 'instagram üzerinden medya indirmek isterseniz npmjs.com/instagram-url-downloader'

7-) sleep

biliyoruz ki javascript single-thread ve asenkron türde bir dil yani satırlardaki işlevler birbirinden bağımsız çalışıyor bu fonksiyonumuz ile birlikte 'await' kullanmadan işlevler arası delay atayabiliriz.

console.log("Hello");
sleep(2 * 1000);
console.log("World!");

// birinci işlevimiz çalıştıktan sonra ikinci işlevimize geçmeden 2 saniye bekledik.

8-) convertAllToSyncFunction

birden fazla asenkron fonksiyonun senkron fonksiyona dönüşmüş hallerini bir dizi olarak döndürür

async function asyncFunction1(param1) {
    return new Promise((res) => { 
        setTimeout(res , 15 , param1)
    });
}

const asyncFunction2 = async function(param1 ,  param2) {
    return param1 + " - " + param2
}

async function asyncFunction3(param1) {
    return await asyncFunction1(param1)
}

const normalFunction = function(num1 , num2) {
    return num1 * num2
}

let [ function_1 , function_2 , function_3 , function_4 ] = convertAllToSyncFunction([
    asyncFunction1,
    asyncFunction2,
    asyncFunction3,
    normalFunction,
])


console.log(function_1("AlpSu <3")) // output: 'AlpSu <3'
console.log(function_2("javascript" , "typescript")) // output: 'javascript - typescript'
console.log(function_3("awaiter :)")) // output: 'awaiter :)'
console.log(function_4(8 , 3)) // output: 24

9-) convertToSyncFunction

bir asenkron fonksiyonun senkron fonksiyona dönüşütürülmüş hanini döndüren fonksiyon

async function asyncFunction(param1) {
    return new Promise((res) => { 
        setTimeout(res , 15 , param1)
    });
}

let converted = convertToSyncFunction(asyncFunction)
console.log(converted("JS single-thread ve asenkron türde bir kütüphanedir!")) // output: 'JS single-thread...'

10-) generatorSync

bir jeneratör foknsiyon bloğu içindeki yield edilen tüm Promise'lerin resolve değerlerini dizi halinde döndürür

async function asyncFunction(param1) {
    return new Promise((res) => { 
        setTimeout(res , 15 , param1)
    });
}

const asyncFunction2 = async function(param1 ,  param2) {
    return param1 + " - " + param2
}

let resolvedValues = generatorSync(function*() {
    yield asyncFunction1("i")
    yield asyncFunction2("love" , "you")
    yield Promise.resolve("AlpSuuğ")
});

console.log(resolvedValues) // Array([ 'i' , 'love - you' , 'AlpSuuğ' ]);

Ekstra kullanım

Promise fonksiyonumuzun Prototipi arasına eklediğimiz "getResponse" fonksiyonumuz ile birlikte bir Promise'in resolve edilen değerini kolaylıkla çekebilirsiniz!

let promise = Promise.resolve("instagram - @alp.kahyaa")

console.log(promise.getResponse()) // output: 'instagram - @alp.kahyaa'